Module

extraction

Typed extraction of query parameters and form/JSON body data.

Automatically populates frozen dataclass instances from request data, converting string values to the annotated field types. Used by the handler resolution system when a parameter's type annotation is a dataclass.

Resolution rules (by HTTP method):

  • GET / HEAD: extract from query string
  • POST / PUT / PATCH / DELETE: extract from form body or JSON body (based on Content-Type header)

Supported field types:str, int, float, bool. Missing keys use the dataclass field default. Type conversion failures also fall back to the default.

Functions

is_extractable_dataclass 1 bool
Return True if *annotation* is a user-defined dataclass type. Excludes chirp's…
def is_extractable_dataclass(annotation: Any) -> bool

Return True if annotation is a user-defined dataclass type.

Excludes chirp's own dataclass types (Request, Response, etc.) which should never be auto-extracted from query/form data.

Parameters
Name Type Description
annotation Any
Returns
bool
extract_dataclass 2 T
Create a dataclass instance from a mapping (query params, form, JSON). For eac…
def extract_dataclass(cls: type[T], data: Mapping[str, Any]) -> T

Create a dataclass instance from a mapping (query params, form, JSON).

For each field in cls, looks up the field name in data. If found, converts the value to the field's annotated type. If missing or conversion fails, uses the field's default value.

Parameters
Name Type Description
cls type[T]

A dataclass type to instantiate.

data Mapping[str, Any]

A mapping of string keys to values (query params, form data, or parsed JSON).

Returns
T
_convert 2 Any
Convert *value* to *target_type*, returning *value* unchanged on failure.
def _convert(value: Any, target_type: Any) -> Any
Parameters
Name Type Description
value Any
target_type Any
Returns
Any
_resolve_type 1 type | str
Resolve common type names from string annotations.
def _resolve_type(name: str) -> type | str
Parameters
Name Type Description
name str
Returns
type | str