Reference
Core classes
The two classes that define an application's surface are FastAPI (the
application) and APIRouter (a mountable group of routes).
| Class | Module | Summary | Public methods |
|---|---|---|---|
FastAPI | fastapi.applications | FastAPI app class, the main entrypoint to use FastAPI. | 22 |
APIWebSocketRoute | fastapi.routing | — | 1 |
APIRoute | fastapi.routing | — | 3 |
RouteContext | fastapi.routing | — | 6 |
APIRouter | fastapi.routing | APIRouter class, used to group path operations, for example to structure | 23 |
Every public class in the package
| Class | Module | Summary | Public methods |
|---|---|---|---|
BackgroundTasks | fastapi.background | A collection of background tasks that will be called after a response has been | 2 |
UploadFile | fastapi.datastructures | A file uploaded in a request. | 4 |
DefaultPlaceholder | fastapi.datastructures | You shouldn't use this class directly. | 0 |
EndpointContext | fastapi.exceptions | — | 0 |
HTTPException | fastapi.exceptions | An HTTP exception you can raise in your own code to show errors to the client. | 0 |
WebSocketException | fastapi.exceptions | A WebSocket exception you can raise in your own code to show errors to the client. | 0 |
FastAPIError | fastapi.exceptions | A generic, FastAPI-specific error. | 0 |
DependencyScopeError | fastapi.exceptions | A dependency declared that it depends on another dependency with an invalid | 0 |
ValidationException | fastapi.exceptions | — | 1 |
RequestValidationError | fastapi.exceptions | — | 0 |
WebSocketRequestValidationError | fastapi.exceptions | — | 0 |
ResponseValidationError | fastapi.exceptions | — | 0 |
PydanticV1NotSupportedError | fastapi.exceptions | A pydantic.v1 model is used, which is no longer supported. | 0 |
FastAPIDeprecationWarning | fastapi.exceptions | A custom deprecation warning as DeprecationWarning is ignored | 0 |
ParamTypes | fastapi.params | — | 0 |
Param | fastapi.params | — | 0 |
Path | fastapi.params | — | 0 |
Query | fastapi.params | — | 0 |
Header | fastapi.params | — | 0 |
Cookie | fastapi.params | — | 0 |
Body | fastapi.params | — | 0 |
Form | fastapi.params | — | 0 |
File | fastapi.params | — | 0 |
Depends | fastapi.params | — | 0 |
Security | fastapi.params | — | 0 |
UJSONResponse | fastapi.responses | JSON response using the ujson library to serialize data to JSON. | 1 |
ORJSONResponse | fastapi.responses | JSON response using the orjson library to serialize data to JSON. | 1 |
EventSourceResponse | fastapi.sse | Streaming response with text/event-stream media type. | 0 |
ServerSentEvent | fastapi.sse | Represents a single Server-Sent Event. | 0 |
BaseModelWithConfig | fastapi.openapi.models | — | 0 |
Contact | fastapi.openapi.models | — | 0 |
License | fastapi.openapi.models | — | 0 |
Info | fastapi.openapi.models | — | 0 |
ServerVariable | fastapi.openapi.models | — | 0 |
Server | fastapi.openapi.models | — | 0 |
Reference | fastapi.openapi.models | — | 0 |
Discriminator | fastapi.openapi.models | — | 0 |
XML | fastapi.openapi.models | — | 0 |
ExternalDocumentation | fastapi.openapi.models | — | 0 |
Schema | fastapi.openapi.models | — | 0 |
Example | fastapi.openapi.models | — | 0 |
ParameterInType | fastapi.openapi.models | — | 0 |
Encoding | fastapi.openapi.models | — | 0 |
MediaType | fastapi.openapi.models | — | 0 |
ParameterBase | fastapi.openapi.models | — | 0 |
Parameter | fastapi.openapi.models | — | 0 |
Header | fastapi.openapi.models | — | 0 |
RequestBody | fastapi.openapi.models | — | 0 |
Link | fastapi.openapi.models | — | 0 |
Response | fastapi.openapi.models | — | 0 |
Operation | fastapi.openapi.models | — | 0 |
PathItem | fastapi.openapi.models | — | 0 |
SecuritySchemeType | fastapi.openapi.models | — | 0 |
SecurityBase | fastapi.openapi.models | — | 0 |
APIKeyIn | fastapi.openapi.models | — | 0 |
APIKey | fastapi.openapi.models | — | 0 |
HTTPBase | fastapi.openapi.models | — | 0 |
HTTPBearer | fastapi.openapi.models | — | 0 |
OAuthFlow | fastapi.openapi.models | — | 0 |
OAuthFlowImplicit | fastapi.openapi.models | — | 0 |
OAuthFlowPassword | fastapi.openapi.models | — | 0 |
OAuthFlowClientCredentials | fastapi.openapi.models | — | 0 |
OAuthFlowAuthorizationCode | fastapi.openapi.models | — | 0 |
OAuthFlows | fastapi.openapi.models | — | 0 |
OAuth2 | fastapi.openapi.models | — | 0 |
OpenIdConnect | fastapi.openapi.models | — | 0 |
Components | fastapi.openapi.models | — | 0 |
Tag | fastapi.openapi.models | — | 0 |
OpenAPI | fastapi.openapi.models | — | 0 |
GenerateJsonSchema | fastapi._compat.v2 | — | 1 |
ModelField | fastapi._compat.v2 | — | 8 |
Dependant | fastapi.dependencies.models | — | 0 |
ParamDetails | fastapi.dependencies.utils | — | 0 |
SolvedDependency | fastapi.dependencies.utils | — | 0 |
AsyncExitStackMiddleware | fastapi.middleware.asyncexitstack | — | 1 |
APIKeyBase | fastapi.security.api_key | — | 2 |
APIKeyQuery | fastapi.security.api_key | API key authentication using a query parameter. | 1 |
APIKeyHeader | fastapi.security.api_key | API key authentication using a header. | 1 |
APIKeyCookie | fastapi.security.api_key | API key authentication using a cookie. | 1 |
SecurityBase | fastapi.security.base | — | 0 |
HTTPBasicCredentials | fastapi.security.http | The HTTP Basic credentials given as the result of using HTTPBasic in a | 0 |
HTTPAuthorizationCredentials | fastapi.security.http | The HTTP authorization credentials in the result of using HTTPBearer or | 0 |
HTTPBase | fastapi.security.http | — | 3 |
HTTPBasic | fastapi.security.http | HTTP Basic authentication. | 2 |
HTTPBearer | fastapi.security.http | HTTP Bearer token authentication. | 1 |
HTTPDigest | fastapi.security.http | HTTP Digest authentication. | 1 |
OAuth2PasswordRequestForm | fastapi.security.oauth2 | This is a dependency class to collect the username and password as form data | 0 |
OAuth2PasswordRequestFormStrict | fastapi.security.oauth2 | This is a dependency class to collect the username and password as form data | 0 |
OAuth2 | fastapi.security.oauth2 | This is the base class for OAuth2 authentication, an instance of it would be used | 2 |
OAuth2PasswordBearer | fastapi.security.oauth2 | OAuth2 flow for authentication using a bearer token obtained with a password. | 1 |
OAuth2AuthorizationCodeBearer | fastapi.security.oauth2 | OAuth2 flow for authentication using a bearer token obtained with an OAuth2 code | 1 |
SecurityScopes | fastapi.security.oauth2 | This is a special class that you can define in a parameter in a dependency to | 0 |
OpenIdConnect | fastapi.security.open_id_connect_url | OpenID Connect authentication class. An instance of it would be used as a | 2 |
Method detail — FastAPI and APIRouter
FastAPI
Module: fastapi.applications — source: fastapi/applications.py
Bases: Starlette
FastAPI app class, the main entrypoint to use FastAPI.
| Method | Signature | Summary |
|---|---|---|
build_middleware_stack | build_middleware_stack() -> ASGIApp | — |
openapi | openapi() -> dict[str, Any] | Generate the OpenAPI schema of the application. This is called by FastAPI |
setup | setup() -> 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: int | None=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[str | os.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: int | None=None, tags: list[str |
add_api_websocket_route | `add_api_websocket_route(path: str, endpoint: Callable[..., Any], name: str | None=None, *, dependencies: Sequence[Depends] |
websocket | `websocket(path: Annotated[str, Doc('\n WebSocket path.\n ')], name: Annotated[str | None, Doc('\n A name for the WebSocket. Only used internally.\n ')]=None, *, dependencies: Annotated[Sequence[Depends] |
include_router | include_router(router: Annotated[routing.APIRouter, Doc('The APIRouter` to include.')], *, prefix: Annotated[str, Doc('An optional path prefix for the router.')]='', tags: Annotated[list[str | Enum] |
get | get(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[int | None, 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 |
put | put(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[int | None, 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 |
post | post(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[int | None, 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 |
delete | delete(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[int | None, 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 |
options | options(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[int | None, 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 |
head | head(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[int | None, 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 |
patch | patch(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[int | None, 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 |
trace | trace(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[int | None, 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: str | None=None) -> Callable[[DecoratedCallable], DecoratedCallable]` |
on_event | on_event(event_type: Annotated[str, Doc('\n The type of event. startuporshutdown.\n ')]) -> Callable[[DecoratedCallable], DecoratedCallable] | Add an event handler for the application. |
middleware | middleware(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[int | type[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
| Method | Signature | Summary |
|---|---|---|
matches | matches(scope: Scope) -> tuple[Match, Scope] | — |
APIRoute
Module: fastapi.routing — source: fastapi/routing.py
Bases: routing.Route
| Method | Signature | Summary |
|---|---|---|
get_route_handler | get_route_handler() -> Callable[[Request], Coroutine[Any, Any, Response]] | — |
matches | matches(scope: Scope) -> tuple[Match, Scope] | — |
handle | handle(scope: Scope, receive: Receive, send: Send) -> None | — |
RouteContext
Module: fastapi.routing — source: fastapi/routing.py
| Method | Signature | Summary |
|---|---|---|
original_route | original_route() -> BaseRoute | — |
path | `path() -> str | None` |
path_format | `path_format() -> str | None` |
name | `name() -> str | None` |
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
| Method | Signature | Summary |
|---|---|---|
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: str | None=None) -> None` |
frontend | `frontend(path: Annotated[str, Doc('\n The URL path prefix where the frontend build should be served.\n ')], *, directory: Annotated[str | os.PathLike[str], Doc('\n The directory containing the static frontend build output.\n ')], fallback: Annotated[Literal['auto', 'index.html', '404.html'] |
app | app(scope: Scope, receive: Receive, send: Send) -> None | — |
handle | handle(scope: Scope, receive: Receive, send: Send) -> None | — |
matches | matches(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: int | None=None, tags: list[str |
api_route | `api_route(path: str, *, response_model: Any=Default(None), status_code: int | None=None, tags: list[str |
add_api_websocket_route | `add_api_websocket_route(path: str, endpoint: Callable[..., Any], name: str | None=None, *, dependencies: Sequence[params.Depends] |
websocket | `websocket(path: Annotated[str, Doc('\n WebSocket path.\n ')], name: Annotated[str | None, Doc('\n A name for the WebSocket. Only used internally.\n ')]=None, *, dependencies: Annotated[Sequence[params.Depends] |
websocket_route | `websocket_route(path: str, name: str | None=None) -> Callable[[DecoratedCallable], DecoratedCallable]` |
include_router | include_router(router: Annotated['APIRouter', Doc('The APIRouter` to include.')], *, prefix: Annotated[str, Doc('An optional path prefix for the router.')]='', tags: Annotated[list[str | Enum] |
get | get(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[int | None, 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 |
put | put(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[int | None, 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 |
post | post(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[int | None, 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 |
delete | delete(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[int | None, 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 |
options | options(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[int | None, 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 |
head | head(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[int | None, 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 |
patch | patch(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[int | None, 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 |
trace | trace(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[int | None, 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_handler | add_event_handler(event_type: str, func: Callable[[], Any]) -> None | Add an event handler function for startup or shutdown. |
on_event | on_event(event_type: Annotated[str, Doc('\n The type of event. startuporshutdown.\n ')]) -> Callable[[DecoratedCallable], DecoratedCallable] | Add an event handler for the router. |