Pydantic-based HTTP forms
Project description
Fodantic
Pydantic-based HTTP forms.
Pydantic is the most widely used data validation library for Python, but it's hard to use it with regular HTTP forms./. until now.
Fodantic allow you to quickly wrap your Pydantic models and use them as forms: with support for multiple values, checkboxes, error handling, and integration with your favorite ORM.
A simple example
from fodantic import formable
from pydantic import BaseModel
@formable
class UserModel(BaseModel):
name: str
friends: list[int]
active: bool = True
request_data = Multidict(('name', 'John Doe'), ('friends', '2'), ('friends', '3')}
form = UserModel.as_form(request_data, obj=None)
print(form)
#> UserModel.as_form(name='John Doe', friends=[2, 3], active=False)
print(form.fields["name"].value)
#> John Doe
print(form.fields["name"].error)
#>
Installation
pip install fodantic
Requirements
- Python 3.10+
- Pydantic 2.*
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fodantic-0.0.1.tar.gz
(3.8 kB
view hashes)