CRUD interface for sqlalchemy using streamlit
Project description
streamlit_sql
Introduction
This package shows a CRUD frontend to a database using sqlalchemy in a streamlit app. With just one line of code, show the data as table and allow the user to read, filter, update, create and delete rows with many useful features.
Demo
See the package in action here.
Features
READ
- Display as a regular st.dataframe
- Add pagination, displaying only a set of rows each time
- Display the string representation of a ForeignKey column (Using str method), instead of its id number
- Set the dataframe to be displayed using standard sqlalchemy select statement, where you can JOIN, ORDER BY, WHERE, etc.
- Add a column to show the rolling sum of a numeric column
FILTER
- Filter the data by some columns before presenting the table.
- Let users filter the columns by selecting conditions in the filter expander
- Give possible candidates when filtering using existing values for the columns
- Let users select ForeignKey's values using the string representation of the foreign table, instead of its id number
CREATE / UPDATE / DELETE
- Users create new rows with a dialog opened by clicking the create button
- Users update rows with a dialog opened by clicking on desired row
- Text columns offers candidates from existing values
- ForeignKey columns are added by the string representation instead of its id number
- Hide columns to fill by offering default values
- Delete button in the UPDATE field
Requirements
All the requirements you should probably have anyway.
- streamlit and sqlalchemy
- Sqlalchemy models needs a str method
- Id column should be called "id"
- Relationships should be added for all ForeignKey columns
Basic Usage
Install the package using pip:
pip install streamlit_sql
Define a ModelOpts and add it to the argument of show_sql_ui function:
from streamlit_sql import show_sql_ui
from sqlalchemy import select
conn = st.connection("sql", url="<db_url>")
stmt = (
select(
db.Invoice.id,
db.Invoice.Date,
db.Invoice.amount,
db.Client.name,
)
.join(db.Client)
.where(db.Invoice.amount > 1000)
.order_by(db.Invoice.date)
)
show_sql_ui(conn=conn,
read_instance=stmt,
edit_create_model=db.Invoice,
available_filter=["name"],
rolling_total_column="amount",
)
show_sql_ui(conn, model_opts)
Customize
You can adjust the CRUD interface by the select statement you provide to read_instance arg and giving optional arguments to the show_sql_ui function. See the docstring for more information or at documentation webpage:
Only create or update form
You can display just a create or update/delete form without the read interface using functions show_updade, and show_create.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamlit_sql-0.2.0.tar.gz.
File metadata
- Download URL: streamlit_sql-0.2.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5a9aabb0a5938e85bb9c7d51d7f680abf5b15b93015607cbac0bb0693d23902
|
|
| MD5 |
15de11900b1f9bd567b3ecb35360ab57
|
|
| BLAKE2b-256 |
ed7bf5a2526e7f10d4a1349e6416af873e884e4cecd897f5b31e0975dfe2e7f8
|
File details
Details for the file streamlit_sql-0.2.0-py3-none-any.whl.
File metadata
- Download URL: streamlit_sql-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcd750ae3e7a82d458dcc81b9954ec8194c5ccc6a1c6afd89d7936192c4823de
|
|
| MD5 |
0bf20f042857403a3331e3e745ecfcde
|
|
| BLAKE2b-256 |
c11d6bcd7fba76fc7490386c75d086e40794f2618bce975b328a0376700e5973
|