{"id":14959569,"url":"https://github.com/lukasmasuch/streamlit-pydantic","last_synced_at":"2025-10-08T18:56:28.792Z","repository":{"id":40642560,"uuid":"384568260","full_name":"lukasmasuch/streamlit-pydantic","owner":"lukasmasuch","description":"🪄 Auto-generate Streamlit UI from Pydantic Models and Dataclasses.","archived":false,"fork":false,"pushed_at":"2024-08-18T18:31:02.000Z","size":480,"stargazers_count":539,"open_issues_count":44,"forks_count":82,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-12T06:40:00.242Z","etag":null,"topics":["dataclasses","forms","json-schema","pydantic","python","streamlit","streamlit-component","streamlit-library","type-hints","typing"],"latest_commit_sha":null,"homepage":"https://st-pydantic.streamlit.app","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukasmasuch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-09T23:03:31.000Z","updated_at":"2025-05-06T13:48:50.000Z","dependencies_parsed_at":"2024-06-18T21:16:59.214Z","dependency_job_id":"36b390d5-4e83-426e-a4a7-90f2b01975de","html_url":"https://github.com/lukasmasuch/streamlit-pydantic","commit_stats":{"total_commits":185,"total_committers":9,"mean_commits":"20.555555555555557","dds":"0.14054054054054055","last_synced_commit":"9f84145b6b6e74cdff3a7815ab75b0464c4d4f24"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasmasuch%2Fstreamlit-pydantic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasmasuch%2Fstreamlit-pydantic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasmasuch%2Fstreamlit-pydantic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukasmasuch%2Fstreamlit-pydantic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukasmasuch","download_url":"https://codeload.github.com/lukasmasuch/streamlit-pydantic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414457,"owners_count":22067263,"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":["dataclasses","forms","json-schema","pydantic","python","streamlit","streamlit-component","streamlit-library","type-hints","typing"],"created_at":"2024-09-24T13:20:01.595Z","updated_at":"2025-10-08T18:56:23.766Z","avatar_url":"https://github.com/lukasmasuch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable MD033 MD041 --\u003e\n\u003ch1 align=\"center\"\u003e\n    Streamlit Pydantic\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cstrong\u003eAuto-generate Streamlit UI elements from Pydantic models.\u003c/strong\u003e\n\u003c/p\u003e\n\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://pypi.org/project/streamlit-pydantic/\" title=\"PyPi Version\"\u003e\u003cimg src=\"https://img.shields.io/pypi/v/streamlit-pydantic?color=green\u0026style=flat\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://pepy.tech/project/streamlit-pydantic\"\u003e\u003cimg src=\"https://img.shields.io/pypi/dm/streamlit-pydantic\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/streamlit-pydantic/\" title=\"Python Version\"\u003e\u003cimg src=\"https://img.shields.io/badge/Python-3.8%2B-blue\u0026style=flat\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/lukasmasuch/streamlit-pydantic/blob/main/LICENSE\" title=\"Project License\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-green.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://st-pydantic.streamlit.app\"\u003e\u003cimg src=\"https://static.streamlit.io/badges/streamlit_badge_black_white.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#getting-started\"\u003eGetting Started\u003c/a\u003e •\n  \u003ca href=\"#documentation\"\u003eDocumentation\u003c/a\u003e •\n  \u003ca href=\"#support--feedback\"\u003eSupport\u003c/a\u003e •\n  \u003ca href=\"https://github.com/lukasmasuch/streamlit-pydantic/issues/new?assignees=\u0026labels=type%3Abug%2Cstatus%3Aneeds-triage\u0026projects=\u0026template=01_bug-report.yml\"\u003eReport a Bug\u003c/a\u003e •\n  \u003ca href=\"#contribution\"\u003eContribution\u003c/a\u003e •\n  \u003ca href=\"https://github.com/lukasmasuch/streamlit-pydantic/releases\"\u003eChangelog\u003c/a\u003e\n\u003c/p\u003e\n\nStreamlit-pydantic makes it easy to auto-generate UI elements from [Pydantic](https://github.com/samuelcolvin/pydantic/) models or [dataclasses](https://docs.python.org/3/library/dataclasses.html). Just define your data model and turn it into a full-fledged UI form. It supports data validation, nested models, and field limitations. Streamlit-pydantic can be easily integrated into any Streamlit app.\n\n\u003cimg style=\"width: 100%\" src=\"https://raw.githubusercontent.com/lukasmasuch/streamlit-pydantic/main/docs/images/banner.png\"/\u003e\n\n---\n\n\u003cp align=\"center\"\u003e\n     Try out and explore various examples in our playground \u003ca href=\"https://st-pydantic.streamlit.app/\"\u003ehere\u003c/a\u003e.\n\u003c/p\u003e\n\n---\n\n## Highlights\n\n- 🪄\u0026nbsp; Auto-generated UI elements from Pydantic models \u0026 Dataclasses.\n- 📇\u0026nbsp; Out-of-the-box data validation.\n- 📑\u0026nbsp; Supports nested Pydantic models.\n- 📏\u0026nbsp; Supports field limits and customizations.\n- 🎈\u0026nbsp; Easy to integrate into any Streamlit app.\n\n## Getting Started\n\n### Installation\n\n```bash\npip install streamlit-pydantic\n```\n\n### Usage\n\n1. Create a script (`my_script.py`) with a Pydantic model and render it via `pydantic_form`:\n\n    ```python\n    import streamlit as st\n    import streamlit_pydantic as sp\n    from pydantic import BaseModel\n\n\n    class ExampleModel(BaseModel):\n        some_text: str\n        some_number: int\n        some_boolean: bool\n\n    data = sp.pydantic_form(key=\"my_sample_form\", model=ExampleModel)\n    if data:\n        st.json(data.model_dump())\n    ```\n\n2. Run the Streamlit server on the Python script: `streamlit run my_script.py`\n\n3. You can find additional examples in the [examples](#examples) section below.\n\n## Examples\n\n---\n\n\u003cp align=\"center\"\u003e\n     👉\u0026nbsp; Try out and explore these examples in our playground \u003ca href=\"https://st-pydantic.streamlit.app/\"\u003ehere\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\nThe following collection of examples demonstrates how Streamlit Pydantic can be applied in more advanced scenarios. You can find additional - even more advanced - examples in the [examples folder](./examples) or on the [playground](https://st-pydantic.streamlit.app/).\n\n### Simple Form\n\n```python\nimport streamlit as st\nimport streamlit_pydantic as sp\nfrom pydantic import BaseModel\n\n\nclass ExampleModel(BaseModel):\n    some_text: str\n    some_number: int\n    some_boolean: bool\n\ndata = sp.pydantic_form(key=\"my_sample_form\", model=ExampleModel)\nif data:\n    st.json(data.model_dump())\n```\n\n### Date Validation\n\n```python\nimport streamlit as st\nimport streamlit_pydantic as sp\nfrom pydantic import BaseModel, Field, HttpUrl\nfrom pydantic_extra_types.color import Color\n\nclass ExampleModel(BaseModel):\n    url: HttpUrl\n    color: Color = Field(\"blue\", format=\"text\")\n    email: str = Field(..., max_length=100, regex=r\"^\\S+@\\S+$\")\n\ndata = sp.pydantic_form(key=\"my_form\", model=ExampleModel)\nif data:\n    st.json(data.model_dump_json())\n```\n\n### Dataclasses Support\n\n```python\nimport dataclasses\nimport json\n\nimport streamlit as st\nfrom pydantic.json import pydantic_encoder\n\nimport streamlit_pydantic as sp\n\n\n@dataclasses.dataclass\nclass ExampleModel:\n    some_number: int\n    some_boolean: bool\n    some_text: str = \"default input\"\n\n\ndata = sp.pydantic_form(key=\"my_dataclass_form\", model=ExampleModel)\nif data:\n    st.json(dataclasses.asdict(data))\n```\n\n### Complex Nested Model\n\n```python\nfrom enum import Enum\nfrom typing import Set\n\nimport streamlit as st\nfrom pydantic import BaseModel, Field\n\nimport streamlit_pydantic as sp\n\n\nclass OtherData(BaseModel):\n    text: str\n    integer: int\n\n\nclass SelectionValue(str, Enum):\n    FOO = \"foo\"\n    BAR = \"bar\"\n\n\nclass ExampleModel(BaseModel):\n    long_text: str = Field(\n        ..., format=\"multi-line\", description=\"Unlimited text property\"\n    )\n    integer_in_range: int = Field(\n        20,\n        ge=10,\n        le=30,\n        multiple_of=2,\n        description=\"Number property with a limited range.\",\n    )\n    single_selection: SelectionValue = Field(\n        ..., description=\"Only select a single item from a set.\"\n    )\n    multi_selection: Set[SelectionValue] = Field(\n        ..., description=\"Allows multiple items from a set.\"\n    )\n    read_only_text: str = Field(\n        \"Lorem ipsum dolor sit amet\",\n        description=\"This is a ready only text.\",\n        readOnly=True,\n    )\n    single_object: OtherData = Field(\n        ...,\n        description=\"Another object embedded into this model.\",\n    )\n\n\ndata = sp.pydantic_form(key=\"my_form\", model=ExampleModel)\nif data:\n    st.json(data.model_dump_json())\n```\n\n### Render Input\n\n```python\nfrom pydantic import BaseModel\n\nimport streamlit_pydantic as sp\n\n\nclass ExampleModel(BaseModel):\n    some_text: str\n    some_number: int = 10  # Optional\n    some_boolean: bool = True  # Option\n\n\ninput_data = sp.pydantic_input(\n    \"model_input\", model=ExampleModel, group_optional_fields=\"sidebar\"\n)\n```\n\n### Render Output\n\n```python\nimport datetime\n\nfrom pydantic import BaseModel, Field\n\nimport streamlit_pydantic as sp\n\n\nclass ExampleModel(BaseModel):\n    text: str = Field(..., description=\"A text property\")\n    integer: int = Field(..., description=\"An integer property.\")\n    date: datetime.date = Field(..., description=\"A date.\")\n\n\ninstance = ExampleModel(text=\"Some text\", integer=40, date=datetime.date.today())\nsp.pydantic_output(instance)\n```\n\n### Custom Form\n\n```python\nimport streamlit as st\nfrom pydantic import BaseModel\n\nimport streamlit_pydantic as sp\n\n\nclass ExampleModel(BaseModel):\n    some_text: str\n    some_number: int = 10\n    some_boolean: bool = True\n\n\nwith st.form(key=\"pydantic_form\"):\n    data = sp.pydantic_input(key=\"my_custom_form_model\", model=ExampleModel)\n    submit_button = st.form_submit_button(label=\"Submit\")\n    obj = ExampleModel(data)\n\nif data:\n    st.json(obj.model_dump())\n```\n\n## Support \u0026 Feedback\n\n| Type                     | Channel                                              |\n| ------------------------ | ------------------------------------------------------ |\n| 🐛\u0026nbsp; **Bug Reports**       | \u003ca href=\"https://github.com/lukasmasuch/streamlit-pydantic/issues/new?assignees=\u0026labels=type%3Abug%2Cstatus%3Aneeds-triage\u0026projects=\u0026template=01_bug-report.yml\" title=\"Open Bug Report\"\u003e\u003cimg src=\"https://img.shields.io/github/issues/lukasmasuch/streamlit-pydantic/type%3Abug.svg?label=bugs\"\u003e\u003c/a\u003e                                 |\n| ✨\u0026nbsp; **Feature Requests**  | \u003ca href=\"https://github.com/lukasmasuch/streamlit-pydantic/issues/new?assignees=\u0026labels=type%3Aenhancement%2Cstatus%3Aneeds-triage\u0026projects=\u0026template=02_feature-request.yml\" title=\"Open Feature Request\"\u003e\u003cimg src=\"https://img.shields.io/github/issues/lukasmasuch/streamlit-pydantic/feature.svg?label=feature%20requests\"\u003e\u003c/a\u003e                                 |\n| 👩‍💻\u0026nbsp; **Usage Questions**   |  \u003ca href=\"https://github.com/lukasmasuch/streamlit-pydantic/discussions\"\u003e \u003cimg src=\"https://img.shields.io/github/discussions/lukasmasuch/streamlit-pydantic\"\u003e\u003c/a\u003e |\n| 📢\u0026nbsp; **Announcements**  | \u003ca href=\"https://twitter.com/lukasmasuch\" title=\"Follow me on Twitter\"\u003e\u003cimg src=\"https://img.shields.io/twitter/follow/lukasmasuch.svg?style=social\u0026label=Follow\"\u003e |\n\n## Documentation\n\nThe API documentation can be found [here](./docs). To generate UI elements, you can use the high-level [`pydantic_form`](./docs/streamlit_pydantic.ui_renderer.md#function-pydantic_form) method. Or the more flexible lower-level [`pydantic_input`](./docs/streamlit_pydantic.ui_renderer.md#function-pydantic_input) and [`pydantic_output`](./docs/streamlit_pydantic.ui_renderer.md#function-pydantic_output) methods. See the [examples](#examples) section on how to use those methods.\n\n## Contribution\n\n- Pull requests are encouraged and always welcome. Read our [contribution guidelines](https://github.com/lukasmasuch/streamlit-pydantic/tree/main/CONTRIBUTING.md) and check out [help-wanted](https://github.com/lukasmasuch/streamlit-pydantic/issues?utf8=%E2%9C%93\u0026q=is%3Aopen+is%3Aissue+label%3A\"help+wanted\"+sort%3Areactions-%2B1-desc+) issues.\n- Submit Github issues for any [feature request and enhancement](https://github.com/lukasmasuch/streamlit-pydantic/issues/new?assignees=\u0026labels=type%3Aenhancement%2Cstatus%3Aneeds-triage\u0026projects=\u0026template=02_feature-request.yml), [bugs](https://github.com/lukasmasuch/streamlit-pydantic/issues/new?assignees=\u0026labels=type%3Abug%2Cstatus%3Aneeds-triage\u0026projects=\u0026template=01_bug-report.yml), or [documentation](https://github.com/lukasmasuch/streamlit-pydantic/issues/new?assignees=\u0026labels=type%3Adocs%2Cstatus%3Aneeds-triage\u0026projects=\u0026template=03_documentation.yml) problems.\n- By participating in this project, you agree to abide by its [Code of Conduct](https://github.com/lukasmasuch/streamlit-pydantic/blob/main/.github/CODE_OF_CONDUCT.md).\n- The [development section](#development) below contains information on how to build and test the project after you have implemented some changes.\n\n## Development\n\n\u003cp\u003e\n  \u003ca href=\"https://github.com/lukasmasuch/streamlit-pydantic/actions/workflows/ci.yml\"\u003e\u003cimg src=\"https://github.com/lukasmasuch/streamlit-pydantic/actions/workflows/ci.yml/badge.svg\" alt=\"Linting \u0026 testing\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/astral-sh/ruff\"\u003e\u003cimg src=\"https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json\" alt=\"Ruff\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://rye.astral.sh\"\u003e\u003cimg src=\"https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/rye/main/artwork/badge.json\" alt=\"Rye\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/python/mypy\"\u003e\u003cimg src=\"https://img.shields.io/badge/mypy-checked-blue\" alt=\"mypy\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\n\n\nThis repo uses [Rye](https://rye.astral.sh/) for development. To get started, [install Rye](https://rye.astral.sh/) and sync the project:\n\n```bash\nrye sync\n```\n\nRun the playground app:\n\n```bash\nrye run playground\n```\n\nRun linting and type checks:\n\n```bash\nrye run checks\n```\n\n\u003e [!TIP]\n\u003e The linting and formatting is using [ruff](https://github.com/astral-sh/ruff) and\n\u003e type-checking is done with [mypy](https://github.com/python/mypy). You can use\n\u003e the ruff and mypy extensions of your IDE to automatically run these checks\n\u003e during development.\n\nFormat the code:\n\n```bash\nrye run format\n```\n\nRun tests:\n\n```bash\nrye test\n```\n\n---\n\nLicensed **MIT**.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukasmasuch%2Fstreamlit-pydantic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukasmasuch%2Fstreamlit-pydantic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukasmasuch%2Fstreamlit-pydantic/lists"}