Reference

Core classes

The two classes that define an application's surface are FastAPI (the application) and APIRouter (a mountable group of routes).

ClassModuleSummaryPublic methods
FastAPIfastapi.applicationsFastAPI app class, the main entrypoint to use FastAPI.22
APIWebSocketRoutefastapi.routing—1
APIRoutefastapi.routing—3
RouteContextfastapi.routing—6
APIRouterfastapi.routingAPIRouter class, used to group path operations, for example to structure23

Every public class in the package

ClassModuleSummaryPublic methods
BackgroundTasksfastapi.backgroundA collection of background tasks that will be called after a response has been2
UploadFilefastapi.datastructuresA file uploaded in a request.4
DefaultPlaceholderfastapi.datastructuresYou shouldn't use this class directly.0
EndpointContextfastapi.exceptions—0
HTTPExceptionfastapi.exceptionsAn HTTP exception you can raise in your own code to show errors to the client.0
WebSocketExceptionfastapi.exceptionsA WebSocket exception you can raise in your own code to show errors to the client.0
FastAPIErrorfastapi.exceptionsA generic, FastAPI-specific error.0
DependencyScopeErrorfastapi.exceptionsA dependency declared that it depends on another dependency with an invalid0
ValidationExceptionfastapi.exceptions—1
RequestValidationErrorfastapi.exceptions—0
WebSocketRequestValidationErrorfastapi.exceptions—0
ResponseValidationErrorfastapi.exceptions—0
PydanticV1NotSupportedErrorfastapi.exceptionsA pydantic.v1 model is used, which is no longer supported.0
FastAPIDeprecationWarningfastapi.exceptionsA custom deprecation warning as DeprecationWarning is ignored0
ParamTypesfastapi.params—0
Paramfastapi.params—0
Pathfastapi.params—0
Queryfastapi.params—0
Headerfastapi.params—0
Cookiefastapi.params—0
Bodyfastapi.params—0
Formfastapi.params—0
Filefastapi.params—0
Dependsfastapi.params—0
Securityfastapi.params—0
UJSONResponsefastapi.responsesJSON response using the ujson library to serialize data to JSON.1
ORJSONResponsefastapi.responsesJSON response using the orjson library to serialize data to JSON.1
EventSourceResponsefastapi.sseStreaming response with text/event-stream media type.0
ServerSentEventfastapi.sseRepresents a single Server-Sent Event.0
BaseModelWithConfigfastapi.openapi.models—0
Contactfastapi.openapi.models—0
Licensefastapi.openapi.models—0
Infofastapi.openapi.models—0
ServerVariablefastapi.openapi.models—0
Serverfastapi.openapi.models—0
Referencefastapi.openapi.models—0
Discriminatorfastapi.openapi.models—0
XMLfastapi.openapi.models—0
ExternalDocumentationfastapi.openapi.models—0
Schemafastapi.openapi.models—0
Examplefastapi.openapi.models—0
ParameterInTypefastapi.openapi.models—0
Encodingfastapi.openapi.models—0
MediaTypefastapi.openapi.models—0
ParameterBasefastapi.openapi.models—0
Parameterfastapi.openapi.models—0
Headerfastapi.openapi.models—0
RequestBodyfastapi.openapi.models—0
Linkfastapi.openapi.models—0
Responsefastapi.openapi.models—0
Operationfastapi.openapi.models—0
PathItemfastapi.openapi.models—0
SecuritySchemeTypefastapi.openapi.models—0
SecurityBasefastapi.openapi.models—0
APIKeyInfastapi.openapi.models—0
APIKeyfastapi.openapi.models—0
HTTPBasefastapi.openapi.models—0
HTTPBearerfastapi.openapi.models—0
OAuthFlowfastapi.openapi.models—0
OAuthFlowImplicitfastapi.openapi.models—0
OAuthFlowPasswordfastapi.openapi.models—0
OAuthFlowClientCredentialsfastapi.openapi.models—0
OAuthFlowAuthorizationCodefastapi.openapi.models—0
OAuthFlowsfastapi.openapi.models—0
OAuth2fastapi.openapi.models—0
OpenIdConnectfastapi.openapi.models—0
Componentsfastapi.openapi.models—0
Tagfastapi.openapi.models—0
OpenAPIfastapi.openapi.models—0
GenerateJsonSchemafastapi._compat.v2—1
ModelFieldfastapi._compat.v2—8
Dependantfastapi.dependencies.models—0
ParamDetailsfastapi.dependencies.utils—0
SolvedDependencyfastapi.dependencies.utils—0
AsyncExitStackMiddlewarefastapi.middleware.asyncexitstack—1
APIKeyBasefastapi.security.api_key—2
APIKeyQueryfastapi.security.api_keyAPI key authentication using a query parameter.1
APIKeyHeaderfastapi.security.api_keyAPI key authentication using a header.1
APIKeyCookiefastapi.security.api_keyAPI key authentication using a cookie.1
SecurityBasefastapi.security.base—0
HTTPBasicCredentialsfastapi.security.httpThe HTTP Basic credentials given as the result of using HTTPBasic in a0
HTTPAuthorizationCredentialsfastapi.security.httpThe HTTP authorization credentials in the result of using HTTPBearer or0
HTTPBasefastapi.security.http—3
HTTPBasicfastapi.security.httpHTTP Basic authentication.2
HTTPBearerfastapi.security.httpHTTP Bearer token authentication.1
HTTPDigestfastapi.security.httpHTTP Digest authentication.1
OAuth2PasswordRequestFormfastapi.security.oauth2This is a dependency class to collect the username and password as form data0
OAuth2PasswordRequestFormStrictfastapi.security.oauth2This is a dependency class to collect the username and password as form data0
OAuth2fastapi.security.oauth2This is the base class for OAuth2 authentication, an instance of it would be used2
OAuth2PasswordBearerfastapi.security.oauth2OAuth2 flow for authentication using a bearer token obtained with a password.1
OAuth2AuthorizationCodeBearerfastapi.security.oauth2OAuth2 flow for authentication using a bearer token obtained with an OAuth2 code1
SecurityScopesfastapi.security.oauth2This is a special class that you can define in a parameter in a dependency to0
OpenIdConnectfastapi.security.open_id_connect_urlOpenID Connect authentication class. An instance of it would be used as a2

