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
- 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
- Conditional styling if the DataFrame based on each row value. For instance, changing its background color
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
UPDATE
- Users update rows with a dialog opened by selecting the row and clicking the icon
- Text columns offers candidates from existing values
- ForeignKey columns are added by the string representation instead of its id number
- In Update form, list all ONE-TO-MANY related rows with pagination, where you can directly create and delete related table rows.
CREATE
- Users create new rows with a dialog opened by clicking the create button
- Text columns offers candidates from existing values
- Hide columns to fill by offering default values
- ForeignKey columns are added by the string representation instead of its id number
DELETE
- Delete one or multiple rows by selecting in DataFrame and clicking the corresponding button. I dialog will list selected rows and confirm deletion.
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
Run show_sql_ui as the example below:
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)
!!! warning In the statement, always include the primary_key column, that should be named id
Interface
- Filter: Open the "Filter" expander and fill the inputs
- Add row: Click on "plus" button (no dataframe row can be selected)
- Edit row: Click on "pencil" button (one and only one dataframe row should be selected)
- Delete row: Click on "trash" button (one or more dataframe rows should be selected)
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.4.tar.gz.
File metadata
- Download URL: streamlit_sql-0.2.4.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4093c0444e5c6d47d0e910933196b2040d08a3ed5da5df0c100346f392f40937
|
|
| MD5 |
f581b2447da98c763fa513096c0d36de
|
|
| BLAKE2b-256 |
4d9ce5865c3c47a5e7050971f42ac4934711d4d3519bee2ffaaba75da8020c71
|
File details
Details for the file streamlit_sql-0.2.4-py3-none-any.whl.
File metadata
- Download URL: streamlit_sql-0.2.4-py3-none-any.whl
- Upload date:
- Size: 17.5 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 |
b13451ca78081b8d62e0bf55a41f3bbb30e59eec0e6a5e119b6554883d685420
|
|
| MD5 |
369ccceeac4f4fad6b3c3e5be15242d0
|
|
| BLAKE2b-256 |
192999dccfd3604848f6f2f1f76ed08e9140421144b878c86803d4fe5c2dc8e9
|