A library that converts a type-annotated function into a webpage with HTML forms?

Kushal Kumaran kushal at locationd.net
Wed Sep 30 21:36:12 EDT 2020


On Wed, Sep 30 2020 at 04:45:47 PM, James Lu <jamtlu at gmail.com> wrote:
> Is there a python library available that converts a type-annotated Python
> function into a webpage with HTML forms?
>
> Something like:
>
>
> def foo(name: str, times: int):
>     return f"Hello {name}!" * times
>
> serve_from(foo, host="0.0.0.0", port=3000)
>
> Turning into a server that serves something like this:
>
> <form>
> <label for="name">name</label>
> <input type="text" id="name" name="name">
> <input type="submit" value="Submit">
> </form>
>
> And hitting the submit button executes the function.
>
> I'm aware I could use sls, and build a form manually, but that's extra work.

https://fastapi.tiangolo.com/

https://fastapi.tiangolo.com/tutorial/path-params/#documentation

Depending on what you need to use the forms for, this might suffice.

-- 
regards,
kushal


More information about the Python-list mailing list