FormBuilder.from_pydantic (Beta)
FormBuilder.from_pydantic() generates a Bootstrap-styled form from a Pydantic model.
Naming update in v0.6.1
Starting in Faststrap v0.6.1, the preferred import is FormBuilder to avoid confusion
with FastHTML's native Form element.
v0.6.1+:from faststrap import FormBuilderv0.6.0 and earlier:from faststrap import FormFormremains available as a compatibility alias, but new code should preferFormBuilder.
Import
Basic Usage
from pydantic import BaseModel, EmailStr
class Signup(BaseModel):
email: EmailStr
age: int
marketing_opt_in: bool = False
form = FormBuilder.from_pydantic(Signup, action="/signup")
Supported Field Mapping (MVP)
str-> text inputEmailStr-> email inputint-> number inputfloat-> number input (step="any")bool-> checkboxLiteral[...]-> selectEnum-> select
Options
include=[...]include only selected fieldsexclude=[...]remove selected fieldssubmit_label="Submit"customize button textsubmit_variant="primary"customize button style
Backward Compatibility
If you are maintaining a project pinned below v0.6.1, this older import still works: