Streamlit SQLAlchemy Integration
Overview
streamlit_sqlalchemy is a Python module that provides seamless integration between Streamlit and SQLAlchemy models. It simplifies the process of creating, updating, and deleting database objects through Streamlit’s user-friendly interface.
Features
- Easy Initialization: Initialize the SQLAlchemy connection with a simple method call.
- CRUD Operations: Create, read, update, and delete operations are streamlined with minimal code.
- Dynamic Forms: Automatically generate forms for creating and updating database objects.
- SQLTypes Support:
String
,Text
,Integer
,Float
,Boolean
,Date
,DateTime
,Time
. - Foreign Key Support: Easily handle foreign key relationships in forms.
Installation
pip install streamlit_sqlalchemy
Usage
-
Initialize the Engine:
from streamlit_sqlalchemy import StreamlitAlchemyMixin # Create your SQLAlchemy model class YourModel(Base, StreamlitAlchemyMixin): __tablename__ = "your_model" id = Column(Integer, primary_key=True) # Other columns... # Initialize the connection StreamlitAlchemyMixin.st_initialize(connection=conn)
-
CRUD Tabs:
YourModel.st_crud_tabs()
-
Create Form:
YourModel.st_create_form()
-
Edit Button:
your_model_instance.st_edit_button("Edit", {"field": "value"})
-
Delete Button:
your_model_instance.st_delete_button()
Advanced Usage
Learn more: GitHub - artygo8/streamlit-sqlalchemy: Templating for streamlit and sqlalchemy