Reference
Parameters and dependencies
Parameter marker classes
| Class | Module | Summary |
|---|---|---|
ParamTypes | fastapi.params | — |
Param | fastapi.params | — |
Path | fastapi.params | — |
Query | fastapi.params | — |
Header | fastapi.params | — |
Cookie | fastapi.params | — |
Body | fastapi.params | — |
Form | fastapi.params | — |
File | fastapi.params | — |
Depends | fastapi.params | — |
Security | fastapi.params | — |
Dependant | fastapi.dependencies.models | — |
Parameter helper functions
| Function | Signature | Summary |
|---|---|---|
Path | Path(default: Annotated[Any, Doc("\n Default value if the parameter field is not set.\n\n This doesn't affect Pathparameters as the value is always required.\n The parameter is available only for compatibility.\n ")]=..., *, default_factory: Annotated[Callable[[], Any] | None, Doc("\n A callable to generate the default value.\n\n This doesn't affectPathparameters as the value is always required.\n The parameter is available only for compatibility.\n ")]=_Unset, alias: Annotated[str | None, Doc("\n An alternative name for the parameter field.\n\n This will be used to extract the data and for the generated OpenAPI.\n It is particularly useful when you can't use the name you want because it\n is a Python reserved keyword or similar.\n ")]=_Unset, alias_priority: Annotated[int | None, Doc('\n Priority of the alias. This affects whether an alias generator is used.\n ')]=_Unset, validation_alias: Annotated[str | AliasPath | AliasChoices | None, Doc("\n 'Whitelist' validation step. The parameter field will be the single one\n allowed by the alias or set of aliases defined.\n ")]=_Unset, serialization_alias: Annotated[str | None, Doc("\n 'Blacklist' validation step. The vanilla parameter field will be the\n single one of the alias' or set of aliases' fields and all the other\n fields will be ignored at serialization time.\n ")]=_Unset, title: Annotated[str | None, Doc('\n Human-readable title.\n\n Read more about it in the\n [FastAPI docs for Path Parameters and Numeric Validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#declare-metadata)\n ')]=_Unset, description: Annotated[str | None, Doc('\n Human-readable description.\n ')]=_Unset, gt: Annotated[float | None, Doc('\n Greater than. If set, value must be greater than this. Only applicable to\n numbers.\n\n Read more about it in the\n [FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)\n ')]=None, ge: Annotated[float | None, Doc('\n Greater than or equal. If set, value must be greater than or equal to\n this. Only applicable to numbers.\n\n Read more about it in the\n [FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)\n ')]=None, lt: Annotated[float | None, Doc('\n Less than. If set, value must be less than this. Only applicable to numbers.\n\n Read more about it in the\n [FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)\n ')]=None, le: Annotated[float | None, Doc('\n Less than or equal. If set, value must be less than or equal to this.\n Only applicable to numbers.\n\n Read more about it in the\n [FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)\n ')]=None, min_length: Annotated[int | None, Doc('\n Minimum length for strings.\n ')]=None, max_length: Annotated[int | None, Doc('\n Maximum length for strings.\n ')]=None, pattern: Annotated[str | re.Pattern[str] | None, Doc('\n Regular expression pattern for strings, as a string or compiled pattern.\n ')]=None, regex: Annotated[str | None, Doc('\n RegEx pattern for strings.\n '), deprecated('Deprecated in FastAPI 0.100.0 and Pydantic v2, usepatterninstead.')]=None, discriminator: Annotated[str | Discriminator | None, Doc('\n Field name or PydanticDiscriminatorfor selecting a tagged union member.\n ')]=_Unset, strict: Annotated[bool | None, Doc('\n IfTrue, strict validation is applied to the field.\n ')]=_Unset, validate_default: Annotated[bool | None, Doc("\n Validate the default value. By default, defaults are not validated.\n\n This doesn't affect Pathparameters as the value is always required.\n ")]=_Unset, union_mode: Annotated[Literal['smart', 'left_to_right'] | None, Doc('\n Strategy for validating unions. By default, Pydantic uses smart matching.\n Useleft_to_rightto try each type in order.\n ')]=_Unset, fail_fast: Annotated[bool | None, Doc('\n Stop collection validation at the first invalid item instead of collecting\n all errors. Only applies to lists, tuples, sets, and frozensets.\n ')]=_Unset, multiple_of: Annotated[float | None, Doc('\n Value must be a multiple of this. Only applicable to numbers.\n ')]=_Unset, allow_inf_nan: Annotated[bool | None, Doc('\n Allowinf, -inf, nan. Only applicable to numbers.\n ')]=_Unset, max_digits: Annotated[int | None, Doc('\n Maximum number of digits allowed for decimal values.\n ')]=_Unset, decimal_places: Annotated[int | None, Doc('\n Maximum number of decimal places allowed for decimal values.\n ')]=_Unset, examples: Annotated[list[Any] | None, Doc('\n Example values for this field.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)\n ')]=_Unset, 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: Annotated[dict[str, Example] | None, Doc("\n OpenAPI-specific examples.\n\n It will be added to the generated OpenAPI (e.g. visible at /docs).\n\n Swagger UI (that provides the /docsinterface) has better support for the\n OpenAPI-specific examples than the JSON Schemaexamples, that's the main\n use case for this.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).\n ")]=None, deprecated: Annotated[deprecated | str | bool | None, Doc('\n Mark this parameter field as deprecated.\n\n It will affect the generated OpenAPI (e.g. visible at /docs).\n ')]=_Unset, include_in_schema: Annotated[bool, Doc("\n To include (or not) this parameter field in the generated OpenAPI.\n You probably don't need it, but it's available.\n\n This affects the generated OpenAPI (e.g. visible at /docs).\n ")]=True, json_schema_extra: Annotated[dict[str, Any] | Callable[[dict[str, Any]], None] | None, Doc('\n Additional JSON Schema properties, or a callable that modifies the schema.\n ')]=_Unset) -> Any | Declare a path parameter for a path operation. |
Query | Query(default: Annotated[Any, Doc('\n Default value if the parameter field is not set.\n\n Read more about it in the\n [FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#alternative-old-query-as-the-default-value)\n ')]=Undefined, *, default_factory: Annotated[Callable[[], Any] | None, Doc("\n A callable to generate the default value.\n\n This doesn't affect Pathparameters as the value is always required.\n The parameter is available only for compatibility.\n ")]=_Unset, alias: Annotated[str | None, Doc("\n An alternative name for the parameter field.\n\n This will be used to extract the data and for the generated OpenAPI.\n It is particularly useful when you can't use the name you want because it\n is a Python reserved keyword or similar.\n\n Read more about it in the\n [FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#alias-parameters)\n ")]=_Unset, alias_priority: Annotated[int | None, Doc('\n Priority of the alias. This affects whether an alias generator is used.\n ')]=_Unset, validation_alias: Annotated[str | AliasPath | AliasChoices | None, Doc("\n 'Whitelist' validation step. The parameter field will be the single one\n allowed by the alias or set of aliases defined.\n ")]=_Unset, serialization_alias: Annotated[str | None, Doc("\n 'Blacklist' validation step. The vanilla parameter field will be the\n single one of the alias' or set of aliases' fields and all the other\n fields will be ignored at serialization time.\n ")]=_Unset, title: Annotated[str | None, Doc('\n Human-readable title.\n\n Read more about it in the\n [FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#declare-more-metadata)\n ')]=_Unset, description: Annotated[str | None, Doc('\n Human-readable description.\n\n Read more about it in the\n [FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#declare-more-metadata)\n ')]=_Unset, gt: Annotated[float | None, Doc('\n Greater than. If set, value must be greater than this. Only applicable to\n numbers.\n\n Read more about it in the\n [FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)\n ')]=None, ge: Annotated[float | None, Doc('\n Greater than or equal. If set, value must be greater than or equal to\n this. Only applicable to numbers.\n\n Read more about it in the\n [FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)\n ')]=None, lt: Annotated[float | None, Doc('\n Less than. If set, value must be less than this. Only applicable to numbers.\n\n Read more about it in the\n [FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)\n ')]=None, le: Annotated[float | None, Doc('\n Less than or equal. If set, value must be less than or equal to this.\n Only applicable to numbers.\n\n Read more about it in the\n [FastAPI docs about Path parameters numeric validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#number-validations-greater-than-and-less-than-or-equal)\n ')]=None, min_length: Annotated[int | None, Doc('\n Minimum length for strings.\n\n Read more about it in the\n [FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/)\n ')]=None, max_length: Annotated[int | None, Doc('\n Maximum length for strings.\n\n Read more about it in the\n [FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/)\n ')]=None, pattern: Annotated[str | re.Pattern[str] | None, Doc('\n Regular expression pattern for strings, as a string or compiled pattern.\n\n Read more about it in the\n [FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#add-regular-expressions\n ')]=None, regex: Annotated[str | None, Doc('\n RegEx pattern for strings.\n '), deprecated('Deprecated in FastAPI 0.100.0 and Pydantic v2, usepatterninstead.')]=None, discriminator: Annotated[str | Discriminator | None, Doc('\n Field name or PydanticDiscriminatorfor selecting a tagged union member.\n ')]=_Unset, strict: Annotated[bool | None, Doc('\n IfTrue, strict validation is applied to the field.\n ')]=_Unset, validate_default: Annotated[bool | None, Doc('\n Validate the default value. By default, defaults are not validated.\n ')]=_Unset, union_mode: Annotated[Literal['smart', 'left_to_right'] | None, Doc('\n Strategy for validating unions. By default, Pydantic uses smart matching.\n Use left_to_rightto try each type in order.\n ')]=_Unset, fail_fast: Annotated[bool | None, Doc('\n Stop collection validation at the first invalid item instead of collecting\n all errors. Only applies to lists, tuples, sets, and frozensets.\n ')]=_Unset, multiple_of: Annotated[float | None, Doc('\n Value must be a multiple of this. Only applicable to numbers.\n ')]=_Unset, allow_inf_nan: Annotated[bool | None, Doc('\n Allowinf, -inf, nan. Only applicable to numbers.\n ')]=_Unset, max_digits: Annotated[int | None, Doc('\n Maximum number of digits allowed for decimal values.\n ')]=_Unset, decimal_places: Annotated[int | None, Doc('\n Maximum number of decimal places allowed for decimal values.\n ')]=_Unset, examples: Annotated[list[Any] | None, Doc('\n Example values for this field.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)\n ')]=_Unset, 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: Annotated[dict[str, Example] | None, Doc("\n OpenAPI-specific examples.\n\n It will be added to the generated OpenAPI (e.g. visible at /docs).\n\n Swagger UI (that provides the /docsinterface) has better support for the\n OpenAPI-specific examples than the JSON Schemaexamples, that's the main\n use case for this.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).\n ")]=None, deprecated: Annotated[deprecated | str | bool | None, Doc('\n Mark this parameter field as deprecated.\n\n It will affect the generated OpenAPI (e.g. visible at /docs).\n\n Read more about it in the\n [FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#deprecating-parameters)\n ')]=_Unset, include_in_schema: Annotated[bool, Doc("\n To include (or not) this parameter field in the generated OpenAPI.\n You probably don't need it, but it's available.\n\n This affects the generated OpenAPI (e.g. visible at /docs).\n\n Read more about it in the\n [FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#exclude-parameters-from-openapi\n ")]=True, json_schema_extra: Annotated[dict[str, Any] | Callable[[dict[str, Any]], None] | None, Doc('\n Additional JSON Schema properties, or a callable that modifies the schema.\n ')]=_Unset) -> Any | — |
Header | Header(default: Annotated[Any, Doc('\n Default value if the parameter field is not set.\n ')]=Undefined, *, default_factory: Annotated[Callable[[], Any] | None, Doc("\n A callable to generate the default value.\n\n This doesn't affect Pathparameters as the value is always required.\n The parameter is available only for compatibility.\n ")]=_Unset, alias: Annotated[str | None, Doc("\n An alternative name for the parameter field.\n\n This will be used to extract the data and for the generated OpenAPI.\n It is particularly useful when you can't use the name you want because it\n is a Python reserved keyword or similar.\n ")]=_Unset, alias_priority: Annotated[int | None, Doc('\n Priority of the alias. This affects whether an alias generator is used.\n ')]=_Unset, validation_alias: Annotated[str | AliasPath | AliasChoices | None, Doc("\n 'Whitelist' validation step. The parameter field will be the single one\n allowed by the alias or set of aliases defined.\n ")]=_Unset, serialization_alias: Annotated[str | None, Doc("\n 'Blacklist' validation step. The vanilla parameter field will be the\n single one of the alias' or set of aliases' fields and all the other\n fields will be ignored at serialization time.\n ")]=_Unset, convert_underscores: Annotated[bool, Doc('\n Automatically convert underscores to hyphens in the parameter field name.\n\n Read more about it in the\n [FastAPI docs for Header Parameters](https://fastapi.tiangolo.com/tutorial/header-params/#automatic-conversion)\n ')]=True, title: Annotated[str | None, Doc('\n Human-readable title.\n ')]=_Unset, description: Annotated[str | None, Doc('\n Human-readable description.\n ')]=_Unset, gt: Annotated[float | None, Doc('\n Greater than. If set, value must be greater than this. Only applicable to\n numbers.\n ')]=None, ge: Annotated[float | None, Doc('\n Greater than or equal. If set, value must be greater than or equal to\n this. Only applicable to numbers.\n ')]=None, lt: Annotated[float | None, Doc('\n Less than. If set, value must be less than this. Only applicable to numbers.\n ')]=None, le: Annotated[float | None, Doc('\n Less than or equal. If set, value must be less than or equal to this.\n Only applicable to numbers.\n ')]=None, min_length: Annotated[int | None, Doc('\n Minimum length for strings.\n ')]=None, max_length: Annotated[int | None, Doc('\n Maximum length for strings.\n ')]=None, pattern: Annotated[str | re.Pattern[str] | None, Doc('\n Regular expression pattern for strings, as a string or compiled pattern.\n ')]=None, regex: Annotated[str | None, Doc('\n RegEx pattern for strings.\n '), deprecated('Deprecated in FastAPI 0.100.0 and Pydantic v2, usepatterninstead.')]=None, discriminator: Annotated[str | Discriminator | None, Doc('\n Field name or PydanticDiscriminatorfor selecting a tagged union member.\n ')]=_Unset, strict: Annotated[bool | None, Doc('\n IfTrue, strict validation is applied to the field.\n ')]=_Unset, validate_default: Annotated[bool | None, Doc('\n Validate the default value. By default, defaults are not validated.\n ')]=_Unset, union_mode: Annotated[Literal['smart', 'left_to_right'] | None, Doc('\n Strategy for validating unions. By default, Pydantic uses smart matching.\n Use left_to_rightto try each type in order.\n ')]=_Unset, fail_fast: Annotated[bool | None, Doc('\n Stop collection validation at the first invalid item instead of collecting\n all errors. Only applies to lists, tuples, sets, and frozensets.\n ')]=_Unset, multiple_of: Annotated[float | None, Doc('\n Value must be a multiple of this. Only applicable to numbers.\n ')]=_Unset, allow_inf_nan: Annotated[bool | None, Doc('\n Allowinf, -inf, nan. Only applicable to numbers.\n ')]=_Unset, max_digits: Annotated[int | None, Doc('\n Maximum number of digits allowed for decimal values.\n ')]=_Unset, decimal_places: Annotated[int | None, Doc('\n Maximum number of decimal places allowed for decimal values.\n ')]=_Unset, examples: Annotated[list[Any] | None, Doc('\n Example values for this field.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)\n ')]=_Unset, 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: Annotated[dict[str, Example] | None, Doc("\n OpenAPI-specific examples.\n\n It will be added to the generated OpenAPI (e.g. visible at /docs).\n\n Swagger UI (that provides the /docsinterface) has better support for the\n OpenAPI-specific examples than the JSON Schemaexamples, that's the main\n use case for this.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).\n ")]=None, deprecated: Annotated[deprecated | str | bool | None, Doc('\n Mark this parameter field as deprecated.\n\n It will affect the generated OpenAPI (e.g. visible at /docs).\n ')]=_Unset, include_in_schema: Annotated[bool, Doc("\n To include (or not) this parameter field in the generated OpenAPI.\n You probably don't need it, but it's available.\n\n This affects the generated OpenAPI (e.g. visible at /docs).\n ")]=True, json_schema_extra: Annotated[dict[str, Any] | Callable[[dict[str, Any]], None] | None, Doc('\n Additional JSON Schema properties, or a callable that modifies the schema.\n ')]=_Unset) -> Any | — |
Cookie | Cookie(default: Annotated[Any, Doc('\n Default value if the parameter field is not set.\n ')]=Undefined, *, default_factory: Annotated[Callable[[], Any] | None, Doc("\n A callable to generate the default value.\n\n This doesn't affect Pathparameters as the value is always required.\n The parameter is available only for compatibility.\n ")]=_Unset, alias: Annotated[str | None, Doc("\n An alternative name for the parameter field.\n\n This will be used to extract the data and for the generated OpenAPI.\n It is particularly useful when you can't use the name you want because it\n is a Python reserved keyword or similar.\n ")]=_Unset, alias_priority: Annotated[int | None, Doc('\n Priority of the alias. This affects whether an alias generator is used.\n ')]=_Unset, validation_alias: Annotated[str | AliasPath | AliasChoices | None, Doc("\n 'Whitelist' validation step. The parameter field will be the single one\n allowed by the alias or set of aliases defined.\n ")]=_Unset, serialization_alias: Annotated[str | None, Doc("\n 'Blacklist' validation step. The vanilla parameter field will be the\n single one of the alias' or set of aliases' fields and all the other\n fields will be ignored at serialization time.\n ")]=_Unset, title: Annotated[str | None, Doc('\n Human-readable title.\n ')]=_Unset, description: Annotated[str | None, Doc('\n Human-readable description.\n ')]=_Unset, gt: Annotated[float | None, Doc('\n Greater than. If set, value must be greater than this. Only applicable to\n numbers.\n ')]=None, ge: Annotated[float | None, Doc('\n Greater than or equal. If set, value must be greater than or equal to\n this. Only applicable to numbers.\n ')]=None, lt: Annotated[float | None, Doc('\n Less than. If set, value must be less than this. Only applicable to numbers.\n ')]=None, le: Annotated[float | None, Doc('\n Less than or equal. If set, value must be less than or equal to this.\n Only applicable to numbers.\n ')]=None, min_length: Annotated[int | None, Doc('\n Minimum length for strings.\n ')]=None, max_length: Annotated[int | None, Doc('\n Maximum length for strings.\n ')]=None, pattern: Annotated[str | re.Pattern[str] | None, Doc('\n Regular expression pattern for strings, as a string or compiled pattern.\n ')]=None, regex: Annotated[str | None, Doc('\n RegEx pattern for strings.\n '), deprecated('Deprecated in FastAPI 0.100.0 and Pydantic v2, usepatterninstead.')]=None, discriminator: Annotated[str | Discriminator | None, Doc('\n Field name or PydanticDiscriminatorfor selecting a tagged union member.\n ')]=_Unset, strict: Annotated[bool | None, Doc('\n IfTrue, strict validation is applied to the field.\n ')]=_Unset, validate_default: Annotated[bool | None, Doc('\n Validate the default value. By default, defaults are not validated.\n ')]=_Unset, union_mode: Annotated[Literal['smart', 'left_to_right'] | None, Doc('\n Strategy for validating unions. By default, Pydantic uses smart matching.\n Use left_to_rightto try each type in order.\n ')]=_Unset, fail_fast: Annotated[bool | None, Doc('\n Stop collection validation at the first invalid item instead of collecting\n all errors. Only applies to lists, tuples, sets, and frozensets.\n ')]=_Unset, multiple_of: Annotated[float | None, Doc('\n Value must be a multiple of this. Only applicable to numbers.\n ')]=_Unset, allow_inf_nan: Annotated[bool | None, Doc('\n Allowinf, -inf, nan. Only applicable to numbers.\n ')]=_Unset, max_digits: Annotated[int | None, Doc('\n Maximum number of digits allowed for decimal values.\n ')]=_Unset, decimal_places: Annotated[int | None, Doc('\n Maximum number of decimal places allowed for decimal values.\n ')]=_Unset, examples: Annotated[list[Any] | None, Doc('\n Example values for this field.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)\n ')]=_Unset, 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: Annotated[dict[str, Example] | None, Doc("\n OpenAPI-specific examples.\n\n It will be added to the generated OpenAPI (e.g. visible at /docs).\n\n Swagger UI (that provides the /docsinterface) has better support for the\n OpenAPI-specific examples than the JSON Schemaexamples, that's the main\n use case for this.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).\n ")]=None, deprecated: Annotated[deprecated | str | bool | None, Doc('\n Mark this parameter field as deprecated.\n\n It will affect the generated OpenAPI (e.g. visible at /docs).\n ')]=_Unset, include_in_schema: Annotated[bool, Doc("\n To include (or not) this parameter field in the generated OpenAPI.\n You probably don't need it, but it's available.\n\n This affects the generated OpenAPI (e.g. visible at /docs).\n ")]=True, json_schema_extra: Annotated[dict[str, Any] | Callable[[dict[str, Any]], None] | None, Doc('\n Additional JSON Schema properties, or a callable that modifies the schema.\n ')]=_Unset) -> Any | — |
Body | Body(default: Annotated[Any, Doc('\n Default value if the parameter field is not set.\n ')]=Undefined, *, default_factory: Annotated[Callable[[], Any] | None, Doc("\n A callable to generate the default value.\n\n This doesn't affect Pathparameters as the value is always required.\n The parameter is available only for compatibility.\n ")]=_Unset, embed: Annotated[bool | None, Doc('\n WhenembedisTrue, the parameter will be expected in a JSON body as a\n key instead of being the JSON body itself.\n\n This happens automatically when more than one Bodyparameter is declared.\n\n Read more about it in the\n [FastAPI docs for Body - Multiple Parameters](https://fastapi.tiangolo.com/tutorial/body-multiple-params/#embed-a-single-body-parameter).\n ')]=None, media_type: Annotated[str, Doc("\n The media type of this parameter field. Changing it would affect the\n generated OpenAPI, but currently it doesn't affect the parsing of the data.\n ")]='application/json', alias: Annotated[str | None, Doc("\n An alternative name for the parameter field.\n\n This will be used to extract the data and for the generated OpenAPI.\n It is particularly useful when you can't use the name you want because it\n is a Python reserved keyword or similar.\n ")]=_Unset, alias_priority: Annotated[int | None, Doc('\n Priority of the alias. This affects whether an alias generator is used.\n ')]=_Unset, validation_alias: Annotated[str | AliasPath | AliasChoices | None, Doc("\n 'Whitelist' validation step. The parameter field will be the single one\n allowed by the alias or set of aliases defined.\n ")]=_Unset, serialization_alias: Annotated[str | None, Doc("\n 'Blacklist' validation step. The vanilla parameter field will be the\n single one of the alias' or set of aliases' fields and all the other\n fields will be ignored at serialization time.\n ")]=_Unset, title: Annotated[str | None, Doc('\n Human-readable title.\n ')]=_Unset, description: Annotated[str | None, Doc('\n Human-readable description.\n ')]=_Unset, gt: Annotated[float | None, Doc('\n Greater than. If set, value must be greater than this. Only applicable to\n numbers.\n ')]=None, ge: Annotated[float | None, Doc('\n Greater than or equal. If set, value must be greater than or equal to\n this. Only applicable to numbers.\n ')]=None, lt: Annotated[float | None, Doc('\n Less than. If set, value must be less than this. Only applicable to numbers.\n ')]=None, le: Annotated[float | None, Doc('\n Less than or equal. If set, value must be less than or equal to this.\n Only applicable to numbers.\n ')]=None, min_length: Annotated[int | None, Doc('\n Minimum length for strings.\n ')]=None, max_length: Annotated[int | None, Doc('\n Maximum length for strings.\n ')]=None, pattern: Annotated[str | re.Pattern[str] | None, Doc('\n Regular expression pattern for strings, as a string or compiled pattern.\n ')]=None, regex: Annotated[str | None, Doc('\n RegEx pattern for strings.\n '), deprecated('Deprecated in FastAPI 0.100.0 and Pydantic v2, usepatterninstead.')]=None, discriminator: Annotated[str | Discriminator | None, Doc('\n Field name or PydanticDiscriminatorfor selecting a tagged union member.\n ')]=_Unset, strict: Annotated[bool | None, Doc('\n IfTrue, strict validation is applied to the field.\n ')]=_Unset, validate_default: Annotated[bool | None, Doc('\n Validate the default value. By default, defaults are not validated.\n ')]=_Unset, union_mode: Annotated[Literal['smart', 'left_to_right'] | None, Doc('\n Strategy for validating unions. By default, Pydantic uses smart matching.\n Use left_to_rightto try each type in order.\n ')]=_Unset, fail_fast: Annotated[bool | None, Doc('\n Stop collection validation at the first invalid item instead of collecting\n all errors. Only applies to lists, tuples, sets, and frozensets.\n ')]=_Unset, multiple_of: Annotated[float | None, Doc('\n Value must be a multiple of this. Only applicable to numbers.\n ')]=_Unset, allow_inf_nan: Annotated[bool | None, Doc('\n Allowinf, -inf, nan. Only applicable to numbers.\n ')]=_Unset, max_digits: Annotated[int | None, Doc('\n Maximum number of digits allowed for decimal values.\n ')]=_Unset, decimal_places: Annotated[int | None, Doc('\n Maximum number of decimal places allowed for decimal values.\n ')]=_Unset, examples: Annotated[list[Any] | None, Doc('\n Example values for this field.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)\n ')]=_Unset, 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: Annotated[dict[str, Example] | None, Doc("\n OpenAPI-specific examples.\n\n It will be added to the generated OpenAPI (e.g. visible at /docs).\n\n Swagger UI (that provides the /docsinterface) has better support for the\n OpenAPI-specific examples than the JSON Schemaexamples, that's the main\n use case for this.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).\n ")]=None, deprecated: Annotated[deprecated | str | bool | None, Doc('\n Mark this parameter field as deprecated.\n\n It will affect the generated OpenAPI (e.g. visible at /docs).\n ')]=_Unset, include_in_schema: Annotated[bool, Doc("\n To include (or not) this parameter field in the generated OpenAPI.\n You probably don't need it, but it's available.\n\n This affects the generated OpenAPI (e.g. visible at /docs).\n ")]=True, json_schema_extra: Annotated[dict[str, Any] | Callable[[dict[str, Any]], None] | None, Doc('\n Additional JSON Schema properties, or a callable that modifies the schema.\n ')]=_Unset) -> Any | — |
Form | Form(default: Annotated[Any, Doc('\n Default value if the parameter field is not set.\n ')]=Undefined, *, default_factory: Annotated[Callable[[], Any] | None, Doc("\n A callable to generate the default value.\n\n This doesn't affect Pathparameters as the value is always required.\n The parameter is available only for compatibility.\n ")]=_Unset, media_type: Annotated[str, Doc("\n The media type of this parameter field. Changing it would affect the\n generated OpenAPI, but currently it doesn't affect the parsing of the data.\n ")]='application/x-www-form-urlencoded', alias: Annotated[str | None, Doc("\n An alternative name for the parameter field.\n\n This will be used to extract the data and for the generated OpenAPI.\n It is particularly useful when you can't use the name you want because it\n is a Python reserved keyword or similar.\n ")]=_Unset, alias_priority: Annotated[int | None, Doc('\n Priority of the alias. This affects whether an alias generator is used.\n ')]=_Unset, validation_alias: Annotated[str | AliasPath | AliasChoices | None, Doc("\n 'Whitelist' validation step. The parameter field will be the single one\n allowed by the alias or set of aliases defined.\n ")]=_Unset, serialization_alias: Annotated[str | None, Doc("\n 'Blacklist' validation step. The vanilla parameter field will be the\n single one of the alias' or set of aliases' fields and all the other\n fields will be ignored at serialization time.\n ")]=_Unset, title: Annotated[str | None, Doc('\n Human-readable title.\n ')]=_Unset, description: Annotated[str | None, Doc('\n Human-readable description.\n ')]=_Unset, gt: Annotated[float | None, Doc('\n Greater than. If set, value must be greater than this. Only applicable to\n numbers.\n ')]=None, ge: Annotated[float | None, Doc('\n Greater than or equal. If set, value must be greater than or equal to\n this. Only applicable to numbers.\n ')]=None, lt: Annotated[float | None, Doc('\n Less than. If set, value must be less than this. Only applicable to numbers.\n ')]=None, le: Annotated[float | None, Doc('\n Less than or equal. If set, value must be less than or equal to this.\n Only applicable to numbers.\n ')]=None, min_length: Annotated[int | None, Doc('\n Minimum length for strings.\n ')]=None, max_length: Annotated[int | None, Doc('\n Maximum length for strings.\n ')]=None, pattern: Annotated[str | re.Pattern[str] | None, Doc('\n Regular expression pattern for strings, as a string or compiled pattern.\n ')]=None, regex: Annotated[str | None, Doc('\n RegEx pattern for strings.\n '), deprecated('Deprecated in FastAPI 0.100.0 and Pydantic v2, usepatterninstead.')]=None, discriminator: Annotated[str | Discriminator | None, Doc('\n Field name or PydanticDiscriminatorfor selecting a tagged union member.\n ')]=_Unset, strict: Annotated[bool | None, Doc('\n IfTrue, strict validation is applied to the field.\n ')]=_Unset, validate_default: Annotated[bool | None, Doc('\n Validate the default value. By default, defaults are not validated.\n ')]=_Unset, union_mode: Annotated[Literal['smart', 'left_to_right'] | None, Doc('\n Strategy for validating unions. By default, Pydantic uses smart matching.\n Use left_to_rightto try each type in order.\n ')]=_Unset, fail_fast: Annotated[bool | None, Doc('\n Stop collection validation at the first invalid item instead of collecting\n all errors. Only applies to lists, tuples, sets, and frozensets.\n ')]=_Unset, multiple_of: Annotated[float | None, Doc('\n Value must be a multiple of this. Only applicable to numbers.\n ')]=_Unset, allow_inf_nan: Annotated[bool | None, Doc('\n Allowinf, -inf, nan. Only applicable to numbers.\n ')]=_Unset, max_digits: Annotated[int | None, Doc('\n Maximum number of digits allowed for decimal values.\n ')]=_Unset, decimal_places: Annotated[int | None, Doc('\n Maximum number of decimal places allowed for decimal values.\n ')]=_Unset, examples: Annotated[list[Any] | None, Doc('\n Example values for this field.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)\n ')]=_Unset, 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: Annotated[dict[str, Example] | None, Doc("\n OpenAPI-specific examples.\n\n It will be added to the generated OpenAPI (e.g. visible at /docs).\n\n Swagger UI (that provides the /docsinterface) has better support for the\n OpenAPI-specific examples than the JSON Schemaexamples, that's the main\n use case for this.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).\n ")]=None, deprecated: Annotated[deprecated | str | bool | None, Doc('\n Mark this parameter field as deprecated.\n\n It will affect the generated OpenAPI (e.g. visible at /docs).\n ')]=_Unset, include_in_schema: Annotated[bool, Doc("\n To include (or not) this parameter field in the generated OpenAPI.\n You probably don't need it, but it's available.\n\n This affects the generated OpenAPI (e.g. visible at /docs).\n ")]=True, json_schema_extra: Annotated[dict[str, Any] | Callable[[dict[str, Any]], None] | None, Doc('\n Additional JSON Schema properties, or a callable that modifies the schema.\n ')]=_Unset) -> Any | — |
File | File(default: Annotated[Any, Doc('\n Default value if the parameter field is not set.\n ')]=Undefined, *, default_factory: Annotated[Callable[[], Any] | None, Doc("\n A callable to generate the default value.\n\n This doesn't affect Pathparameters as the value is always required.\n The parameter is available only for compatibility.\n ")]=_Unset, media_type: Annotated[str, Doc("\n The media type of this parameter field. Changing it would affect the\n generated OpenAPI, but currently it doesn't affect the parsing of the data.\n ")]='multipart/form-data', alias: Annotated[str | None, Doc("\n An alternative name for the parameter field.\n\n This will be used to extract the data and for the generated OpenAPI.\n It is particularly useful when you can't use the name you want because it\n is a Python reserved keyword or similar.\n ")]=_Unset, alias_priority: Annotated[int | None, Doc('\n Priority of the alias. This affects whether an alias generator is used.\n ')]=_Unset, validation_alias: Annotated[str | AliasPath | AliasChoices | None, Doc("\n 'Whitelist' validation step. The parameter field will be the single one\n allowed by the alias or set of aliases defined.\n ")]=_Unset, serialization_alias: Annotated[str | None, Doc("\n 'Blacklist' validation step. The vanilla parameter field will be the\n single one of the alias' or set of aliases' fields and all the other\n fields will be ignored at serialization time.\n ")]=_Unset, title: Annotated[str | None, Doc('\n Human-readable title.\n ')]=_Unset, description: Annotated[str | None, Doc('\n Human-readable description.\n ')]=_Unset, gt: Annotated[float | None, Doc('\n Greater than. If set, value must be greater than this. Only applicable to\n numbers.\n ')]=None, ge: Annotated[float | None, Doc('\n Greater than or equal. If set, value must be greater than or equal to\n this. Only applicable to numbers.\n ')]=None, lt: Annotated[float | None, Doc('\n Less than. If set, value must be less than this. Only applicable to numbers.\n ')]=None, le: Annotated[float | None, Doc('\n Less than or equal. If set, value must be less than or equal to this.\n Only applicable to numbers.\n ')]=None, min_length: Annotated[int | None, Doc('\n Minimum length for strings.\n ')]=None, max_length: Annotated[int | None, Doc('\n Maximum length for strings.\n ')]=None, pattern: Annotated[str | re.Pattern[str] | None, Doc('\n Regular expression pattern for strings, as a string or compiled pattern.\n ')]=None, regex: Annotated[str | None, Doc('\n RegEx pattern for strings.\n '), deprecated('Deprecated in FastAPI 0.100.0 and Pydantic v2, usepatterninstead.')]=None, discriminator: Annotated[str | Discriminator | None, Doc('\n Field name or PydanticDiscriminatorfor selecting a tagged union member.\n ')]=_Unset, strict: Annotated[bool | None, Doc('\n IfTrue, strict validation is applied to the field.\n ')]=_Unset, validate_default: Annotated[bool | None, Doc('\n Validate the default value. By default, defaults are not validated.\n ')]=_Unset, union_mode: Annotated[Literal['smart', 'left_to_right'] | None, Doc('\n Strategy for validating unions. By default, Pydantic uses smart matching.\n Use left_to_rightto try each type in order.\n ')]=_Unset, fail_fast: Annotated[bool | None, Doc('\n Stop collection validation at the first invalid item instead of collecting\n all errors. Only applies to lists, tuples, sets, and frozensets.\n ')]=_Unset, multiple_of: Annotated[float | None, Doc('\n Value must be a multiple of this. Only applicable to numbers.\n ')]=_Unset, allow_inf_nan: Annotated[bool | None, Doc('\n Allowinf, -inf, nan. Only applicable to numbers.\n ')]=_Unset, max_digits: Annotated[int | None, Doc('\n Maximum number of digits allowed for decimal values.\n ')]=_Unset, decimal_places: Annotated[int | None, Doc('\n Maximum number of decimal places allowed for decimal values.\n ')]=_Unset, examples: Annotated[list[Any] | None, Doc('\n Example values for this field.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/)\n ')]=_Unset, 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: Annotated[dict[str, Example] | None, Doc("\n OpenAPI-specific examples.\n\n It will be added to the generated OpenAPI (e.g. visible at /docs).\n\n Swagger UI (that provides the /docsinterface) has better support for the\n OpenAPI-specific examples than the JSON Schemaexamples, that's the main\n use case for this.\n\n Read more about it in the\n [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).\n ")]=None, deprecated: Annotated[deprecated | str | bool | None, Doc('\n Mark this parameter field as deprecated.\n\n It will affect the generated OpenAPI (e.g. visible at /docs).\n ')]=_Unset, include_in_schema: Annotated[bool, Doc("\n To include (or not) this parameter field in the generated OpenAPI.\n You probably don't need it, but it's available.\n\n This affects the generated OpenAPI (e.g. visible at /docs).\n ")]=True, json_schema_extra: Annotated[dict[str, Any] | Callable[[dict[str, Any]], None] | None, Doc('\n Additional JSON Schema properties, or a callable that modifies the schema.\n ')]=_Unset) -> Any | — |
Depends | Depends(dependency: Annotated[Callable[..., Any] | None, Doc('\n A "dependable" callable (like a function).\n\n Don\'t call it directly, FastAPI will call it for you, just pass the object\n directly.\n\n Read more about it in the\n [FastAPI docs for Dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/)\n ')]=None, *, use_cache: Annotated[bool, Doc('\n By default, after a dependency is called the first time in a request, if\n the dependency is declared again for the rest of the request (for example\n if the dependency is needed by several dependencies), the value will be\n re-used for the rest of the request.\n\n Set use_cachetoFalseto disable this behavior and ensure the\n dependency is called again (if declared more than once) in the same request.\n\n Read more about it in the\n [FastAPI docs about sub-dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/sub-dependencies/#using-the-same-dependency-multiple-times)\n ')]=True, scope: Annotated[Literal['function', 'request'] | None, Doc('\n Mainly for dependencies withyield, define when the dependency function\n should start (the code before yield) and when it should end (the code\n after yield).\n\n * "function": start the dependency before the *path operation function*\n that handles the request, end the dependency after the *path operation\n function* ends, but **before** the response is sent back to the client.\n So, the dependency function will be executed **around** the *path operation\n **function***.\n * "request": start the dependency before the *path operation function*\n that handles the request (similar to when using "function"), but end\n **after** the response is sent back to the client. So, the dependency\n function will be executed **around** the **request** and response cycle.\n\n Read more about it in the\n [FastAPI docs for FastAPI Dependencies with yield](https://fastapi.tiangolo.com/tutorial/dependencies/dependencies-with-yield/#early-exit-and-scope)\n ')]=None) -> Any | Declare a FastAPI dependency. |
Security | Security(dependency: Annotated[Callable[..., Any] | None, Doc('\n A "dependable" callable (like a function).\n\n Don\'t call it directly, FastAPI will call it for you, just pass the object\n directly.\n\n Read more about it in the\n [FastAPI docs for Dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/)\n ')]=None, *, scopes: Annotated[Sequence[str] | None, Doc('\n OAuth2 scopes required for the *path operation* that uses this Security\n dependency.\n\n The term "scope" comes from the OAuth2 specification, it seems to be\n intentionally vague and interpretable. It normally refers to permissions,\n in cases to roles.\n\n These scopes are integrated with OpenAPI (and the API docs at /docs).\n So they are visible in the OpenAPI specification.\n\n Read more about it in the\n [FastAPI docs about OAuth2 scopes](https://fastapi.tiangolo.com/advanced/security/oauth2-scopes/)\n ')]=None, use_cache: Annotated[bool, Doc('\n By default, after a dependency is called the first time in a request, if\n the dependency is declared again for the rest of the request (for example\n if the dependency is needed by several dependencies), the value will be\n re-used for the rest of the request.\n\n Set use_cachetoFalse to disable this behavior and ensure the\n dependency is called again (if declared more than once) in the same request.\n\n Read more about it in the\n [FastAPI docs about sub-dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/sub-dependencies/#using-the-same-dependency-multiple-times)\n ')]=True) -> Any | Declare a FastAPI Security dependency. |
Using them
from typing import Annotated
from fastapi import Depends, FastAPI, Query
app = FastAPI()
def api_key_header(x_key: Annotated[str, Query()]):
return x_key
@app.get("/items/")
async def read_items(
q: Annotated[str | None, Query(max_length=50)] = None,
x_key: Annotated[str, Depends(api_key_header)] = "",
):
return {"q": q, "x_key": x_key}Every helper above is defined in fastapi.param_functions and is re-exported
from the package root, so from fastapi import Depends, Query is the public path.