{"id":47981003,"url":"https://github.com/artygo8/streamlit-sqlalchemy","last_synced_at":"2026-04-04T11:05:14.452Z","repository":{"id":210752959,"uuid":"726791520","full_name":"artygo8/streamlit-sqlalchemy","owner":"artygo8","description":"Templating for streamlit and sqlalchemy","archived":false,"fork":false,"pushed_at":"2026-01-28T09:29:30.000Z","size":9531,"stargazers_count":23,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-29T00:51:01.485Z","etag":null,"topics":["sql","sqlalchemy","streamlit","streamlit-component","templating"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/artygo8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-12-03T12:18:42.000Z","updated_at":"2026-01-28T09:23:28.000Z","dependencies_parsed_at":"2023-12-17T09:26:43.201Z","dependency_job_id":"4f6b6b75-abfe-42ad-acf7-01f413f88e9e","html_url":"https://github.com/artygo8/streamlit-sqlalchemy","commit_stats":null,"previous_names":["artygo8/streamlit-sqlalchemy"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/artygo8/streamlit-sqlalchemy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artygo8%2Fstreamlit-sqlalchemy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artygo8%2Fstreamlit-sqlalchemy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artygo8%2Fstreamlit-sqlalchemy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artygo8%2Fstreamlit-sqlalchemy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/artygo8","download_url":"https://codeload.github.com/artygo8/streamlit-sqlalchemy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artygo8%2Fstreamlit-sqlalchemy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31397056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T10:20:44.708Z","status":"ssl_error","status_checked_at":"2026-04-04T10:20:06.846Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sql","sqlalchemy","streamlit","streamlit-component","templating"],"created_at":"2026-04-04T11:05:14.261Z","updated_at":"2026-04-04T11:05:14.437Z","avatar_url":"https://github.com/artygo8.png","language":"Python","readme":"# Streamlit SQLAlchemy Integration\n\n## Overview\n\n`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.\n\n![assets/crud_create.png](./assets/crud_create.png)\n![assets/crud_update.png](./assets/crud_update.png)\n\n## Features\n\n- **Easy Initialization**: Initialize the SQLAlchemy connection with a simple method call.\n- **CRUD Operations**: Create, read, update, and delete operations are streamlined with minimal code.\n- **Dynamic Forms**: Automatically generate forms for creating and updating database objects.\n- **SQLTypes Support**: `String`, `Text`, `Integer`, `Float`, `Boolean`, `Date`, `DateTime`, `Time`, `Enum`.\n- **Foreign Key Support**: Easily handle foreign key relationships in forms.\n\n## Installation\n\n```bash\npip install streamlit_sqlalchemy\n```\n\n## Usage\n\n1. **Initialize the Engine:**\n\n    ```python\n    from streamlit_sqlalchemy import StreamlitAlchemyMixin\n\n    # Create your SQLAlchemy model\n    class YourModel(Base, StreamlitAlchemyMixin):\n        __tablename__ = \"your_model\"\n\n        id = Column(Integer, primary_key=True)\n        name = Column(String)\n        active = Column(Boolean, default=True)\n        count = Column(Integer)\n        text = Column(Text)\n        created_at = Column(DateTime)\n\n    # Initialize the connection\n        StreamlitAlchemyMixin.st_initialize(connection=conn)\n    ```\n\n2. **CRUD Tabs:**\n\n    ```python\n    YourModel.st_crud_tabs()\n    ```\n\n3. **Create Form:**\n\n    ```python\n    YourModel.st_create_form()\n    ```\n\n4. **Edit Button:**\n\n    ```python\n    your_model_instance.st_edit_button(\"Edit\", {\"field\": \"value\"})\n    ```\n\n5. **Delete Button:**\n\n    ```python\n    your_model_instance.st_delete_button()\n    ```\n\n## Advanced Usage\n\n1. **Customize behavior with Meta Attributes:**\n\n    ```python\n    class YourModel(Base, StreamlitAlchemyMixin):\n        __tablename__ = \"your_model\"\n\n        id = Column(Integer, primary_key=True)\n        name = Column(String)\n        active = Column(Boolean, default=True)\n        count = Column(Integer)\n        text = Column(Text)\n        created_at = Column(DateTime)\n\n        # Customize the form fields with non-defaults\n        __st_input_meta__ = {\n            'name': st.text_input,\n            'active': lambda *a, **kw: st.checkbox(*a, **kw, value=False),\n        }\n\n        # Customize display of the instances in the selectbox\n        __st_repr__ = lambda _self: f'{self.name} ({self.count})'\n\n        # Customize the order of the instances in the selectbox\n        __st_order_by__ = lambda _self: self.count\n    ```\n\n2. **CRUD Tabs:**\n\n    ```python\n    YourModel.st_crud_tabs(\n        defaults={\"name\": \"Default Name\"},  # Will not appear in the create form\n        filter_by={\"active\": True},  # Will filter the instances in the selectbox\n        except_columns=[\"active\"],  # Will not appear in the update form\n        border=True,  # Will add a border around the form\n    )\n    ```\n\n3. **Create Form:**\n\n    ```python\n    YourModel.st_create_form(\n        defaults={\"active\": False},  # Will not appear in the form\n        border=True,  # Will add a border around the form\n    )\n    ```\n\n4. **Edit Button:**\n\n    ```python\n    your_model_instance.st_edit_button(\n        \"Edit\",  # Button label\n        {\"name\": \"New Name\"},  # Will be updated on click\n        # Any other kwargs will be passed to the st.button\n    )\n    ```\n\n5. **Delete Button:**\n\n    ```python\n    your_model_instance.st_delete_button(\n        label=\"Delete\",  # Button label\n        # Any other kwargs will be passed to the st.button\n    )\n    ```\n\n## Simple Example\n\n```python\nimport streamlit as st\nfrom sqlalchemy import create_engine, Column, String, Integer\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom streamlit_sqlalchemy import StreamlitAlchemyMixin\n\nBase = declarative_base()\n\nclass ExampleModel(Base, StreamlitAlchemyMixin):\n    __tablename__ = \"example\"\n\n    id = Column(Integer, primary_key=True)\n    name = Column(String)\n\n# Initialize the connection\nCONNECTION = st.connection(\"example_db\", type=\"sql\")\nBase.metadata.create_all(CONNECTION.engine)\nStreamlitAlchemyMixin.st_initialize(CONNECTION)\n\n# Create CRUD tabs\nExampleModel.st_crud_tabs()\n```\n\n## Comprehensive Example\n\n```python\nimport logging\nfrom pathlib import Path\n\nimport streamlit as st\n\nfrom examples.models import Base, Task, User\nfrom streamlit_sqlalchemy import StreamlitAlchemyMixin\n\n\ndef show_single_task(task):\n    col1, col2, col3 = st.columns([1, 1, 1])\n    if task.done:\n        col1.write(f\" - ~~{task.description}~~\")\n        with col2:\n            task.st_delete_button()\n    else:\n        if task.due_date:\n            date_color = \"red\" if task.due_date \u003c datetime.now() else \"green\"\n            col1.write(f\" - {task.description} (:{date_color}[{task.due_date.strftime('%H:%M - %d.%m.%Y')}])\")\n        else:\n            col1.write(f\" - {task.description}\")\n        with col2:\n            task.st_edit_button(\"Done\", {\"done\": True})\n        with col3:\n            task.st_delete_button()\n\n\ndef app():\n    st.title(\"Streamlit SQLAlchemy Demo\")\n\n    User.st_crud_tabs()\n\n    with CONNECTION.session as session:\n        for user in session.query(User).all():\n            with st.expander(f\"### {user.name}'s tasks:\"):\n                c = st.container()\n\n                st.write(\"**Add a new task:**\")\n                Task.st_create_form(defaults={\"user_id\": user.id, \"done\": False})\n                with c:\n                    if not user.tasks:\n                        st.caption(\"No tasks yet.\")\n\n                    for task in user.tasks:\n                        show_single_task(task)\n\n\ndef main():\n    if not Path(\"example.db\").exists():\n        Base.metadata.create_all(CONNECTION.engine)\n\n    StreamlitAlchemyMixin.st_initialize(connection=CONNECTION)\n\n    app()\n\n\nif __name__ == \"__main__\":\n    # initialize the database connection\n    # (see https://docs.streamlit.io/library/api-reference/connections/st.connection)\n    CONNECTION = st.connection(\"example_db\", type=\"sql\")\n    main()\n```\n\nYou can explore this provided [example](./examples/example.py), and launch it from the root directory (because it relies on relative imports):\n\n```bash\npython -m streamlit run examples/example.py\n```\n\n![assets/streamlit-example-2023-12-31-16-12-91.gif](./assets/streamlit-example-2023-12-31-16-12-91.gif)\n\n\n## Contributing\n\nWe welcome contributions! See our [contribution guidelines](./CONTRIBUTING) for more details.\n\n## License\n\nThis project is licensed under the Apache License 2.0 - see the [LICENSE](./LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartygo8%2Fstreamlit-sqlalchemy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartygo8%2Fstreamlit-sqlalchemy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartygo8%2Fstreamlit-sqlalchemy/lists"}