maxfordham / ipyautoui

create ipywidgets user input form pydantic model or jsonschema
https://maxfordham.github.io/ipyautoui/
38 stars 5 forks source link

Whats the relationship to FastUI✨ #280

Open paddymul opened 4 months ago

paddymul commented 4 months ago

Is your feature request related to a problem? Please describe. I'm writing to think here. Pydantic the comapny is working on FastUI but that seems more aimed at creating simple static websites. Samuel doesn't seem to be too familiar with ipywidgets or interested in supporting them. https://github.com/pydantic/FastUI/issues/51

I have a dataframe widget that I'm looking at doing a couple of things with.

  1. Continue supporting IPYwidgets
  2. Add more Pydantic typing to the widget code
  3. Possibly support FastUI

I would like that to be easier

Describe the solution you'd like Could you show an example of supporting both with the minimal amount of extra code?

Describe alternatives you've considered I'm also looking at porting my widget to streamlit and solara. Do they have a Pydantic story? Anything I should look at?

Additional context N/A

jgunstone commented 4 months ago

hi there @paddymul -

currently no relation to FastUI. I'm interested in it though and had previously spotted your issue - your message here prompted me to respond and also create this: https://github.com/pydantic/FastUI/issues/197.

I'm not sure exactly what you're after... but here are some bits that are maybe of interest:

In terms of using pydantic with jupyter-widgets ... the landscape is a little confusing as traitlets fulfils much of the same functionality as pydantic in a widget context. The way I do it is:

when a ipyautoui form is built, kwargs stored in json_schema_extra are passed to ipyautoui traits - this is how I'm able to store form configuration in the pydantic model.

every form widget has a _value dict which is defined by the pydantic model. on change of the ui widget it updates, and then the whole value gets validated by the pydantic model, and then changes to the whole form then get passed back to the ui objects. this is a little complex (and could probs be done better) but is handled here: https://github.com/maxfordham/ipyautoui/blob/main/src/ipyautoui/watch_validate.py

other: have you seen pandera ? its pydantic for dataframes. in ipyautoui i interpret the following type of pydantic model as a dataframe: https://github.com/maxfordham/ipyautoui/blob/main/src/ipyautoui/demo_schemas/editable_datagrid.py