Method detail — FastAPI and APIRouter

FastAPI

Module: fastapi.applications — source: fastapi/applications.py

Bases: Starlette

FastAPI app class, the main entrypoint to use FastAPI.

MethodSignatureSummary
build_middleware_stackbuild_middleware_stack() -> ASGIApp—
openapiopenapi() -> dict[str, Any]Generate the OpenAPI schema of the application. This is called by FastAPI
setupsetup() -> None—
__call____call__(scope: Scope, receive: Receive, send: Send) -> None—
add_api_route`add_api_route(path: str, endpoint: Callable[..., Any], *, response_model: Any=Default(None), status_code: intNone=None, tags: list[str
frontend`frontend(path: Annotated[str, Doc('\n The URL path prefix where the frontend build should be served.\n ')], *, directory: Annotated[stros.PathLike[str], Doc('\n The directory containing the static frontend build output.\n ')], fallback: Annotated[Literal['auto', 'index.html', '404.html']
api_route`api_route(path: str, *, response_model: Any=Default(None), status_code: intNone=None, tags: list[str
add_api_websocket_route`add_api_websocket_route(path: str, endpoint: Callable[..., Any], name: strNone=None, *, dependencies: Sequence[Depends]
websocket`websocket(path: Annotated[str, Doc('\n WebSocket path.\n ')], name: Annotated[strNone, Doc('\n A name for the WebSocket. Only used internally.\n ')]=None, *, dependencies: Annotated[Sequence[Depends]
include_routerinclude_router(router: Annotated[routing.APIRouter, Doc('The APIRouter` to include.')], *, prefix: Annotated[str, Doc('An optional path prefix for the router.')]='', tags: Annotated[list[strEnum]
getget(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
putput(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
postpost(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
deletedelete(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
optionsoptions(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
headhead(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
patchpatch(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
tracetrace(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
websocket_route`websocket_route(path: str, name: strNone=None) -> Callable[[DecoratedCallable], DecoratedCallable]`
on_eventon_event(event_type: Annotated[str, Doc('\n The type of event. startuporshutdown.\n ')]) -> Callable[[DecoratedCallable], DecoratedCallable]Add an event handler for the application.
middlewaremiddleware(middleware_type: Annotated[str, Doc('\n The type of middleware. Currently only supports http.\n ')]) -> Callable[[DecoratedCallable], DecoratedCallable]Add a middleware to the application.
exception_handler`exception_handler(exc_class_or_status_code: Annotated[inttype[Exception], Doc('\n The Exception class this would handle, or a status code.\n ')]) -> Callable[[DecoratedCallable], DecoratedCallable]`

APIWebSocketRoute

Module: fastapi.routing — source: fastapi/routing.py

Bases: routing.WebSocketRoute

MethodSignatureSummary
matchesmatches(scope: Scope) -> tuple[Match, Scope]—

APIRoute

Module: fastapi.routing — source: fastapi/routing.py

Bases: routing.Route

MethodSignatureSummary
get_route_handlerget_route_handler() -> Callable[[Request], Coroutine[Any, Any, Response]]—
matchesmatches(scope: Scope) -> tuple[Match, Scope]—
handlehandle(scope: Scope, receive: Receive, send: Send) -> None—

RouteContext

Module: fastapi.routing — source: fastapi/routing.py

MethodSignatureSummary
original_routeoriginal_route() -> BaseRoute—
path`path() -> strNone`
path_format`path_format() -> strNone`
name`name() -> strNone`
methods`methods() -> set[str]None`
endpoint`endpoint() -> Callable[..., Any]None`

APIRouter

Module: fastapi.routing — source: fastapi/routing.py

Bases: routing.Router

APIRouter class, used to group path operations, for example to structure

MethodSignatureSummary
add_route`add_route(path: str, endpoint: Callable[[Request], Awaitable[Response]Response], methods: Collection[str]
add_websocket_route`add_websocket_route(path: str, endpoint: Callable[[WebSocket], Awaitable[None]], name: strNone=None) -> None`
frontend`frontend(path: Annotated[str, Doc('\n The URL path prefix where the frontend build should be served.\n ')], *, directory: Annotated[stros.PathLike[str], Doc('\n The directory containing the static frontend build output.\n ')], fallback: Annotated[Literal['auto', 'index.html', '404.html']
appapp(scope: Scope, receive: Receive, send: Send) -> None—
handlehandle(scope: Scope, receive: Receive, send: Send) -> None—
matchesmatches(scope: Scope) -> tuple[Match, Scope]—
route`route(path: str, methods: Collection[str]None=None, name: str
add_api_route`add_api_route(path: str, endpoint: Callable[..., Any], *, response_model: Any=Default(None), status_code: intNone=None, tags: list[str
api_route`api_route(path: str, *, response_model: Any=Default(None), status_code: intNone=None, tags: list[str
add_api_websocket_route`add_api_websocket_route(path: str, endpoint: Callable[..., Any], name: strNone=None, *, dependencies: Sequence[params.Depends]
websocket`websocket(path: Annotated[str, Doc('\n WebSocket path.\n ')], name: Annotated[strNone, Doc('\n A name for the WebSocket. Only used internally.\n ')]=None, *, dependencies: Annotated[Sequence[params.Depends]
websocket_route`websocket_route(path: str, name: strNone=None) -> Callable[[DecoratedCallable], DecoratedCallable]`
include_routerinclude_router(router: Annotated['APIRouter', Doc('The APIRouter` to include.')], *, prefix: Annotated[str, Doc('An optional path prefix for the router.')]='', tags: Annotated[list[strEnum]
getget(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
putput(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
postpost(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
deletedelete(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
optionsoptions(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
headhead(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
patchpatch(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
tracetrace(path: Annotated[str, Doc('\n The URL path to be used for this *path operation*.\n\n For example, in http://example.com/items`, the path is /items.\n ')], *, response_model: Annotated[Any, Doc("\n The type to use for the response.\n\n It could be any valid Pydantic *field* type. So, it doesn't have to\n be a Pydantic model, it could be other things, like a list, dict,\n etc.\n\n It will be used for:\n\n * Documentation: the generated OpenAPI (and the UI at /docs) will\n show it as the response (JSON Schema).\n * Serialization: you could return an arbitrary object and the\n response_model would be used to serialize that object into the\n corresponding JSON.\n * Filtering: the JSON sent to the client will only contain the data\n (fields) defined in the response_model. If you returned an object\n that contains an attribute password but the response_model does\n not include that field, the JSON sent to the client would not have\n that password.\n * Validation: whatever you return will be serialized with the\n response_model, converting any data as necessary to generate the\n corresponding JSON. But if the data in the object returned is not\n valid, that would mean a violation of the contract with the client,\n so it's an error from the API developer. So, FastAPI will raise an\n error and return a 500 error code (Internal Server Error).\n\n Read more about it in the\n FastAPI docs for Response Model.\n ")]=Default(None), status_code: Annotated[intNone, Doc('\n The default status code to be used for the response.\n\n You could override the status code by returning a response directly.\n\n Read more about it in the\n FastAPI docs for Response Status Code.\n ')]=None, tags: Annotated[list[str
add_event_handleradd_event_handler(event_type: str, func: Callable[[], Any]) -> NoneAdd an event handler function for startup or shutdown.
on_eventon_event(event_type: Annotated[str, Doc('\n The type of event. startuporshutdown.\n ')]) -> Callable[[DecoratedCallable], DecoratedCallable]Add an event handler for the router.