Skip to main content

Pydantic-native form validation and rendering. Define a model, get a validated, rendered HTML form. Works with or without Air web framework.

Project description

AirForm

PyPI version

Pydantic-native form validation and rendering for Air. Define an AirModel, get a validated, rendered HTML form with CSRF protection.

Features

  • Type-safe validated data via AirForm[MyModel] generic parameter
  • Works with AirModel (database-backed forms) and plain BaseModel (contact forms, search, etc.)
  • Reads the full AirField metadata vocabulary: Widget, Label, Placeholder, HelpText, Choices, Autofocus, PrimaryKey, Hidden, ReadOnly
  • Auto-skips PrimaryKey and Hidden("form") fields in rendered output
  • HTML5 validation attributes from Pydantic constraints (minlength, maxlength, required)
  • Accessible by default: aria-invalid, aria-describedby, role="alert" on errors
  • Textarea, select, and checkbox rendering from type annotations and metadata
  • Zero-config CSRF protection: render() embeds a signed token, validate() checks it
  • Swappable widget for custom renderers
  • from_request() for async ASGI request handling (works with FastAPI Depends)

Quick start

Database-backed form (most common)

from airmodel import AirModel, AirField
from airform import AirForm
import air

app = air.Air()

class BookOrder(AirModel):
    id: int | None = AirField(default=None, primary_key=True)
    title: str = AirField(label="Book Title", min_length=1)
    quantity: int = AirField(label="Quantity")

class BookOrderForm(AirForm[BookOrder]):
    pass

@app.page
def order_page(request: air.Request):
    return air.Html(
        air.H1("Order a Book"),
        air.Form(
            air.Raw(BookOrderForm().render()),
            air.Button("Order", type_="submit"),
            method="post", action="/order",
        ),
    )

@app.post("/order")
async def submit_order(request: air.Request):
    form = await BookOrderForm.from_request(request)
    if form.is_valid:
        await BookOrder.create(
            title=form.data.title,
            quantity=form.data.quantity,
        )
        return air.Html(air.H1(f"Ordered: {form.data.title}"))
    return air.Html(
        air.Form(
            air.Raw(form.render()),
            air.Button("Order", type_="submit"),
            method="post", action="/order",
        ),
    )

Plain form (no database)

from pydantic import BaseModel
from airfield import AirField
from airform import AirForm

class ContactMessage(BaseModel):
    name: str = AirField(label="Name", autofocus=True)
    email: str = AirField(type="email", label="Email")
    message: str = AirField(widget="textarea", label="Message")

class ContactForm(AirForm[ContactMessage]):
    pass

form = ContactForm()
form.validate({"name": "Audrey", "email": "audreyfeldroy@example.com", "message": "Hello!"})
if form.is_valid:
    send_email(form.data.name, form.data.email, form.data.message)

html = ContactForm().render()

Documentation

Documentation is built with Zensical and deployed to GitHub Pages.

API documentation is auto-generated from docstrings using mkdocstrings.

Docs deploy automatically on push to main via GitHub Actions. To enable this, go to your repo's Settings > Pages and set the source to GitHub Actions.

Installation

uv add AirForm

CLI

Preview rendered form HTML from any Pydantic model:

airform preview myapp.models:ContactModel

Development

See CONTRIBUTING.md for setup instructions.

Author

AirForm was created in 2026 by Audrey M. Roy Greenfeld, extending Daniel Roy Greenfeld's original form rendering design from Air.

Built with Cookiecutter and the audreyfeldroy/cookiecutter-pypackage project template.

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

airform-0.3.1.tar.gz (75.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

airform-0.3.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file airform-0.3.1.tar.gz.

File metadata

  • Download URL: airform-0.3.1.tar.gz
  • Upload date:
  • Size: 75.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for airform-0.3.1.tar.gz
Algorithm Hash digest
SHA256 0481c6985f65ab6d0a90b34891e20e2ea093f317f50525706a0e88f952996af4
MD5 3f64c83744538081873a8343ee8109e9
BLAKE2b-256 8d3da49a3a072b6dcfab3ce0f06fbf3fce3608fec65c43b9c694cc4f3b62d86e

See more details on using hashes here.

Provenance

The following attestation bundles were made for airform-0.3.1.tar.gz:

Publisher: publish.yml on feldroy/AirForm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file airform-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: airform-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for airform-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7a4f0861fc311a7dbc4918a8b070de5108806345479859f828728b126952e31
MD5 19b3ad29ce3bb7fd724582a1e6dcd3ed
BLAKE2b-256 a42e004260be7c8411afd89f252df1479b288111968dafddcce06aee0229fc7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for airform-0.3.1-py3-none-any.whl:

Publisher: publish.yml on feldroy/AirForm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page