Top-level package for pydantic-panel.
Project description
Edit pydantic models with panel. This is just a small little porject i made for my own use, its limited in scope and probably filled with bugs, USE AT YOUR OWN RISK. I will continue to add support for more types as I need them but feel free to open issues with requests or better yet PRs with implementations.
Free software: MIT
Documentation: https://pydantic-panel.readthedocs.io.
Basic Usage
If you import pydantic_panel, it will register the widget automatically using the panel.BasePane.applies interface. After importing, calling panel.panel(model) will return a panel.CompositeWidget whos value is the model. When you change one of the sub-widget values, the new value is validated/coerced using the corresponding pydantic field and if it passes validation/coercion the new value is set on the model itself. This is a one-way sync, if the model field values are changed via code, it does not sync the widgets. Nested models and List[BaseModel] are supported, Dict[str,BaseModel] is trivial to also implement so will probably get around to that soon.
import panel as pn
import pydantic_panel
class SomeModel(pydantic.BaseModel):
name: str
value: float
w = pn.panel(SomeModel) # all widget values will be None
w = pn.panel(SomeModel(name='meaning', value=42)) # widget values will be the same as the model instance
>>> w
# This will display widgets to edit the model in a notebook
>>> w.value
# This will be None if the widgets have not yet been set to values
# if all the required fields have been set, this will be an instance of SomeModel
# with the validated attribute values from the widgets
Features
TODO
Credits
This package was created with Cookiecutter and the briggySmalls/cookiecutter-pypackage project template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pydantic_panel-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dee18b5962411a00463f6af9b946fa2af102abe60d033381f23287c3eca5560 |
|
MD5 | 7f4b0500ecb48232bd0fbd9f4a86e5b0 |
|
BLAKE2b-256 | e26169c76818657e13d4f053a08e398b4bde9054f126664cd1c48f7b9409d867 |