Generalize Function to Streamlit Form
Check it out live for full explanation / guide to python inspect.signature
Streamlit-Pydantic shoutout to the work on that library
inspect.signature to build a form input class from a function definition.
Streamlit-Pydantic gives us creation of UI form from Pydantic
BaseModel or standard lib
So we just have to get from function parameters to dataclass or BaseModel and we’re golden!
What’s the point?
Even more rapid development!
Take any CLI or other functional API and create an input form for it!
Add function arguments to get new UI inputs for free!
Memo-ize your form inputs / outputs without the mental overhead of managing the form and the processing function!
Encourage library developers to write accurate type hints
I figured out this could work when hacking the Darts library to make a model playground (see Interactive Timeseries Forecasting with Darts!)
I’ve avoided having to initialize Python objects safely (i.e. without raw
eval), but that limits functionality
Parse out well formed argument docstrings to pass as tooltip hints. (Or just dump the whole
__doc__ of your function at the top of the form)
Turn it into some QA tool akin to Swagger / Postman for python API’s not written to those specs.
Destroy this monstrosity and stick to CLI tools like