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 few lines 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
  • Select the columns to display to the user
  • Add a column to show the rolling sum of a numeric column

FILTER

  • Filter the data by some columns before presenting the table. It can use columns from relationship tables too.
  • Let users filter the columns by selecting conditions in the sidebar
  • 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

Define a ModelOpts and add it to the argument of show_sql_ui function:

from streamlit_sql import ModelOpts, show_sql_ui

conn = st.connection("sql", url="<db_url>")

model_opts = ModelOpts(MyModel)
show_sql_ui(conn, model_opts)

Customize

You can configure the CRUD interface by giving optional arguments to the ModelOpts object. See its docstring for more information or at documentation webpage:

Multiple Models

You can set the model_opts argument to a list of ModelOpts objects. In this case, a st.selectbox will let user to select the table to work on.

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.1.8.tar.gz (11.5 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.1.8-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: streamlit_sql-0.1.8.tar.gz
  • Upload date:
  • Size: 11.5 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.1.8.tar.gz
Algorithm Hash digest
SHA256 f619b86f019b9c8cdf9072ec49d76c2c8de9403814dc6aa8548746314d64ed4e
MD5 e4c5115fb6fd991a5c0e110ebf14703a
BLAKE2b-256 8bfc523ef8391e3cb31ca1b38792401e8c8acecb341bfbd0502d3c5b3cf218b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: streamlit_sql-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 12.3 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.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 caf3f2e343ff7a16b40b5ee373cc216506260e206756a35020c70a48a3da1c53
MD5 4aa5f727fa52098584808e9e66204eec
BLAKE2b-256 2c4f8e1c2cf2db518f00638c6e128adaa66fc2a92b312e7672801f28212581b0

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