committed by
GitHub
217 changed files with 12744 additions and 2249 deletions
@ -14,14 +14,14 @@ jobs: |
|||
env: |
|||
GITHUB_CONTEXT: ${{ toJson(github) }} |
|||
run: echo "$GITHUB_CONTEXT" |
|||
- uses: actions/checkout@v3 |
|||
- uses: actions/checkout@v4 |
|||
- name: Clean site |
|||
run: | |
|||
rm -rf ./site |
|||
mkdir ./site |
|||
- name: Download Artifact Docs |
|||
id: download |
|||
uses: dawidd6/[email protected]7.0 |
|||
uses: dawidd6/[email protected]8.0 |
|||
with: |
|||
if_no_artifact_found: ignore |
|||
github_token: ${{ secrets.FASTAPI_PREVIEW_DOCS_DOWNLOAD_ARTIFACTS }} |
|||
|
@ -13,11 +13,11 @@ jobs: |
|||
env: |
|||
GITHUB_CONTEXT: ${{ toJson(github) }} |
|||
run: echo "$GITHUB_CONTEXT" |
|||
- uses: actions/checkout@v3 |
|||
- uses: actions/checkout@v4 |
|||
- name: Set up Python |
|||
uses: actions/setup-python@v4 |
|||
with: |
|||
python-version: "3.7" |
|||
python-version: "3.10" |
|||
# Issue ref: https://github.com/actions/setup-python/issues/436 |
|||
# cache: "pip" |
|||
cache-dependency-path: pyproject.toml |
|||
@ -32,7 +32,7 @@ jobs: |
|||
- name: Build distribution |
|||
run: python -m build |
|||
- name: Publish |
|||
uses: pypa/[email protected].6 |
|||
uses: pypa/[email protected].10 |
|||
with: |
|||
password: ${{ secrets.PYPI_API_TOKEN }} |
|||
- name: Dump GitHub context |
|||
|
@ -24,7 +24,7 @@ jobs: |
|||
|
|||
- run: pip install smokeshow |
|||
|
|||
- uses: dawidd6/[email protected]7.0 |
|||
- uses: dawidd6/[email protected]8.0 |
|||
with: |
|||
github_token: ${{ secrets.FASTAPI_SMOKESHOW_DOWNLOAD_ARTIFACTS }} |
|||
workflow: test.yml |
|||
|
@ -0,0 +1,24 @@ |
|||
# This CITATION.cff file was generated with cffinit. |
|||
# Visit https://bit.ly/cffinit to generate yours today! |
|||
|
|||
cff-version: 1.2.0 |
|||
title: FastAPI |
|||
message: >- |
|||
If you use this software, please cite it using the |
|||
metadata from this file. |
|||
type: software |
|||
authors: |
|||
- given-names: Sebastián |
|||
family-names: Ramírez |
|||
email: [email protected] |
|||
identifiers: |
|||
repository-code: 'https://github.com/tiangolo/fastapi' |
|||
url: 'https://fastapi.tiangolo.com' |
|||
abstract: >- |
|||
FastAPI framework, high performance, easy to learn, fast to code, |
|||
ready for production |
|||
keywords: |
|||
- fastapi |
|||
- pydantic |
|||
- starlette |
|||
license: MIT |
@ -0,0 +1,3 @@ |
|||
# About |
|||
|
|||
About FastAPI, its design, inspiration and more. 🤓 |
@ -0,0 +1,3 @@ |
|||
# Help |
|||
|
|||
Help and get help, contribute, get involved. 🤝 |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 45 KiB |
@ -1,3 +0,0 @@ |
|||
((window.gitter = {}).chat = {}).options = { |
|||
room: 'tiangolo/fastapi' |
|||
}; |
@ -0,0 +1,5 @@ |
|||
# Learn |
|||
|
|||
Here are the introductory sections and the tutorials to learn **FastAPI**. |
|||
|
|||
You could consider this a **book**, a **course**, the **official** and recommended way to learn FastAPI. 😎 |
@ -0,0 +1,25 @@ |
|||
# `APIRouter` class |
|||
|
|||
Here's the reference information for the `APIRouter` class, with all its parameters, |
|||
attributes and methods. |
|||
|
|||
You can import the `APIRouter` class directly from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import APIRouter |
|||
``` |
|||
|
|||
::: fastapi.APIRouter |
|||
options: |
|||
members: |
|||
- websocket |
|||
- include_router |
|||
- get |
|||
- put |
|||
- post |
|||
- delete |
|||
- options |
|||
- head |
|||
- patch |
|||
- trace |
|||
- on_event |
@ -0,0 +1,13 @@ |
|||
# Background Tasks - `BackgroundTasks` |
|||
|
|||
You can declare a parameter in a *path operation function* or dependency function |
|||
with the type `BackgroundTasks`, and then you can use it to schedule the execution |
|||
of background tasks after the response is sent. |
|||
|
|||
You can import it directly from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import BackgroundTasks |
|||
``` |
|||
|
|||
::: fastapi.BackgroundTasks |
@ -0,0 +1,32 @@ |
|||
# Dependencies - `Depends()` and `Security()` |
|||
|
|||
## `Depends()` |
|||
|
|||
Dependencies are handled mainly with the special function `Depends()` that takes a |
|||
callable. |
|||
|
|||
Here is the reference for it and its parameters. |
|||
|
|||
You can import it directly from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import Depends |
|||
``` |
|||
|
|||
::: fastapi.Depends |
|||
|
|||
## `Security()` |
|||
|
|||
For many scenarios, you can handle security (authorization, authentication, etc.) with |
|||
dependencies, using `Depends()`. |
|||
|
|||
But when you want to also declare OAuth2 scopes, you can use `Security()` instead of |
|||
`Depends()`. |
|||
|
|||
You can import `Security()` directly from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import Security |
|||
``` |
|||
|
|||
::: fastapi.Security |
@ -0,0 +1,3 @@ |
|||
# Encoders - `jsonable_encoder` |
|||
|
|||
::: fastapi.encoders.jsonable_encoder |
@ -0,0 +1,22 @@ |
|||
# Exceptions - `HTTPException` and `WebSocketException` |
|||
|
|||
These are the exceptions that you can raise to show errors to the client. |
|||
|
|||
When you raise an exception, as would happen with normal Python, the rest of the |
|||
excecution is aborted. This way you can raise these exceptions from anywhere in the |
|||
code to abort a request and show the error to the client. |
|||
|
|||
You can use: |
|||
|
|||
* `HTTPException` |
|||
* `WebSocketException` |
|||
|
|||
These exceptions can be imported directly from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import HTTPException, WebSocketException |
|||
``` |
|||
|
|||
::: fastapi.HTTPException |
|||
|
|||
::: fastapi.WebSocketException |
@ -0,0 +1,32 @@ |
|||
# `FastAPI` class |
|||
|
|||
Here's the reference information for the `FastAPI` class, with all its parameters, |
|||
attributes and methods. |
|||
|
|||
You can import the `FastAPI` class directly from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import FastAPI |
|||
``` |
|||
|
|||
::: fastapi.FastAPI |
|||
options: |
|||
members: |
|||
- openapi_version |
|||
- webhooks |
|||
- state |
|||
- dependency_overrides |
|||
- openapi |
|||
- websocket |
|||
- include_router |
|||
- get |
|||
- put |
|||
- post |
|||
- delete |
|||
- options |
|||
- head |
|||
- patch |
|||
- trace |
|||
- on_event |
|||
- middleware |
|||
- exception_handler |
@ -0,0 +1,13 @@ |
|||
# `HTTPConnection` class |
|||
|
|||
When you want to define dependencies that should be compatible with both HTTP and |
|||
WebSockets, you can define a parameter that takes an `HTTPConnection` instead of a |
|||
`Request` or a `WebSocket`. |
|||
|
|||
You can import it from `fastapi.requests`: |
|||
|
|||
```python |
|||
from fastapi.requests import HTTPConnection |
|||
``` |
|||
|
|||
::: fastapi.requests.HTTPConnection |
@ -0,0 +1,7 @@ |
|||
# Reference - Code API |
|||
|
|||
Here's the reference or code API, the classes, functions, parameters, attributes, and |
|||
all the FastAPI parts you can use in your applications. |
|||
|
|||
If you want to **learn FastAPI** you are much better off reading the |
|||
[FastAPI Tutorial](https://fastapi.tiangolo.com/tutorial/). |
@ -0,0 +1,46 @@ |
|||
# Middleware |
|||
|
|||
There are several middlewares available provided by Starlette directly. |
|||
|
|||
Read more about them in the |
|||
[FastAPI docs for Middleware](https://fastapi.tiangolo.com/advanced/middleware/). |
|||
|
|||
::: fastapi.middleware.cors.CORSMiddleware |
|||
|
|||
It can be imported from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi.middleware.cors import CORSMiddleware |
|||
``` |
|||
|
|||
::: fastapi.middleware.gzip.GZipMiddleware |
|||
|
|||
It can be imported from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi.middleware.gzip import GZipMiddleware |
|||
``` |
|||
|
|||
::: fastapi.middleware.httpsredirect.HTTPSRedirectMiddleware |
|||
|
|||
It can be imported from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi.middleware.httpsredirect import HTTPSRedirectMiddleware |
|||
``` |
|||
|
|||
::: fastapi.middleware.trustedhost.TrustedHostMiddleware |
|||
|
|||
It can be imported from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi.middleware.trustedhost import TrustedHostMiddleware |
|||
``` |
|||
|
|||
::: fastapi.middleware.wsgi.WSGIMiddleware |
|||
|
|||
It can be imported from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi.middleware.wsgi import WSGIMiddleware |
|||
``` |
@ -0,0 +1,11 @@ |
|||
# OpenAPI `docs` |
|||
|
|||
Utilities to handle OpenAPI automatic UI documentation, including Swagger UI (by default at `/docs`) and ReDoc (by default at `/redoc`). |
|||
|
|||
::: fastapi.openapi.docs.get_swagger_ui_html |
|||
|
|||
::: fastapi.openapi.docs.get_redoc_html |
|||
|
|||
::: fastapi.openapi.docs.get_swagger_ui_oauth2_redirect_html |
|||
|
|||
::: fastapi.openapi.docs.swagger_ui_default_parameters |
@ -0,0 +1,5 @@ |
|||
# OpenAPI |
|||
|
|||
There are several utilities to handle OpenAPI. |
|||
|
|||
You normally don't need to use them unless you have a specific advanced use case that requires it. |
@ -0,0 +1,5 @@ |
|||
# OpenAPI `models` |
|||
|
|||
OpenAPI Pydantic models used to generate and validate the generated OpenAPI. |
|||
|
|||
::: fastapi.openapi.models |
@ -0,0 +1,36 @@ |
|||
# Request Parameters |
|||
|
|||
Here's the reference information for the request parameters. |
|||
|
|||
These are the special functions that you can put in *path operation function* |
|||
parameters or dependency functions with `Annotated` to get data from the request. |
|||
|
|||
It includes: |
|||
|
|||
* `Query()` |
|||
* `Path()` |
|||
* `Body()` |
|||
* `Cookie()` |
|||
* `Header()` |
|||
* `Form()` |
|||
* `File()` |
|||
|
|||
You can import them all directly from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import Body, Cookie, File, Form, Header, Path, Query |
|||
``` |
|||
|
|||
::: fastapi.Query |
|||
|
|||
::: fastapi.Path |
|||
|
|||
::: fastapi.Body |
|||
|
|||
::: fastapi.Cookie |
|||
|
|||
::: fastapi.Header |
|||
|
|||
::: fastapi.Form |
|||
|
|||
::: fastapi.File |
@ -0,0 +1,18 @@ |
|||
# `Request` class |
|||
|
|||
You can declare a parameter in a *path operation function* or dependency to be of type |
|||
`Request` and then you can access the raw request object directly, without any |
|||
validation, etc. |
|||
|
|||
You can import it directly from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import Request |
|||
``` |
|||
|
|||
!!! tip |
|||
When you want to define dependencies that should be compatible with both HTTP and |
|||
WebSockets, you can define a parameter that takes an `HTTPConnection` instead of a |
|||
`Request` or a `WebSocket`. |
|||
|
|||
::: fastapi.Request |
@ -0,0 +1,15 @@ |
|||
# `Response` class |
|||
|
|||
You can declare a parameter in a *path operation function* or dependency to be of type |
|||
`Response` and then you can set data for the response like headers or cookies. |
|||
|
|||
You can also use it directly to create an instance of it and return it from your *path |
|||
operations*. |
|||
|
|||
You can import it directly from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import Response |
|||
``` |
|||
|
|||
::: fastapi.Response |
@ -0,0 +1,166 @@ |
|||
# Custom Response Classes - File, HTML, Redirect, Streaming, etc. |
|||
|
|||
There are several custom response classes you can use to create an instance and return |
|||
them directly from your *path operations*. |
|||
|
|||
Read more about it in the |
|||
[FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/). |
|||
|
|||
You can import them directly from `fastapi.responses`: |
|||
|
|||
```python |
|||
from fastapi.responses import ( |
|||
FileResponse, |
|||
HTMLResponse, |
|||
JSONResponse, |
|||
ORJSONResponse, |
|||
PlainTextResponse, |
|||
RedirectResponse, |
|||
Response, |
|||
StreamingResponse, |
|||
UJSONResponse, |
|||
) |
|||
``` |
|||
|
|||
## FastAPI Responses |
|||
|
|||
There are a couple of custom FastAPI response classes, you can use them to optimize JSON performance. |
|||
|
|||
::: fastapi.responses.UJSONResponse |
|||
options: |
|||
members: |
|||
- charset |
|||
- status_code |
|||
- media_type |
|||
- body |
|||
- background |
|||
- raw_headers |
|||
- render |
|||
- init_headers |
|||
- headers |
|||
- set_cookie |
|||
- delete_cookie |
|||
|
|||
::: fastapi.responses.ORJSONResponse |
|||
options: |
|||
members: |
|||
- charset |
|||
- status_code |
|||
- media_type |
|||
- body |
|||
- background |
|||
- raw_headers |
|||
- render |
|||
- init_headers |
|||
- headers |
|||
- set_cookie |
|||
- delete_cookie |
|||
|
|||
## Starlette Responses |
|||
|
|||
::: fastapi.responses.FileResponse |
|||
options: |
|||
members: |
|||
- chunk_size |
|||
- charset |
|||
- status_code |
|||
- media_type |
|||
- body |
|||
- background |
|||
- raw_headers |
|||
- render |
|||
- init_headers |
|||
- headers |
|||
- set_cookie |
|||
- delete_cookie |
|||
|
|||
::: fastapi.responses.HTMLResponse |
|||
options: |
|||
members: |
|||
- charset |
|||
- status_code |
|||
- media_type |
|||
- body |
|||
- background |
|||
- raw_headers |
|||
- render |
|||
- init_headers |
|||
- headers |
|||
- set_cookie |
|||
- delete_cookie |
|||
|
|||
::: fastapi.responses.JSONResponse |
|||
options: |
|||
members: |
|||
- charset |
|||
- status_code |
|||
- media_type |
|||
- body |
|||
- background |
|||
- raw_headers |
|||
- render |
|||
- init_headers |
|||
- headers |
|||
- set_cookie |
|||
- delete_cookie |
|||
|
|||
::: fastapi.responses.PlainTextResponse |
|||
options: |
|||
members: |
|||
- charset |
|||
- status_code |
|||
- media_type |
|||
- body |
|||
- background |
|||
- raw_headers |
|||
- render |
|||
- init_headers |
|||
- headers |
|||
- set_cookie |
|||
- delete_cookie |
|||
|
|||
::: fastapi.responses.RedirectResponse |
|||
options: |
|||
members: |
|||
- charset |
|||
- status_code |
|||
- media_type |
|||
- body |
|||
- background |
|||
- raw_headers |
|||
- render |
|||
- init_headers |
|||
- headers |
|||
- set_cookie |
|||
- delete_cookie |
|||
|
|||
::: fastapi.responses.Response |
|||
options: |
|||
members: |
|||
- charset |
|||
- status_code |
|||
- media_type |
|||
- body |
|||
- background |
|||
- raw_headers |
|||
- render |
|||
- init_headers |
|||
- headers |
|||
- set_cookie |
|||
- delete_cookie |
|||
|
|||
::: fastapi.responses.StreamingResponse |
|||
options: |
|||
members: |
|||
- body_iterator |
|||
- charset |
|||
- status_code |
|||
- media_type |
|||
- body |
|||
- background |
|||
- raw_headers |
|||
- render |
|||
- init_headers |
|||
- headers |
|||
- set_cookie |
|||
- delete_cookie |
@ -0,0 +1,76 @@ |
|||
# Security Tools |
|||
|
|||
When you need to declare dependencies with OAuth2 scopes you use `Security()`. |
|||
|
|||
But you still need to define what is the dependable, the callable that you pass as |
|||
a parameter to `Depends()` or `Security()`. |
|||
|
|||
There are multiple tools that you can use to create those dependables, and they get |
|||
integrated into OpenAPI so they are shown in the automatic docs UI, they can be used |
|||
by automatically generated clients and SDKs, etc. |
|||
|
|||
You can import them from `fastapi.security`: |
|||
|
|||
```python |
|||
from fastapi.security import ( |
|||
APIKeyCookie, |
|||
APIKeyHeader, |
|||
APIKeyQuery, |
|||
HTTPAuthorizationCredentials, |
|||
HTTPBasic, |
|||
HTTPBasicCredentials, |
|||
HTTPBearer, |
|||
HTTPDigest, |
|||
OAuth2, |
|||
OAuth2AuthorizationCodeBearer, |
|||
OAuth2PasswordBearer, |
|||
OAuth2PasswordRequestForm, |
|||
OAuth2PasswordRequestFormStrict, |
|||
OpenIdConnect, |
|||
SecurityScopes, |
|||
) |
|||
``` |
|||
|
|||
## API Key Security Schemes |
|||
|
|||
::: fastapi.security.APIKeyCookie |
|||
|
|||
::: fastapi.security.APIKeyHeader |
|||
|
|||
::: fastapi.security.APIKeyQuery |
|||
|
|||
## HTTP Authentication Schemes |
|||
|
|||
::: fastapi.security.HTTPBasic |
|||
|
|||
::: fastapi.security.HTTPBearer |
|||
|
|||
::: fastapi.security.HTTPDigest |
|||
|
|||
## HTTP Credentials |
|||
|
|||
::: fastapi.security.HTTPAuthorizationCredentials |
|||
|
|||
::: fastapi.security.HTTPBasicCredentials |
|||
|
|||
## OAuth2 Authentication |
|||
|
|||
::: fastapi.security.OAuth2 |
|||
|
|||
::: fastapi.security.OAuth2AuthorizationCodeBearer |
|||
|
|||
::: fastapi.security.OAuth2PasswordBearer |
|||
|
|||
## OAuth2 Password Form |
|||
|
|||
::: fastapi.security.OAuth2PasswordRequestForm |
|||
|
|||
::: fastapi.security.OAuth2PasswordRequestFormStrict |
|||
|
|||
## OAuth2 Security Scopes in Dependencies |
|||
|
|||
::: fastapi.security.SecurityScopes |
|||
|
|||
## OpenID Connect |
|||
|
|||
::: fastapi.security.OpenIdConnect |
@ -0,0 +1,14 @@ |
|||
# Static Files - `StaticFiles` |
|||
|
|||
You can use the `StaticFiles` class to serve static files, like JavaScript, CSS, images, etc. |
|||
|
|||
Read more about it in the |
|||
[FastAPI docs for Static Files](https://fastapi.tiangolo.com/tutorial/static-files/). |
|||
|
|||
You can import it directly from `fastapi.staticfiles`: |
|||
|
|||
```python |
|||
from fastapi.staticfiles import StaticFiles |
|||
``` |
|||
|
|||
::: fastapi.staticfiles.StaticFiles |
@ -0,0 +1,39 @@ |
|||
# Status Codes |
|||
|
|||
You can import the `status` module from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import status |
|||
``` |
|||
|
|||
`status` is provided directly by Starlette. |
|||
|
|||
It containes a group of named constants (variables) with integer status codes. |
|||
|
|||
For example: |
|||
|
|||
* 200: `status.HTTP_200_OK` |
|||
* 403: `status.HTTP_403_FORBIDDEN` |
|||
* etc. |
|||
|
|||
It can be convenient to quickly access HTTP (and WebSocket) status codes in your app, |
|||
using autocompletion for the name without having to remember the integer status codes |
|||
by memory. |
|||
|
|||
Read more about it in the |
|||
[FastAPI docs about Response Status Code](https://fastapi.tiangolo.com/tutorial/response-status-code/). |
|||
|
|||
## Example |
|||
|
|||
```python |
|||
from fastapi import FastAPI, status |
|||
|
|||
app = FastAPI() |
|||
|
|||
|
|||
@app.get("/items/", status_code=status.HTTP_418_IM_A_TEAPOT) |
|||
def read_items(): |
|||
return [{"name": "Plumbus"}, {"name": "Portal Gun"}] |
|||
``` |
|||
|
|||
::: fastapi.status |
@ -0,0 +1,14 @@ |
|||
# Templating - `Jinja2Templates` |
|||
|
|||
You can use the `Jinja2Templates` class to render Jinja templates. |
|||
|
|||
Read more about it in the |
|||
[FastAPI docs for Templates](https://fastapi.tiangolo.com/advanced/templates/). |
|||
|
|||
You can import it directly from `fastapi.templating`: |
|||
|
|||
```python |
|||
from fastapi.templating import Jinja2Templates |
|||
``` |
|||
|
|||
::: fastapi.templating.Jinja2Templates |
@ -0,0 +1,14 @@ |
|||
# Test Client - `TestClient` |
|||
|
|||
You can use the `TestClient` class to test FastAPI applications without creating an actual HTTP and socket connection, just communicating directly with the FastAPI code. |
|||
|
|||
Read more about it in the |
|||
[FastAPI docs for Testing](https://fastapi.tiangolo.com/tutorial/testing/). |
|||
|
|||
You can import it directly from `fastapi.testclient`: |
|||
|
|||
```python |
|||
from fastapi.testclient import TestClient |
|||
``` |
|||
|
|||
::: fastapi.testclient.TestClient |
@ -0,0 +1,23 @@ |
|||
# `UploadFile` class |
|||
|
|||
You can define *path operation function* parameters to be of the type `UploadFile` |
|||
to receive files from the request. |
|||
|
|||
You can import it directly from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import UploadFile |
|||
``` |
|||
|
|||
::: fastapi.UploadFile |
|||
options: |
|||
members: |
|||
- file |
|||
- filename |
|||
- size |
|||
- headers |
|||
- content_type |
|||
- read |
|||
- write |
|||
- seek |
|||
- close |
@ -0,0 +1,70 @@ |
|||
# WebSockets |
|||
|
|||
When defining WebSockets, you normally declare a parameter of type `WebSocket` and |
|||
with it you can read data from the client and send data to it. |
|||
|
|||
It is provided directly by Starlette, but you can import it from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import WebSocket |
|||
``` |
|||
|
|||
!!! tip |
|||
When you want to define dependencies that should be compatible with both HTTP and |
|||
WebSockets, you can define a parameter that takes an `HTTPConnection` instead of a |
|||
`Request` or a `WebSocket`. |
|||
|
|||
::: fastapi.WebSocket |
|||
options: |
|||
members: |
|||
- scope |
|||
- app |
|||
- url |
|||
- base_url |
|||
- headers |
|||
- query_params |
|||
- path_params |
|||
- cookies |
|||
- client |
|||
- state |
|||
- url_for |
|||
- client_state |
|||
- application_state |
|||
- receive |
|||
- send |
|||
- accept |
|||
- receive_text |
|||
- receive_bytes |
|||
- receive_json |
|||
- iter_text |
|||
- iter_bytes |
|||
- iter_json |
|||
- send_text |
|||
- send_bytes |
|||
- send_json |
|||
- close |
|||
|
|||
When a client disconnects, a `WebSocketDisconnect` exception is raised, you can catch |
|||
it. |
|||
|
|||
You can import it directly form `fastapi`: |
|||
|
|||
```python |
|||
from fastapi import WebSocketDisconnect |
|||
``` |
|||
|
|||
::: fastapi.WebSocketDisconnect |
|||
|
|||
## WebSockets - additional classes |
|||
|
|||
Additional classes for handling WebSockets. |
|||
|
|||
Provided directly by Starlette, but you can import it from `fastapi`: |
|||
|
|||
```python |
|||
from fastapi.websockets import WebSocketDisconnect, WebSocketState |
|||
``` |
|||
|
|||
::: fastapi.websockets.WebSocketDisconnect |
|||
|
|||
::: fastapi.websockets.WebSocketState |
@ -0,0 +1,3 @@ |
|||
# Resources |
|||
|
|||
Additional resources, external links, articles and more. ✈️ |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue