Skip to main content

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

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.

  1. streamlit and sqlalchemy
  2. Sqlalchemy models needs a str method
  3. Id column should be called "id"
  4. 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)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_sql-0.2.3.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_sql-0.2.3-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_sql-0.2.3.tar.gz.

File metadata

  • Download URL: streamlit_sql-0.2.3.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for streamlit_sql-0.2.3.tar.gz
Algorithm Hash digest
SHA256 7d91ee53cb05c9edb4f87332cf9cc43f766a2f39973fa522461da446b529c890
MD5 e6fa120dfd02469859fc9829a0bc2b45
BLAKE2b-256 0cd649e7d8d9fe0736387d18d35e94f3ead204f3a944627e18ea6c7ffacdb0af

See more details on using hashes here.

File details

Details for the file streamlit_sql-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: streamlit_sql-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for streamlit_sql-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d1873e22b526fc48e4cdbe8e75ec98e8f9e94f8293011722f1b8c8ecb5d551df
MD5 cd615a850c7abf7bc6bbec09f57d405d
BLAKE2b-256 7595d1f7feb8e584f031285847b4de0702f9d41c3624e13c0a92dcb4bdaa2890

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page