Body
Declares a parameter to be extracted from the request's JSON body, allowing for metadata configuration, validation constraints, and OpenAPI documentation customization. It supports embedding parameters as keys within the JSON body and provides extensive options for data validation and schema generation.
def Body(
default: Any = Undefined,
default_factory: Callable[[], Any] | None = _Unset,
embed: bool | None = null,
media_type: str = application/json,
alias: str | None = null,
alias_priority: int | None = _Unset,
validation_alias: str | AliasPath | AliasChoices | None = null,
serialization_alias: str | None = null,
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: str | None = 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: Any | None = _Unset,
openapi_examples: dict[str, 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
) - > Any
Declares a parameter that should be extracted from the request body. Use this to configure validation, documentation, and metadata for JSON body fields in FastAPI path operations.
Parameters
| Name | Type | Description |
|---|---|---|
| default | Any = Undefined | Default value if the parameter field is not set. |
| default_factory | `Callable[[], Any] | None` = _Unset |
| embed | `bool | None` = null |
| media_type | str = application/json | The media type of this parameter field used for OpenAPI documentation generation. |
| alias | `str | None` = null |
| alias_priority | `int | None` = _Unset |
| validation_alias | `str | AliasPath |
| serialization_alias | `str | None` = null |
| 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 | `str | None` = 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 | `Any | None` = _Unset |
| openapi_examples | `dict[str, Example] | None` = null |
| deprecated | `deprecated | str |
| include_in_schema | bool = true | Whether to include this parameter in the generated OpenAPI documentation. |
| json_schema_extra | `dict[str, Any] | None` = null |
| extra | Any = null | Deprecated keyword arguments for extra JSON Schema fields; use 'json_schema_extra' instead. |
Returns
| Type | Description |
|---|---|
Any | A FastAPI parameter metadata object used by the dependency injection system to parse and validate the request body. |