streamlit-pydantic-object-builder
Streamlit custom component for building and editing Pydantic v2 objects with a drag-and-drop UI.
The widget returns a validated Pydantic model instance (or None while the draft is invalid). JSON is only used as the component wire format.
Install
pip install streamlit-pydantic-object-builder
Requires Python ≥ 3.10, Streamlit ≥ 1.62, and Pydantic ≥ 2.
Quick start
import streamlit as st
from pydantic import BaseModel
from streamlit_pydantic_object_builder import pydantic_object_builder
class Hair(BaseModel):
color: str
length: str
class Person(BaseModel):
name: str
age: int
hair: Hair | None = None
result = pydantic_object_builder(
edit_object=Person(name="Rhubarb", age=41, hair=Hair(color="red", length="short")),
library=[Hair(color="brown", length="long")],
label_fields={Hair: "color"},
return_on_change=True,
key="person_editor",
)
if result is None:
st.warning("Draft does not currently validate")
else:
st.json(result.model_dump(mode="json"))
Pass a model class instead of an instance to start from defaults / empty placeholders.
API
pydantic_object_builder(
edit_object,
library=None,
*,
return_on_change=True,
save_button_position="bottom-left",
label_fields=None,
key=None,
disabled=False,
hide_library=False,
min_height=360,
on_change=None,
on_save=None,
seed=None,
) -> BaseModel | None
| Parameter | Description |
|---|---|
edit_object |
Initial Pydantic instance, or a model class to start blank / from defaults. Applied once per key/seed, not on every rerun |
library |
Instances to drag in. None (default) hides the library pane. [] shows blank “New {Type}” cards only |
return_on_change |
True: return a validated model on each change (debounced), or None while invalid. False: show a Save button and return the last successful save |
save_button_position |
top, bottom, top-left, top-right, bottom-left, or bottom-right |
label_fields |
Map of model type → field name used for compact labels and breadcrumbs |
key |
Streamlit key when more than one editor is on the page |
disabled |
Read-only editor |
hide_library |
Hide the library pane even when library is a list |
min_height |
Minimum host height in pixels (the component grows with content) |
on_change |
Callback when the live return value changes |
on_save |
Callback after a successful Save |
seed |
Change this to re-initialize the editor from edit_object |
| returns | Validated BaseModel, last saved snapshot, or None |
edit_object is the initial value for a given key (like other Streamlit widgets). To load a different object into the same editor, pass a new seed or key.
Features
- Nested models with compact summaries, click-to-expand, pencil to open a nested view, Expand all / Collapse all, Undo / Reset
- Library pane: search, accordion by type, blank “New {Type}” cards, copy-on-drop
- Lists and sets: reorder, insert (
+), duplicate, trash-to-remove, drop-to-replace - Enums,
Literal, date / time / datetime, dict, tuples, unions (including discriminators) UUID,Decimal,EmailStr/HttpUrl(when the matching Pydantic extras are installed)Fieldmetadata: description, examples, numeric and string constraints- Inline validation errors; unsupported types shown read-only
- Streamlit theme tokens and SVG icons
Development
Clone the repo, then:
python -m pip install -e ".[devel]"
cd streamlit_pydantic_object_builder/frontend
npm install
npm run build
If your environment uses TLS interception, npm install --strict-ssl=false may be required.
streamlit run example.py
pytest -q
cd streamlit_pydantic_object_builder/frontend && npm test
During frontend development, run npm run dev in frontend/ and streamlit run example.py in the repo root.
Optional Playwright smoke (demo must be running):
cd streamlit_pydantic_object_builder/frontend
npx playwright install chromium
E2E=1 npx playwright test
Frontend assets are built into the wheel; they are not committed.
cd streamlit_pydantic_object_builder/frontend
npm ci
npm run build
cd ../../
python -m build
Release files for streamlit-pydantic-object-builder 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| streamlit_pydantic_object_builder-0.1.0.tar.gz | 89.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| streamlit_pydantic_object_builder-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 176.9 kB
Release files / streamlit_pydantic_object_builder-0.1.0.tar.gz
| Download URL | streamlit_pydantic_object_builder-0.1.0.tar.gz |
|---|---|
| Size | 89.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ae8a8cc661431064ca98fab0155697c162c99bcc7beb136c5bc06f5ed286542
|
|
BLAKE2b-256 checksum How to use checksums |
341eabad1d2d7ee84ee783b1d817cd046d35ca409e8e87a82269c6824f71ab9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / streamlit_pydantic_object_builder-0.1.0-py3-none-any.whl
| Download URL | streamlit_pydantic_object_builder-0.1.0-py3-none-any.whl |
|---|---|
| Size | 87.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
751ca3d3ef25b84553c531a207ed9df0a07e3b7f373e8601a08d3cf47f961bda
|
|
BLAKE2b-256 checksum How to use checksums |
04de9108639fa1fa25a59288ad96f90da4f4afef36749136e028b87e584df6e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|