Skip to main content

Some templating for streamlit and sqlalchemy

Project description

streamlit-sqlalchemy

Some templating for streamlit and sqlalchemy

streamlit-sql-crud

Status & Objectives

  • Integer fields
  • String fields
  • Many2One
  • Many2Many

Usage

python3 -m pip install streamlit-sqlalchemy
python3 -m streamlit run example.py

Add the mixin to your SQLAlchemy defined class

# sqlalchemy stuff
Base = declarative_base()
engine = create_engine("sqlite:///db.sqlite3")

class Awesome(Base, StreamlitAlchemyMixin):
    __tablename__ = "awesome"

    id = Column(Integer, primary_key=True)
    name = Column(String)
    other_field = Column(Integer)

Then you need to link the Mixin with the Base, in order to have access to the foreign keys. And to the engine for access to the database.

# Must be called before any other method
StreamlitAlchemyMixin.sam_initialize(Base, engine)

Then you have access to streamlit components.

# The classic 3 tabs
Awesome.sam_crud_tabs()

# Create
Awesome.sam_create_form()

# Update with a select choice on top
Awesome.sam_update_select_form()

# Delete with a select choice on top
Awesome.sam_delete_select_form()

for awesome in Awesome.sam_get_all():
    # Update a single element
    awesome.sam_update_form()

    # Delete an element
    awesome.sam_delete_button()

Contribute

You are welcome to contribute!

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_sqlalchemy-0.0.3.tar.gz (45.5 kB view hashes)

Uploaded Source

Built Distribution

streamlit_sqlalchemy-0.0.3-py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 3

Supported by

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