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.
extraction
| Name | Type | Default | Description |
|---|---|---|---|
type
|
|
— | |
qualified_name
|
|
— | |
element_type
|
|
— | |
description
|
|
— | |
source_file
|
|
— | |
line_number
|
|
— | |
is_autodoc
|
|
— | |
autodoc_element
|
|
— | |
_autodoc_template
|
|
— | |
_autodoc_url_path
|
|
— | |
_autodoc_page_type
|
|
— | |
title
|
|
— | |
doc_content_hash
|
|
— |
Symbols on this page
Return True if annotation is a user-defined dataclass type.
Excludes chirp's own dataclass types (Request, Response, etc.) which should never be…
Create a dataclass instance from a mapping (query params, form, JSON).
For each field in cls, looks up the field name in data…
Convert value to target_type, returning value unchanged on failure.
Logs a WARNING when int/float coercion fails so the mismatch is visible.
Resolve common type names from string annotations.
is_extractable_dataclass
function
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 | Default | Description |
|---|---|---|---|
annotation
|
Any
|
— |
extract_dataclass
function
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 | Default | 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). |
_convert
function
def _convert(value: Any, target_type: Any) -> Any
Convert value to target_type, returning value unchanged on failure.
Logs a WARNING when int/float coercion fails so the mismatch is visible.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
Any
|
— | |
target_type
|
Any
|
— |
_resolve_type
function
def _resolve_type(name: str) -> type | str
Resolve common type names from string annotations.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name
|
str
|
— |
View source · /home/runner/work/chirp/chirp/site/../src/chirp/extraction.py:1