API Reference¶
AirField: UI presentation vocabulary for Pydantic models.
annotated-types is for validation. airfield is for presentation. Define once on the model, render anywhere.
Autofocus
dataclass
¶
Bases: BasePresentation
This field should receive input focus when the UI context loads.
In a form: sets the autofocus attribute on the input. In a CLI: this field is prompted first. In a TUI: this widget receives initial focus.
Only one field per form/view should have this.
Source code in src/airfield/types.py
BasePresentation
¶
Base class for all presentation metadata.
Consumers can do isinstance(m, BasePresentation) while
traversing field annotations to find all airfield metadata.
Source code in src/airfield/types.py
Choices
dataclass
¶
Bases: BasePresentation
Constrains the field to a set of labeled options.
In a form: rendered as a <select>, radio group, or combobox.
In a CLI: a numbered menu or autocomplete.
In API docs: an enumerated parameter.
Each option is (value, display_label).
Source code in src/airfield/types.py
ColumnAlign
dataclass
¶
Bases: BasePresentation
How to align the field's value in a table column.
Source code in src/airfield/types.py
ColumnWidth
dataclass
¶
Bases: BasePresentation
Preferred width for the field in a table column.
Expressed as a relative weight. A field with weight=2 gets roughly twice the space of a field with weight=1.
Source code in src/airfield/types.py
Compact
dataclass
¶
Bases: BasePresentation
How to represent this field in space-constrained contexts.
Source code in src/airfield/types.py
CsrfToken
dataclass
¶
Bases: BasePresentation
Marks this field as a CSRF protection token.
Form renderers should render this as a hidden input with a signed value. Form validators should verify the signature before processing other fields. The field should not appear in user-facing form layouts.
Source code in src/airfield/types.py
DisplayFormat
dataclass
¶
Bases: BasePresentation
How to format the field's value for display (not input).
Common patterns
"percent" 0.42 -> "42%"
"currency" 1234.5 -> "$1,234.50"
"bytes" 1048576 -> "1 MB"
"relative_time" datetime -> "3 hours ago"
"%Y-%m-%d" datetime -> "2026-03-18"
Source code in src/airfield/types.py
Filterable
dataclass
¶
Bases: BasePresentation
Whether and how this field should appear in search/filter UI.
In a table: adds a filter control to the column.
In an admin panel: adds to the filter sidebar.
In a CLI list command: adds a --field=value filter flag.
Source code in src/airfield/types.py
Grouped
dataclass
¶
Bases: BasePresentation
Assigns the field to a named group for layout purposes.
In a form: fields in the same group appear in the same fieldset. In a table: groups can become column groups. In a detail view: groups become sections.
Source code in src/airfield/types.py
HelpText
dataclass
¶
Bases: BasePresentation
Explanatory text that supplements the label.
In a form: text below the input. In a CLI: shown when the user asks for help on a field. In API docs: the parameter description. In a table: tooltip on the column header.
Source code in src/airfield/types.py
Hidden
dataclass
¶
Bases: BasePresentation
Field should not be shown in the specified contexts.
With no arguments, hidden everywhere. Standard context names:
"form", "table", "detail", "api", "cli", "export"
Source code in src/airfield/types.py
Label
dataclass
¶
Bases: BasePresentation
Human-readable name for the field.
Used everywhere a field needs a display name: form labels, table headers, CLI prompts, chart axis labels, API docs.
Without this, consumers fall back to the field name with underscores replaced by spaces and title-cased.
Source code in src/airfield/types.py
Placeholder
dataclass
¶
Bases: BasePresentation
Example or hint text shown when the field is empty.
In a form: the placeholder attribute. In a CLI: shown in parentheses after the prompt. In API docs: the example value.
Source code in src/airfield/types.py
PrimaryKey
dataclass
¶
Bases: BasePresentation
Marks this field as the primary identity for the record.
Affects presentation across contexts: typically hidden in create forms, read-only in edit forms, displayed as a link in tables, used as the record identifier in detail views and URLs.
Source code in src/airfield/types.py
Priority
dataclass
¶
Bases: BasePresentation
How important this field is relative to siblings.
Higher priority fields are shown first, or shown when space is limited while lower-priority fields are hidden.
Source code in src/airfield/types.py
ReadOnly
dataclass
¶
Bases: BasePresentation
Field should be displayed but not editable.
With no arguments, read-only everywhere.
Source code in src/airfield/types.py
Sortable
dataclass
¶
Bases: BasePresentation
Whether this field should be sortable in list/table contexts.
When default is True, this field is the initial sort key.
Source code in src/airfield/types.py
Widget
dataclass
¶
Bases: BasePresentation
Preferred input/display mechanism for the field.
The kind is a semantic name, not an HTML element.
Consuming libraries map these to their own components.
Standard kinds (consumers should recognize at minimum): text, textarea, date, datetime, time, color, email, url, password, file, hidden, toggle, slider, rating, rich_text, code, search, phone, currency, autocomplete
Libraries are free to define additional kinds. Unknown kinds
should fall back to "text" without raising errors.
Source code in src/airfield/types.py
AirField(default=..., *, primary_key=False, type=None, label=None, widget=None, choices=None, autofocus=False, placeholder=None, help_text=None, default_factory=None, **kwargs)
¶
Unified field descriptor for Pydantic models.
Accepts presentation metadata (primary_key, type, label,
widget, choices, placeholder, help_text,
autofocus) and all standard pydantic.Field parameters.
All AirField-specific parameters become typed metadata objects in
field_info.metadata. Remaining **kwargs pass through to
pydantic.Field(); Pydantic raises on unrecognized parameters.
Returns:
| Type | Description |
|---|---|
Any
|
A Pydantic FieldInfo configured with all specified parameters. |