Skip to content

Parameters & Converters

The declarations that bind a handler's arguments to parts of the request, and the path converters behind them.

Path

Bases: ParamBase

Path parameter declaration.

from_field_info classmethod

from_field_info(field_info: FieldInfo, default: Any = ...) -> Self

Build this marker from a pydantic Field carried in Annotated metadata.

Folding it into a marker is what makes it enforced and published: the slot, the OpenAPI document and the MCP tool schema all read the marker and none of them knows about FieldInfo. default is the parameter's own, adopted only when the Field declares none.

with_default

with_default(default: Any) -> Self

Return a copy of this marker carrying default as its own.

A copy, because one marker can be shared between parameters - SHARED = Query() used twice must not take the first one's default.

resolve_default

resolve_default() -> Any

Return a fresh default - calling default_factory when one is set.

validate

validate(value: Any, name: str) -> Any

Validate value against constraints.

Query

Bases: ParamBase

Query parameter declaration.

from_field_info classmethod

from_field_info(field_info: FieldInfo, default: Any = ...) -> Self

Build this marker from a pydantic Field carried in Annotated metadata.

Folding it into a marker is what makes it enforced and published: the slot, the OpenAPI document and the MCP tool schema all read the marker and none of them knows about FieldInfo. default is the parameter's own, adopted only when the Field declares none.

with_default

with_default(default: Any) -> Self

Return a copy of this marker carrying default as its own.

A copy, because one marker can be shared between parameters - SHARED = Query() used twice must not take the first one's default.

resolve_default

resolve_default() -> Any

Return a fresh default - calling default_factory when one is set.

validate

validate(value: Any, name: str) -> Any

Validate value against constraints.

Header

Bases: ParamBase

HTTP header parameter declaration.

from_field_info classmethod

from_field_info(field_info: FieldInfo, default: Any = ...) -> Self

Build this marker from a pydantic Field carried in Annotated metadata.

Folding it into a marker is what makes it enforced and published: the slot, the OpenAPI document and the MCP tool schema all read the marker and none of them knows about FieldInfo. default is the parameter's own, adopted only when the Field declares none.

with_default

with_default(default: Any) -> Self

Return a copy of this marker carrying default as its own.

A copy, because one marker can be shared between parameters - SHARED = Query() used twice must not take the first one's default.

resolve_default

resolve_default() -> Any

Return a fresh default - calling default_factory when one is set.

validate

validate(value: Any, name: str) -> Any

Validate value against constraints.

Cookie

Bases: ParamBase

Cookie parameter declaration.

from_field_info classmethod

from_field_info(field_info: FieldInfo, default: Any = ...) -> Self

Build this marker from a pydantic Field carried in Annotated metadata.

Folding it into a marker is what makes it enforced and published: the slot, the OpenAPI document and the MCP tool schema all read the marker and none of them knows about FieldInfo. default is the parameter's own, adopted only when the Field declares none.

with_default

with_default(default: Any) -> Self

Return a copy of this marker carrying default as its own.

A copy, because one marker can be shared between parameters - SHARED = Query() used twice must not take the first one's default.

resolve_default

resolve_default() -> Any

Return a fresh default - calling default_factory when one is set.

validate

validate(value: Any, name: str) -> Any

Validate value against constraints.

Body

Bases: ParamBase

Request body parameter declaration.

from_field_info classmethod

from_field_info(field_info: FieldInfo, default: Any = ...) -> Self

Build this marker from a pydantic Field carried in Annotated metadata.

Folding it into a marker is what makes it enforced and published: the slot, the OpenAPI document and the MCP tool schema all read the marker and none of them knows about FieldInfo. default is the parameter's own, adopted only when the Field declares none.

with_default

with_default(default: Any) -> Self

Return a copy of this marker carrying default as its own.

A copy, because one marker can be shared between parameters - SHARED = Query() used twice must not take the first one's default.

resolve_default

resolve_default() -> Any

Return a fresh default - calling default_factory when one is set.

validate

validate(value: Any, name: str) -> Any

Validate value against constraints.

Form

Bases: ParamBase

Form field parameter declaration.

from_field_info classmethod

from_field_info(field_info: FieldInfo, default: Any = ...) -> Self

Build this marker from a pydantic Field carried in Annotated metadata.

Folding it into a marker is what makes it enforced and published: the slot, the OpenAPI document and the MCP tool schema all read the marker and none of them knows about FieldInfo. default is the parameter's own, adopted only when the Field declares none.

with_default

with_default(default: Any) -> Self

Return a copy of this marker carrying default as its own.

A copy, because one marker can be shared between parameters - SHARED = Query() used twice must not take the first one's default.

resolve_default

resolve_default() -> Any

Return a fresh default - calling default_factory when one is set.

validate

validate(value: Any, name: str) -> Any

Validate value against constraints.

File

Bases: ParamBase

File upload parameter declaration.

from_field_info classmethod

from_field_info(field_info: FieldInfo, default: Any = ...) -> Self

Build this marker from a pydantic Field carried in Annotated metadata.

Folding it into a marker is what makes it enforced and published: the slot, the OpenAPI document and the MCP tool schema all read the marker and none of them knows about FieldInfo. default is the parameter's own, adopted only when the Field declares none.

with_default

with_default(default: Any) -> Self

Return a copy of this marker carrying default as its own.

A copy, because one marker can be shared between parameters - SHARED = Query() used twice must not take the first one's default.

resolve_default

resolve_default() -> Any

Return a fresh default - calling default_factory when one is set.

validate

validate(value: Any, name: str) -> Any

Validate value against constraints.

Converter

Base class - subclasses override match and may set greedy.

match

match(value: str) -> tuple[bool, Any]

Validate (and coerce) value. Return (ok, coerced).

register_converter

register_converter(name: str, converter_cls: type[Converter]) -> None

Register a custom path converter.

After register_converter("slug", SlugConverter), routes may use {post:slug} and the radix tree coerces the segment through SlugConverter().match(...). Shadowing a built-in name raises ValueError.

unregister_converter

unregister_converter(name: str) -> None

Remove a converter registered with register_converter.

No-op when name was never registered; a built-in name raises ValueError as in register_converter. Routes already registered keep the instance they were built with, so this affects only later registrations.

RouteInfo

Stored route metadata.

RouteMatch

Result of matching a path against the tree.