streamlit-crud


Namestreamlit-crud JSON
Version 0.1.61 PyPI version JSON
download
home_pagehttps://github.com/davidho123/streamlit-crud
SummaryAutomatically generate UI components based on the data model, and implement CRUD functionalities.
upload_time2025-01-21 02:30:33
maintainerNone
docs_urlNone
authordavidho
requires_pythonNone
licenseMIT
keywords crud streamlit model function python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Streamlit-Crud

**Automatically generate UI interfaces and implement CRUD functions**

![CRUD主界面](home.png)\
![新增表单](creat.png)\
![修改表单](modify.png)

## Table of Contents
* [Overview](README.md##1.Overview)
* [Features](README.md##2.Features)
* [Usage](README.md##3.Usage)
* [Version Information](README.md##4.Version Information)

## 1. Overview
This module is a class that automatically generates form components and CRUD buttons based on the database model. After the form is submitted, it implements the CRUD functions of the database.
## 2. Features
- Dynamically generate form components based on the database model.\
The form components are dynamically generated according to the field types of the model.
- Generate CRUD buttons, and after submission, implement the CRUD functions of the database.
- The database is displayed in a dataframe table, which is equipped with filtering, searching, pagination, and downloading functions.
- Add a log folder in the root directory, create a log file with the current date, and record the information of adding, deleting, modifying, and querying.
>Note: The newly added table export generates the file name based on local time.\
>The download of the streamlit table uses UTC time. Therefore, this export function is added.

## 3. Usage
- Install the required packages
```Python
pip install streamlit_crud
pip install streamlit sqlmodel streamlit_antd_components pandas
```
UI component generation uses streamlit
Database model uses sqlmodel
Table pagination function uses streamlit_antd_components
Table filtering uses pandas
- Usage example

**The StreamlitCrud class requires two parameters, the first is the database model class, and the second is the database connection address.**\
**Run the main method of StreamlitCrud to generate the UI interface and implement CRUD functions.**

>Note:\
>1.In the database model class, when the field name is "Remarks", a multi-line text component will be used.\
>2.The initial value of the form component is initialized according to the default value of the model field.\
>3.In the creat and modify forms, each item in the form is a required field, and an error will be prompted if it is not filled in.\
>4.Select the wide mode, otherwise the buttons will be cramped together\
> st.set_page_config(layout="wide")

```Python
import streamlit as st
from sqlmodel import SQLModel, Field
from streamlit_crud import StreamlitCrud
from datetime import date, datetime

# Define the database model class
class Data(SQLModel, table=True):
    __tablename__ = "data"
    __table_args__ = {'extend_existing': True}
    id: int = Field(default=None, primary_key=True,
                    sa_column_kwargs={"autoincrement": True})
    Name: str = Field(default="")
    Price: float = Field(default=0.0)
    In_Stock: bool = Field(default=True)
    Entry_Date: date = Field(default=date.today())
    Entry_Time: str = Field(default=datetime.now().strftime('%H:%M:%S'))
    Remarks: str = Field(default="None")  # The remarks attribute will use a multi-line text component

database_url = "sqlite:///example.db"
# Select the wide mode, otherwise the buttons will be cramped together.
st.set_page_config(page_title="数据管理系统",  layout="wide")
stcrud = StreamlitCrud(Data, database_url)
stcrud.main()
```
## 4. Version Information
v 0.1
Provides the class module to implement the CRUD functions of the database.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/davidho123/streamlit-crud",
    "name": "streamlit-crud",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "crud, streamlit, model, function, python",
    "author": "davidho",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/2c/9b/dca2d2386a729975edab202397cd239b563c89f603b98e36da0d9a3157e8/streamlit_crud-0.1.61.tar.gz",
    "platform": null,
    "description": "\r\n# Streamlit-Crud\r\n\r\n**Automatically generate UI interfaces and implement CRUD functions**\r\n\r\n![CRUD\u4e3b\u754c\u9762](home.png)\\\r\n![\u65b0\u589e\u8868\u5355](creat.png)\\\r\n![\u4fee\u6539\u8868\u5355](modify.png)\r\n\r\n## Table of Contents\r\n* [Overview](README.md##1.Overview)\r\n* [Features](README.md##2.Features)\r\n* [Usage](README.md##3.Usage)\r\n* [Version Information](README.md##4.Version Information)\r\n\r\n## 1. Overview\r\nThis module is a class that automatically generates form components and CRUD buttons based on the database model. After the form is submitted, it implements the CRUD functions of the database.\r\n## 2. Features\r\n- Dynamically generate form components based on the database model.\\\r\nThe form components are dynamically generated according to the field types of the model.\r\n- Generate CRUD buttons, and after submission, implement the CRUD functions of the database.\r\n- The database is displayed in a dataframe table, which is equipped with filtering, searching, pagination, and downloading functions.\r\n- Add a log folder in the root directory, create a log file with the current date, and record the information of adding, deleting, modifying, and querying.\r\n>Note: The newly added table export generates the file name based on local time.\\\r\n>The download of the streamlit table uses UTC time. Therefore, this export function is added.\r\n\r\n## 3. Usage\r\n- Install the required packages\r\n```Python\r\npip install streamlit_crud\r\npip install streamlit sqlmodel streamlit_antd_components pandas\r\n```\r\nUI component generation uses streamlit\r\nDatabase model uses sqlmodel\r\nTable pagination function uses streamlit_antd_components\r\nTable filtering uses pandas\r\n- Usage example\r\n\r\n**The StreamlitCrud class requires two parameters, the first is the database model class, and the second is the database connection address.**\\\r\n**Run the main method of StreamlitCrud to generate the UI interface and implement CRUD functions.**\r\n\r\n>Note:\\\r\n>1.In the database model class, when the field name is \"Remarks\", a multi-line text component will be used.\\\r\n>2.The initial value of the form component is initialized according to the default value of the model field.\\\r\n>3.In the creat and modify forms, each item in the form is a required field, and an error will be prompted if it is not filled in.\\\r\n>4.Select the wide mode, otherwise the buttons will be cramped together\\\r\n> st.set_page_config(layout=\"wide\")\r\n\r\n```Python\r\nimport streamlit as st\r\nfrom sqlmodel import SQLModel, Field\r\nfrom streamlit_crud import StreamlitCrud\r\nfrom datetime import date, datetime\r\n\r\n# Define the database model class\r\nclass Data(SQLModel, table=True):\r\n    __tablename__ = \"data\"\r\n    __table_args__ = {'extend_existing': True}\r\n    id: int = Field(default=None, primary_key=True,\r\n                    sa_column_kwargs={\"autoincrement\": True})\r\n    Name: str = Field(default=\"\")\r\n    Price: float = Field(default=0.0)\r\n    In_Stock: bool = Field(default=True)\r\n    Entry_Date: date = Field(default=date.today())\r\n    Entry_Time: str = Field(default=datetime.now().strftime('%H:%M:%S'))\r\n    Remarks: str = Field(default=\"None\")  # The remarks attribute will use a multi-line text component\r\n\r\ndatabase_url = \"sqlite:///example.db\"\r\n# Select the wide mode, otherwise the buttons will be cramped together.\r\nst.set_page_config(page_title=\"\u6570\u636e\u7ba1\u7406\u7cfb\u7edf\",  layout=\"wide\")\r\nstcrud = StreamlitCrud(Data, database_url)\r\nstcrud.main()\r\n```\r\n## 4. Version Information\r\nv 0.1\r\nProvides the class module to implement the CRUD functions of the database.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Automatically generate UI components based on the data model, and implement CRUD functionalities.",
    "version": "0.1.61",
    "project_urls": {
        "Homepage": "https://github.com/davidho123/streamlit-crud"
    },
    "split_keywords": [
        "crud",
        " streamlit",
        " model",
        " function",
        " python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2c9bdca2d2386a729975edab202397cd239b563c89f603b98e36da0d9a3157e8",
                "md5": "7381db75eef164b47e7e9dddf0484e52",
                "sha256": "7e6ca32415a1d73c06e3cf2458088d2e9a074616d6dac3198d02004049c910b0"
            },
            "downloads": -1,
            "filename": "streamlit_crud-0.1.61.tar.gz",
            "has_sig": false,
            "md5_digest": "7381db75eef164b47e7e9dddf0484e52",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9996,
            "upload_time": "2025-01-21T02:30:33",
            "upload_time_iso_8601": "2025-01-21T02:30:33.009847Z",
            "url": "https://files.pythonhosted.org/packages/2c/9b/dca2d2386a729975edab202397cd239b563c89f603b98e36da0d9a3157e8/streamlit_crud-0.1.61.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-21 02:30:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "davidho123",
    "github_project": "streamlit-crud",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "streamlit-crud"
}
        
Elapsed time: 4.22347s