{"id":22429845,"url":"https://github.com/edkedk99/streamlit_sql","last_synced_at":"2025-10-16T00:31:26.862Z","repository":{"id":266506479,"uuid":"898507177","full_name":"edkedk99/streamlit_sql","owner":"edkedk99","description":"CRUD interface for sqlalchemy using streamlit","archived":false,"fork":false,"pushed_at":"2025-01-21T17:17:57.000Z","size":782,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-29T09:01:50.578Z","etag":null,"topics":["crud","sqlalchemy","streamlit","streamlit-component"],"latest_commit_sha":null,"homepage":"https://edkedk99.github.io/streamlit_sql/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edkedk99.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-12-04T14:17:13.000Z","updated_at":"2025-01-22T01:24:22.000Z","dependencies_parsed_at":"2024-12-04T16:37:43.868Z","dependency_job_id":"2d883d11-8446-405f-9351-0685423b5a4c","html_url":"https://github.com/edkedk99/streamlit_sql","commit_stats":null,"previous_names":["edkedk99/streamlit_sql"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edkedk99%2Fstreamlit_sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edkedk99%2Fstreamlit_sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edkedk99%2Fstreamlit_sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edkedk99%2Fstreamlit_sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edkedk99","download_url":"https://codeload.github.com/edkedk99/streamlit_sql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236658022,"owners_count":19184581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["crud","sqlalchemy","streamlit","streamlit-component"],"created_at":"2024-12-05T21:05:56.889Z","updated_at":"2025-10-16T00:31:26.856Z","avatar_url":"https://github.com/edkedk99.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# streamlit_sql\n\n## Introduction\n\nCreating a CRUD interface can be a tedious and repetitive task. This package is intended to replace all of that with a few lines of code that involves simply creating a sqlalchemy statement and calling the main *SqlUi* class with only 3 required arguments. All extra and advanced features are available by supplying non-required arguments to the class initialization.\n\nWhen the main class is initialized, it will display the database table data with most of the expected features of a crud interface, so the user will be able to **read, filter, update, create and delete rows** with many useful features. \n\nIt also offers useful information about the data as property like:\n- df: The Dataframe displayed in the screen\n- selected_rows: The position of selected rows. This is not the row id\n- qtty_rows: The quantity of all rows after filtering\n\n## Demo\n\nSee the package in action [here](https://example-crud.streamlit.app/).\n\n## Features\n\n### READ\n\n- Display as a regular st.dataframe\n- Add pagination, displaying only a set of rows each time\n- Set the dataframe to be displayed using standard sqlalchemy select statement, where you can JOIN, ORDER BY, WHERE, etc.\n- Add a column to show the rolling sum of a numeric column\n- Conditional styling if the DataFrame based on each row value. For instance, changing its background color\n- Format the number display format.\n- Display multiple CRUD interfaces in the same page using unique base_key.\n- Show *many-to-one* relation in edit forms with basic editing.\n- Log database modification to stderr or to your prefered loguru handler. (can be disabled)\n\n### FILTER\n\n- Filter the data by some columns before presenting the table.\n- Let users filter the columns by selecting conditions in the filter expander\n- Give possible candidates when filtering using existing values for the columns\n- Let users select ForeignKey's values using the string representation of the foreign table, instead of its id number\n\n### UPDATE\n\n- Users update rows with a dialog opened by selecting the row and clicking the icon\n- Text columns offers candidates from existing values\n- ForeignKey columns are added by the string representation instead of its id number\n- In Update form, list all ONE-TO-MANY related rows with pagination, where you can directly create and delete related table rows. \n- Log updates to database to stderr or in anyway **loguru** can handle\n\n\n### CREATE\n\n- Users create new rows with a dialog opened by clicking the create button\n- Text columns offers candidates from existing values\n- Hide columns to fill by offering default values\n- ForeignKey columns are added by the string representation instead of its id number\n\n### DELETE\n\n- Delete one or multiple rows by selecting in DataFrame and clicking the corresponding button. A dialog will list selected rows and confirm deletion.\n\n\n\n## Requirements\n\nAll the requirements you should probably have anyway.\n\n1. streamlit and sqlalchemy\n2. Sqlalchemy models needs a __str__ method\n2. Id column should be called \"id\"\n3. Relationships should be added for all ForeignKey columns \n\n\n## Basic Usage\n\nInstall the package using pip:\n\n```bash\npip install streamlit_sql\n```\n\nRun `show_sql_ui` as the example below:\n\n```python\nfrom streamlit_sql import show_sql_ui\nfrom sqlalchemy import select\n\nconn = st.connection(\"sql\", url=\"\u003cdb_url\u003e\")\n\nstmt = (\n    select(\n        db.Invoice.id,\n        db.Invoice.Date,\n        db.Invoice.amount,\n        db.Client.name,\n    )\n    .join(db.Client)\n    .where(db.Invoice.amount \u003e 1000)\n    .order_by(db.Invoice.date)\n)\n\nshow_sql_ui(conn=conn,\n            read_instance=stmt,\n            edit_create_model=db.Invoice,\n            available_filter=[\"name\"],\n            rolling_total_column=\"amount\",\n)\n\nshow_sql_ui(conn, model_opts)\n```\n\n!!! warning\n    In the statement, **always** include the primary_key column, that should be named *id*\n\n### Interface\n\n- Filter: Open the \"Filter\" expander and fill the inputs\n- Add row: Click on \"plus\" button (no dataframe row can be selected)\n- Edit row: Click on \"pencil\" button (one and only one dataframe row should be selected)\n- Delete row: Click on \"trash\" button (one or more dataframe rows should be selected)\n\n\n## Customize\n\nYou 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](https://edkedk99.github.io/streamlit_sql/api/#streamlit_sql.SqlUi):\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedkedk99%2Fstreamlit_sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedkedk99%2Fstreamlit_sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedkedk99%2Fstreamlit_sql/lists"}