Header
This class represents a header parameter, inheriting functionality from Param. It is used to define and validate header values, supporting various validation constraints such as length, pattern, and numeric ranges. The class also handles aliases, descriptions, and schema generation for API documentation.
Attributes
| Attribute | Type | Description |
|---|---|---|
| in_ | ParamTypes.header | This attribute stores the parameter type as 'header', indicating that the parameter should be extracted from the request headers. |
Constructor
Signature
def Header(
default: Any = Undefined,
default_factory: Callable[[], Any]| None = _Unset,
annotation: Any | None = null,
alias: str | None = null,
alias_priority: int | None = _Unset,
validation_alias: str | AliasPath | AliasChoices | None = null,
serialization_alias: str | None = null,
convert_underscores: bool = true,
title: str | None = null,
description: str | None = null,
gt: float | None = null,
ge: float | None = null,
lt: float | None = null,
le: float | None = null,
min_length: int | None = null,
max_length: int | None = null,
pattern: str | None = null,
regex: Annotated[str | None, deprecated("Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead.")] = null,
discriminator: str | None = null,
strict: bool | None = _Unset,
multiple_of: float | None = _Unset,
allow_inf_nan: bool | None = _Unset,
max_digits: int | None = _Unset,
decimal_places: int | None = _Unset,
examples: list[Any]| None = null,
example: Annotated[Any | None, deprecated("Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, although still supported. Use examples instead.")] = _Unset,
openapi_examples: dict[str, [Example](../openapi/models/example.md?sid=fastapi_openapi_models_example)]| None = null,
deprecated: deprecated | str | bool | None = null,
include_in_schema: bool = true,
json_schema_extra: dict[str, Any]| None = null,
extra: Any = null
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| default | Any = Undefined | The default value for the parameter. |
| default_factory | `Callable[[], Any] | None` = _Unset |
| annotation | `Any | None` = null |
| alias | `str | None` = null |
| alias_priority | `int | None` = _Unset |
| validation_alias | `str | AliasPath |
| serialization_alias | `str | None` = null |
| convert_underscores | bool = true | Whether to convert underscores in the parameter name to hyphens for HTTP headers. |
| title | `str | None` = null |
| description | `str | None` = null |
| gt | `float | None` = null |
| ge | `float | None` = null |
| lt | `float | None` = null |
| le | `float | None` = null |
| min_length | `int | None` = null |
| max_length | `int | None` = null |
| pattern | `str | None` = null |
| regex | `Annotated[str | None, deprecated("Deprecated in FastAPI 0.100.0 and Pydantic v2, use pattern instead.")]` = null |
| discriminator | `str | None` = null |
| strict | `bool | None` = _Unset |
| multiple_of | `float | None` = _Unset |
| allow_inf_nan | `bool | None` = _Unset |
| max_digits | `int | None` = _Unset |
| decimal_places | `int | None` = _Unset |
| examples | `list[Any] | None` = null |
| example | `Annotated[Any | None, deprecated("Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, although still supported. Use examples instead.")]` = _Unset |
| openapi_examples | `dict[str, Example] | None` = null |
| deprecated | `deprecated | str |
| include_in_schema | bool = true | Whether to include the parameter in the OpenAPI schema. |
| json_schema_extra | `dict[str, Any] | None` = null |
| extra | Any = null | Additional keyword arguments. |
Signature
def Header(
default: Any = Undefined,
default_factory: Callable[[], Any]| None = _Unset,
annotation: Any | None = null,
alias: str | None = null,
alias_priority: int | None = _Unset,
validation_alias: str | AliasPath | AliasChoices | None = null,
serialization_alias: str | None = null,
convert_underscores: bool = true,
title: str | None = null,
description: str | None = null,
gt: float | None = null,
ge: float | None = null,
lt: float | None = null,
le: float | None = null,
min_length: int | None = null,
max_length: int | None = null,
pattern: str | None = null,
regex: Annotated[str | None, deprecated("Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead.")] = null,
discriminator: str | None = null,
strict: bool | None = _Unset,
multiple_of: float | None = _Unset,
allow_inf_nan: bool | None = _Unset,
max_digits: int | None = _Unset,
decimal_places: int | None = _Unset,
examples: list[Any]| None = null,
example: Annotated[Any | None, deprecated("Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, although still supported. Use examples instead.")] = _Unset,
openapi_examples: dict[str, [Example](../openapi/models/example.md?sid=fastapi_openapi_models_example)]| None = null,
deprecated: deprecated | str | bool | None = null,
include_in_schema: bool = true,
json_schema_extra: dict[str, Any]| None = null,
extra: Any = null
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| default | Any = Undefined | The default value for the header if it is not provided. Use Undefined if there is no default value. |
| default_factory | `Callable[[], Any] | None` = _Unset |
| annotation | `Any | None` = null |
| alias | `str | None` = null |
| alias_priority | `int | None` = _Unset |
| validation_alias | `str | AliasPath |
| serialization_alias | `str | None` = null |
| convert_underscores | bool = true | A boolean indicating whether underscores in the header name should be converted to hyphens for HTTP header compatibility. |
| title | `str | None` = null |
| description | `str | None` = null |
| gt | `float | None` = null |
| ge | `float | None` = null |
| lt | `float | None` = null |
| le | `float | None` = null |
| min_length | `int | None` = null |
| max_length | `int | None` = null |
| pattern | `str | None` = null |
| regex | `Annotated[str | None, deprecated("Deprecated in FastAPI 0.100.0 and Pydantic v2, use pattern instead.")]` = null |
| discriminator | `str | None` = null |
| strict | `bool | None` = _Unset |
| multiple_of | `float | None` = _Unset |
| allow_inf_nan | `bool | None` = _Unset |
| max_digits | `int | None` = _Unset |
| decimal_places | `int | None` = _Unset |
| examples | `list[Any] | None` = null |
| example | `Annotated[Any | None, deprecated("Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, although still supported. Use examples instead.")]` = _Unset |
| openapi_examples | `dict[str, Example] | None` = null |
| deprecated | `deprecated | str |
| include_in_schema | bool = true | A boolean indicating whether the header parameter should be included in the generated OpenAPI schema. |
| json_schema_extra | `dict[str, Any] | None` = null |
| extra | Any = null | Additional keyword arguments that can be passed to the underlying Pydantic Field. |