| 1 |
<p align="center"> |
| 2 |
<a href="https://fastapi.tiangolo.com"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" alt="FastAPI"></a> |
| 3 |
</p> |
| 4 |
<p align="center"> |
| 5 |
<em>FastAPI framework, high performance, easy to learn, fast to code, ready for production</em> |
| 6 |
</p> |
| 7 |
<p align="center"> |
| 8 |
<a href="https://github.com/fastapi/fastapi/actions?query=workflow%3ATest+event%3Apush+branch%3Amaster"> |
| 9 |
<img src="https://github.com/fastapi/fastapi/actions/workflows/test.yml/badge.svg?event=push&branch=master" alt="Test"> |
| 10 |
</a> |
| 11 |
<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/fastapi"> |
| 12 |
<img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/fastapi.svg" alt="Coverage"> |
| 13 |
</a> |
| 14 |
<a href="https://pypi.org/project/fastapi"> |
| 15 |
<img src="https://img.shields.io/pypi/v/fastapi?color=%2334D058&label=pypi%20package" alt="Package version"> |
| 16 |
</a> |
| 17 |
<a href="https://pypi.org/project/fastapi"> |
| 18 |
<img src="https://img.shields.io/pypi/pyversions/fastapi.svg?color=%2334D058" alt="Supported Python versions"> |
| 19 |
</a> |
| 20 |
</p> |
| 21 |
|
| 22 |
--- |
| 23 |
|
| 24 |
**Documentation**: [https://fastapi.tiangolo.com](https://fastapi.tiangolo.com) |
| 25 |
|
| 26 |
**Source Code**: [https://github.com/fastapi/fastapi](https://github.com/fastapi/fastapi) |
| 27 |
|
| 28 |
--- |
| 29 |
|
| 30 |
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python based on standard Python type hints. |
| 31 |
|
| 32 |
The key features are: |
| 33 |
|
| 34 |
* **Fast**: Very high performance, on par with **NodeJS** and **Go** (thanks to Starlette and Pydantic). [One of the fastest Python frameworks available](#performance). |
| 35 |
* **Fast to code**: Increase the speed to develop features by about 200% to 300%. * |
| 36 |
* **Fewer bugs**: Reduce about 40% of human (developer) induced errors. * |
| 37 |
* **Intuitive**: Great editor support. <dfn title="also known as auto-complete, autocompletion, IntelliSense">Completion</dfn> everywhere. Less time debugging. |
| 38 |
* **Easy**: Designed to be easy to use and learn. Less time reading docs. |
| 39 |
* **Short**: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs. |
| 40 |
* **Robust**: Get production-ready code. With automatic interactive documentation. |
| 41 |
* **Standards-based**: Based on (and fully compatible with) the open standards for APIs: [OpenAPI](https://github.com/OAI/OpenAPI-Specification) (previously known as Swagger) and [JSON Schema](https://json-schema.org/). |
| 42 |
|
| 43 |
<small>* estimation based on tests conducted by an internal development team, building production applications.</small> |
| 44 |
|
| 45 |
## Sponsors |
| 46 |
|
| 47 |
<!-- sponsors --> |
| 48 |
### Keystone Sponsor |
| 49 |
|
| 50 |
<a href="https://fastapicloud.com" target="_blank" title="FastAPI Cloud. By the same team behind FastAPI. You code. We Cloud."><img src="https://fastapi.tiangolo.com/img/sponsors/fastapicloud.png"></a> |
| 51 |
|
| 52 |
### Gold Sponsors |
| 53 |
|
| 54 |
<a href="https://blockbee.io?ref=fastapi" target="_blank" title="BlockBee Cryptocurrency Payment Gateway"><img src="https://fastapi.tiangolo.com/img/sponsors/blockbee.png"></a> |
| 55 |
<a href="https://www.propelauth.com/?utm_source=fastapi&utm_campaign=1223&utm_medium=mainbadge" target="_blank" title="Auth, user management and more for your B2B product"><img src="https://fastapi.tiangolo.com/img/sponsors/propelauth.png"></a> |
| 56 |
<a href="https://docs.render.com/deploy-fastapi?utm_source=deploydoc&utm_medium=referral&utm_campaign=fastapi" target="_blank" title="Deploy & scale any full-stack web app on Render. Focus on building apps, not infra."><img src="https://fastapi.tiangolo.com/img/sponsors/render.svg"></a> |
| 57 |
<a href="https://www.coderabbit.ai/?utm_source=fastapi&utm_medium=badge&utm_campaign=fastapi" target="_blank" title="Cut Code Review Time & Bugs in Half with CodeRabbit"><img src="https://fastapi.tiangolo.com/img/sponsors/coderabbit.png"></a> |
| 58 |
<a href="https://subtotal.com/?utm_source=fastapi&utm_medium=sponsorship&utm_campaign=open-source" target="_blank" title="The Gold Standard in Retail Account Linking"><img src="https://fastapi.tiangolo.com/img/sponsors/subtotal.svg"></a> |
| 59 |
<a href="https://docs.railway.com/guides/fastapi?utm_medium=integration&utm_source=docs&utm_campaign=fastapi" target="_blank" title="Deploy enterprise applications at startup speed"><img src="https://fastapi.tiangolo.com/img/sponsors/railway.png"></a> |
| 60 |
<a href="https://serpapi.com/?utm_source=fastapi_website" target="_blank" title="SerpApi: Web Search API"><img src="https://fastapi.tiangolo.com/img/sponsors/serpapi.png"></a> |
| 61 |
<a href="https://www.greptile.com/?utm_source=fastapi&utm_medium=sponsorship&utm_campaign=fastapi_sponsor_page" target="_blank" title="Greptile: The AI Code Reviewer"><img src="https://fastapi.tiangolo.com/img/sponsors/greptile.png"></a> |
| 62 |
|
| 63 |
### Silver Sponsors |
| 64 |
|
| 65 |
<a href="https://databento.com/?utm_source=fastapi&utm_medium=sponsor&utm_content=display" target="_blank" title="Pay as you go for market data"><img src="https://fastapi.tiangolo.com/img/sponsors/databento.svg"></a> |
| 66 |
<a href="https://www.svix.com/" target="_blank" title="Svix - Webhooks as a service"><img src="https://fastapi.tiangolo.com/img/sponsors/svix.svg"></a> |
| 67 |
<a href="https://www.permit.io/blog/implement-authorization-in-fastapi?utm_source=github&utm_medium=referral&utm_campaign=fastapi" target="_blank" title="Fine-Grained Authorization for FastAPI"><img src="https://fastapi.tiangolo.com/img/sponsors/permit.png"></a> |
| 68 |
<a href="https://dribia.com/en/" target="_blank" title="Dribia - Data Science within your reach"><img src="https://fastapi.tiangolo.com/img/sponsors/dribia.png"></a> |
| 69 |
<a href="https://www.bairesdev.com/" target="_blank" title="BairesDev | Nearshore Software Development & Staff Augmentation Company"><img src="https://fastapi.tiangolo.com/img/sponsors/bairesdev.svg"></a> |
| 70 |
<a href="https://tutorcruncher.com/?utm_source=fastapi" target="_blank" title="TutorCruncher"><img src="https://fastapi.tiangolo.com/img/sponsors/tutorcruncher.png"></a> |
| 71 |
|
| 72 |
<!-- /sponsors --> |
| 73 |
|
| 74 |
[Other sponsors](https://fastapi.tiangolo.com/fastapi-people/#sponsors) |
| 75 |
|
| 76 |
## Opinions |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
<div class="only-github" markdown="1"> |
| 81 |
|
| 82 |
"_[...] I'm using **FastAPI** a ton these days. [...] I'm actually planning to use it for all of my team's **ML services at Microsoft**. Some of them are getting integrated into the core **Windows** product and some **Office** products._" |
| 83 |
|
| 84 |
<div style="text-align: right; margin-right: 10%;">Kabir Khan - <strong>Microsoft</strong> <a href="https://github.com/fastapi/fastapi/pull/26"><small>(ref)</small></a></div> |
| 85 |
|
| 86 |
--- |
| 87 |
|
| 88 |
"_We adopted the **FastAPI** library to spawn a **REST** server that can be queried to obtain **predictions**. [for Ludwig]_" |
| 89 |
|
| 90 |
<div style="text-align: right; margin-right: 10%;">Piero Molino, Yaroslav Dudin, and Sai Sumanth Miryala - <strong>Uber</strong> <a href="https://www.uber.com/us/en/blog/ludwig-v0-2/"><small>(ref)</small></a></div> |
| 91 |
|
| 92 |
--- |
| 93 |
|
| 94 |
"_**Netflix** is pleased to announce the open-source release of our **crisis management** orchestration framework: **Dispatch**! [built with **FastAPI**]_" |
| 95 |
|
| 96 |
<div style="text-align: right; margin-right: 10%;">Kevin Glisson, Marc Vilanova, Forest Monsen - <strong>Netflix</strong> <a href="https://netflixtechblog.com/introducing-dispatch-da4b8a2a8072"><small>(ref)</small></a></div> |
| 97 |
|
| 98 |
--- |
| 99 |
|
| 100 |
"_If anyone is looking to build a production Python API, I would highly recommend **FastAPI**. It is **beautifully designed**, **simple to use** and **highly scalable**, it has become a **key component** in our API first development strategy and is driving many automations and services such as our Virtual TAC Engineer._" |
| 101 |
|
| 102 |
<div style="text-align: right; margin-right: 10%;">Deon Pillsbury - <strong>Cisco</strong> <a href="https://www.linkedin.com/posts/deonpillsbury_cisco-cx-python-activity-6963242628536487936-trAp/"><small>(ref)</small></a></div> |
| 103 |
|
| 104 |
--- |
| 105 |
|
| 106 |
</div> |
| 107 |
|
| 108 |
## FastAPI Conf |
| 109 |
|
| 110 |
[**FastAPI Conf '26**](https://fastapiconf.com) is happening on **October 28, 2026** in **Amsterdam, NL**. All about FastAPI, right from the source. ๐ค |
| 111 |
|
| 112 |
<a class="fastapi-feature-banner" href="https://fastapiconf.com"><img src="https://fastapi.tiangolo.com/img/fastapi-conf.jpeg" alt="FastAPI Conf '26 - October 28, 2026 - Amsterdam, NL"></a> |
| 113 |
|
| 114 |
## FastAPI mini documentary |
| 115 |
|
| 116 |
There's a [FastAPI mini documentary](https://www.youtube.com/watch?v=mpR8ngthqiE) released at the end of 2025, you can watch it online: |
| 117 |
|
| 118 |
<a class="fastapi-feature-banner" href="https://www.youtube.com/watch?v=mpR8ngthqiE"><img src="https://fastapi.tiangolo.com/img/fastapi-documentary.jpg" alt="FastAPI Mini Documentary"></a> |
| 119 |
|
| 120 |
## **Typer**, the FastAPI of CLIs |
| 121 |
|
| 122 |
<a href="https://typer.tiangolo.com"><img src="https://typer.tiangolo.com/img/logo-margin/logo-margin-vector.svg" style="width: 20%;"></a> |
| 123 |
|
| 124 |
If you are building a <abbr title="Command Line Interface">CLI</abbr> app to be used in the terminal instead of a web API, check out [**Typer**](https://typer.tiangolo.com/). |
| 125 |
|
| 126 |
**Typer** is FastAPI's little sibling. And it's intended to be the **FastAPI of CLIs**. โจ๏ธ ๐ |
| 127 |
|
| 128 |
## Requirements |
| 129 |
|
| 130 |
FastAPI stands on the shoulders of giants: |
| 131 |
|
| 132 |
* [Starlette](https://starlette.dev/) for the web parts. |
| 133 |
* [Pydantic](https://pydantic.dev/docs/) for the data parts. |
| 134 |
|
| 135 |
## Installation |
| 136 |
|
| 137 |
First, [install `uv`](https://docs.astral.sh/uv/getting-started/installation/), and then add FastAPI to your project: |
| 138 |
|
| 139 |
<div class="termy"> |
| 140 |
|
| 141 |
```console |
| 142 |
$ uv add "fastapi[standard]" |
| 143 |
|
| 144 |
---> 100% |
| 145 |
``` |
| 146 |
|
| 147 |
</div> |
| 148 |
|
| 149 |
**Note**: Make sure you put `"fastapi[standard]"` in quotes to ensure it works in all terminals. |
| 150 |
|
| 151 |
If you prefer to use `pip`, install `fastapi[standard]` inside a virtual environment. See the [installation guide](tutorial/#install-fastapi) for the alternative steps. |
| 152 |
|
| 153 |
## Example |
| 154 |
|
| 155 |
### Create it |
| 156 |
|
| 157 |
Create a file `main.py` with: |
| 158 |
|
| 159 |
```Python |
| 160 |
from fastapi import FastAPI |
| 161 |
|
| 162 |
app = FastAPI() |
| 163 |
|
| 164 |
|
| 165 |
@app.get("/") |
| 166 |
def read_root(): |
| 167 |
return {"Hello": "World"} |
| 168 |
|
| 169 |
|
| 170 |
@app.get("/items/{item_id}") |
| 171 |
def read_item(item_id: int, q: str | None = None): |
| 172 |
return {"item_id": item_id, "q": q} |
| 173 |
``` |
| 174 |
|
| 175 |
<details markdown="1"> |
| 176 |
<summary>Or use <code>async def</code>...</summary> |
| 177 |
|
| 178 |
If your code uses `async` / `await`, use `async def`: |
| 179 |
|
| 180 |
```Python hl_lines="7 12" |
| 181 |
from fastapi import FastAPI |
| 182 |
|
| 183 |
app = FastAPI() |
| 184 |
|
| 185 |
|
| 186 |
@app.get("/") |
| 187 |
async def read_root(): |
| 188 |
return {"Hello": "World"} |
| 189 |
|
| 190 |
|
| 191 |
@app.get("/items/{item_id}") |
| 192 |
async def read_item(item_id: int, q: str | None = None): |
| 193 |
return {"item_id": item_id, "q": q} |
| 194 |
``` |
| 195 |
|
| 196 |
**Note**: |
| 197 |
|
| 198 |
If you don't know, check the _"In a hurry?"_ section about [`async` and `await` in the docs](https://fastapi.tiangolo.com/async/#in-a-hurry). |
| 199 |
|
| 200 |
</details> |
| 201 |
|
| 202 |
### Run it |
| 203 |
|
| 204 |
Run the server with: |
| 205 |
|
| 206 |
<div class="termy"> |
| 207 |
|
| 208 |
```console |
| 209 |
$ uv run fastapi dev |
| 210 |
|
| 211 |
โญโโโโโโโโโโ FastAPI CLI - Development mode โโโโโโโโโโโโฎ |
| 212 |
โ โ |
| 213 |
โ Serving at: http://127.0.0.1:8000 โ |
| 214 |
โ โ |
| 215 |
โ API docs: http://127.0.0.1:8000/docs โ |
| 216 |
โ โ |
| 217 |
โ Running in development mode, for production use: โ |
| 218 |
โ โ |
| 219 |
โ fastapi run โ |
| 220 |
โ โ |
| 221 |
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ |
| 222 |
|
| 223 |
INFO: Will watch for changes in these directories: ['/home/user/code/awesomeapp'] |
| 224 |
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) |
| 225 |
INFO: Started reloader process [2248755] using WatchFiles |
| 226 |
INFO: Started server process [2248757] |
| 227 |
INFO: Waiting for application startup. |
| 228 |
INFO: Application startup complete. |
| 229 |
``` |
| 230 |
|
| 231 |
</div> |
| 232 |
|
| 233 |
<details markdown="1"> |
| 234 |
<summary>About the command <code>fastapi dev</code>...</summary> |
| 235 |
|
| 236 |
The command `fastapi dev` reads your `main.py` file automatically, detects the **FastAPI** app in it, and starts a server using [Uvicorn](https://uvicorn.dev). |
| 237 |
|
| 238 |
By default, `fastapi dev` will start with auto-reload enabled for local development. |
| 239 |
|
| 240 |
You can read more about it in the [FastAPI CLI docs](https://fastapi.tiangolo.com/fastapi-cli/). |
| 241 |
|
| 242 |
</details> |
| 243 |
|
| 244 |
### Check it |
| 245 |
|
| 246 |
Open your browser at [http://127.0.0.1:8000/items/5?q=somequery](http://127.0.0.1:8000/items/5?q=somequery). |
| 247 |
|
| 248 |
You will see the JSON response as: |
| 249 |
|
| 250 |
```JSON |
| 251 |
{"item_id": 5, "q": "somequery"} |
| 252 |
``` |
| 253 |
|
| 254 |
You already created an API that: |
| 255 |
|
| 256 |
* Receives HTTP requests in the _paths_ `/` and `/items/{item_id}`. |
| 257 |
* Both _paths_ take `GET` <em>operations</em> (also known as HTTP _methods_). |
| 258 |
* The _path_ `/items/{item_id}` has a _path parameter_ `item_id` that should be an `int`. |
| 259 |
* The _path_ `/items/{item_id}` has an optional `str` _query parameter_ `q`. |
| 260 |
|
| 261 |
### Interactive API docs |
| 262 |
|
| 263 |
Now go to [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs). |
| 264 |
|
| 265 |
You will see the automatic interactive API documentation (provided by [Swagger UI](https://github.com/swagger-api/swagger-ui)): |
| 266 |
|
| 267 |
 |
| 268 |
|
| 269 |
### Alternative API docs |
| 270 |
|
| 271 |
And now, go to [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc). |
| 272 |
|
| 273 |
You will see the alternative automatic documentation (provided by [ReDoc](https://github.com/Redocly/redoc)): |
| 274 |
|
| 275 |
 |
| 276 |
|
| 277 |
## Example upgrade |
| 278 |
|
| 279 |
Now modify the file `main.py` to receive a body from a `PUT` request. |
| 280 |
|
| 281 |
Declare the body using standard Python types, thanks to Pydantic. |
| 282 |
|
| 283 |
```Python hl_lines="2 7-10 23-25" |
| 284 |
from fastapi import FastAPI |
| 285 |
from pydantic import BaseModel |
| 286 |
|
| 287 |
app = FastAPI() |
| 288 |
|
| 289 |
|
| 290 |
class Item(BaseModel): |
| 291 |
name: str |
| 292 |
price: float |
| 293 |
is_offer: bool | None = None |
| 294 |
|
| 295 |
|
| 296 |
@app.get("/") |
| 297 |
def read_root(): |
| 298 |
return {"Hello": "World"} |
| 299 |
|
| 300 |
|
| 301 |
@app.get("/items/{item_id}") |
| 302 |
def read_item(item_id: int, q: str | None = None): |
| 303 |
return {"item_id": item_id, "q": q} |
| 304 |
|
| 305 |
|
| 306 |
@app.put("/items/{item_id}") |
| 307 |
def update_item(item_id: int, item: Item): |
| 308 |
return {"item_name": item.name, "item_id": item_id} |
| 309 |
``` |
| 310 |
|
| 311 |
The `fastapi dev` server should reload automatically. |
| 312 |
|
| 313 |
### Interactive API docs upgrade |
| 314 |
|
| 315 |
Now go to [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs). |
| 316 |
|
| 317 |
* The interactive API documentation will be automatically updated, including the new body: |
| 318 |
|
| 319 |
 |
| 320 |
|
| 321 |
* Click on the button "Try it out", it allows you to fill the parameters and directly interact with the API: |
| 322 |
|
| 323 |
 |
| 324 |
|
| 325 |
* Then click on the "Execute" button, the user interface will communicate with your API, send the parameters, get the results and show them on the screen: |
| 326 |
|
| 327 |
 |
| 328 |
|
| 329 |
### Alternative API docs upgrade |
| 330 |
|
| 331 |
And now, go to [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc). |
| 332 |
|
| 333 |
* The alternative documentation will also reflect the new query parameter and body: |
| 334 |
|
| 335 |
 |
| 336 |
|
| 337 |
### Recap |
| 338 |
|
| 339 |
In summary, you declare **once** the types of parameters, body, etc. as function parameters. |
| 340 |
|
| 341 |
You do that with standard modern Python types. |
| 342 |
|
| 343 |
You don't have to learn a new syntax, the methods or classes of a specific library, etc. |
| 344 |
|
| 345 |
Just standard **Python**. |
| 346 |
|
| 347 |
For example, for an `int`: |
| 348 |
|
| 349 |
```Python |
| 350 |
item_id: int |
| 351 |
``` |
| 352 |
|
| 353 |
or for a more complex `Item` model: |
| 354 |
|
| 355 |
```Python |
| 356 |
item: Item |
| 357 |
``` |
| 358 |
|
| 359 |
...and with that single declaration you get: |
| 360 |
|
| 361 |
* Editor support, including: |
| 362 |
* Completion. |
| 363 |
* Type checks. |
| 364 |
* Validation of data: |
| 365 |
* Automatic and clear errors when the data is invalid. |
| 366 |
* Validation even for deeply nested JSON objects. |
| 367 |
* <dfn title="also known as: serialization, parsing, marshalling">Conversion</dfn> of input data: coming from the network to Python data and types. Reading from: |
| 368 |
* JSON. |
| 369 |
* Path parameters. |
| 370 |
* Query parameters. |
| 371 |
* Cookies. |
| 372 |
* Headers. |
| 373 |
* Forms. |
| 374 |
* Files. |
| 375 |
* <dfn title="also known as: serialization, parsing, marshalling">Conversion</dfn> of output data: converting from Python data and types to network data (as JSON): |
| 376 |
* Convert Python types (`str`, `int`, `float`, `bool`, `list`, etc). |
| 377 |
* `datetime` objects. |
| 378 |
* `UUID` objects. |
| 379 |
* Database models. |
| 380 |
* ...and many more. |
| 381 |
* Automatic interactive API documentation, including 2 alternative user interfaces: |
| 382 |
* Swagger UI. |
| 383 |
* ReDoc. |
| 384 |
|
| 385 |
--- |
| 386 |
|
| 387 |
Coming back to the previous code example, **FastAPI** will: |
| 388 |
|
| 389 |
* Validate that there is an `item_id` in the path for `GET` and `PUT` requests. |
| 390 |
* Validate that the `item_id` is of type `int` for `GET` and `PUT` requests. |
| 391 |
* If it is not, the client will see a useful, clear error. |
| 392 |
* Check if there is an optional query parameter named `q` (as in `http://127.0.0.1:8000/items/foo?q=somequery`) for `GET` requests. |
| 393 |
* As the `q` parameter is declared with `= None`, it is optional. |
| 394 |
* Without the `None` it would be required (as is the body in the case with `PUT`). |
| 395 |
* For `PUT` requests to `/items/{item_id}`, read the body as JSON: |
| 396 |
* Check that it has a required attribute `name` that should be a `str`. |
| 397 |
* Check that it has a required attribute `price` that has to be a `float`. |
| 398 |
* Check that it has an optional attribute `is_offer`, that should be a `bool`, if present. |
| 399 |
* All this would also work for deeply nested JSON objects. |
| 400 |
* Convert from and to JSON automatically. |
| 401 |
* Document everything with OpenAPI, that can be used by: |
| 402 |
* Interactive documentation systems. |
| 403 |
* Automatic client code generation systems, for many languages. |
| 404 |
* Provide 2 interactive documentation web interfaces directly. |
| 405 |
|
| 406 |
--- |
| 407 |
|
| 408 |
We just scratched the surface, but you already get the idea of how it all works. |
| 409 |
|
| 410 |
Try changing the line with: |
| 411 |
|
| 412 |
```Python |
| 413 |
return {"item_name": item.name, "item_id": item_id} |
| 414 |
``` |
| 415 |
|
| 416 |
...from: |
| 417 |
|
| 418 |
```Python |
| 419 |
... "item_name": item.name ... |
| 420 |
``` |
| 421 |
|
| 422 |
...to: |
| 423 |
|
| 424 |
```Python |
| 425 |
... "item_price": item.price ... |
| 426 |
``` |
| 427 |
|
| 428 |
...and see how your editor will auto-complete the attributes and know their types: |
| 429 |
|
| 430 |
 |
| 431 |
|
| 432 |
For a more complete example including more features, see the <a href="https://fastapi.tiangolo.com/tutorial/">Tutorial - User Guide</a>. |
| 433 |
|
| 434 |
**Spoiler alert**: the tutorial - user guide includes: |
| 435 |
|
| 436 |
* Declaration of **parameters** from other different places such as: **headers**, **cookies**, **form fields** and **files**. |
| 437 |
* How to set **validation constraints** such as `maximum_length` or `regex`. |
| 438 |
* A very powerful and easy to use **<dfn title="also known as components, resources, providers, services, injectables">Dependency Injection</dfn>** system. |
| 439 |
* Security and authentication, including support for **OAuth2** with **JWT tokens** and **HTTP Basic** auth. |
| 440 |
* More advanced (but equally easy) techniques for declaring **deeply nested JSON models** (thanks to Pydantic). |
| 441 |
* **GraphQL** integration with [Strawberry](https://strawberry.rocks) and other libraries. |
| 442 |
* Many extra features (thanks to Starlette) such as: |
| 443 |
* **WebSockets** |
| 444 |
* extremely easy tests based on HTTPX and `pytest` |
| 445 |
* **CORS** |
| 446 |
* **Cookie Sessions** |
| 447 |
* ...and more. |
| 448 |
|
| 449 |
### Deploy your app (optional) |
| 450 |
|
| 451 |
You can optionally deploy your FastAPI app to [FastAPI Cloud](https://fastapicloud.com) with a single command. ๐ |
| 452 |
|
| 453 |
<div class="termy"> |
| 454 |
|
| 455 |
```console |
| 456 |
$ uv run fastapi deploy |
| 457 |
|
| 458 |
Deploying to FastAPI Cloud... |
| 459 |
|
| 460 |
โ
Deployment successful! |
| 461 |
|
| 462 |
๐ Ready the chicken! Your app is ready at https://myapp.fastapicloud.dev |
| 463 |
``` |
| 464 |
|
| 465 |
</div> |
| 466 |
|
| 467 |
The CLI will automatically detect your FastAPI application and deploy it to the cloud. If you are not logged in, your browser will open to complete the authentication process. |
| 468 |
|
| 469 |
That's it! Now you can access your app at that URL. โจ |
| 470 |
|
| 471 |
#### About FastAPI Cloud |
| 472 |
|
| 473 |
**[FastAPI Cloud](https://fastapicloud.com)** is built by the same author and team behind **FastAPI**. |
| 474 |
|
| 475 |
It streamlines the process of **building**, **deploying**, and **accessing** an API with minimal effort. |
| 476 |
|
| 477 |
It brings the same **developer experience** of building apps with FastAPI to **deploying** them to the cloud. ๐ |
| 478 |
|
| 479 |
FastAPI Cloud is the primary sponsor and funding provider for the *FastAPI and friends* open source projects. โจ |
| 480 |
|
| 481 |
#### Deploy to other cloud providers |
| 482 |
|
| 483 |
FastAPI is open source and based on standards. You can deploy FastAPI apps to any cloud provider you choose. |
| 484 |
|
| 485 |
Follow your cloud provider's guides to deploy FastAPI apps with them. ๐ค |
| 486 |
|
| 487 |
## Performance |
| 488 |
|
| 489 |
Independent TechEmpower benchmarks show **FastAPI** applications running under Uvicorn as [one of the fastest Python frameworks available](https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-7), only below Starlette and Uvicorn themselves (used internally by FastAPI). (*) |
| 490 |
|
| 491 |
To understand more about it, see the section [Benchmarks](https://fastapi.tiangolo.com/benchmarks/). |
| 492 |
|
| 493 |
## Dependencies |
| 494 |
|
| 495 |
FastAPI depends on Pydantic and Starlette. |
| 496 |
|
| 497 |
### `standard` Dependencies |
| 498 |
|
| 499 |
When you install FastAPI with `uv add "fastapi[standard]"` it comes with the `standard` group of optional dependencies: |
| 500 |
|
| 501 |
Used by Pydantic: |
| 502 |
|
| 503 |
* [`email-validator`](https://github.com/JoshData/python-email-validator) - for email validation. |
| 504 |
|
| 505 |
Used by Starlette: |
| 506 |
|
| 507 |
* [`httpx`](https://www.python-httpx.org) - Required if you want to use the `TestClient`. |
| 508 |
* [`jinja2`](https://jinja.palletsprojects.com) - Required if you want to use the default template configuration. |
| 509 |
* [`python-multipart`](https://github.com/Kludex/python-multipart) - Required if you want to support form <dfn title="converting the string that comes from an HTTP request into Python data">"parsing"</dfn>, with `request.form()`. |
| 510 |
|
| 511 |
Used by FastAPI: |
| 512 |
|
| 513 |
* [`uvicorn`](https://uvicorn.dev) - for the server that loads and serves your application. This includes `uvicorn[standard]`, which includes some dependencies (e.g. `uvloop`) needed for high performance serving. |
| 514 |
* `fastapi-cli[standard]` - to provide the `fastapi` command. |
| 515 |
* This includes `fastapi-cloud-cli`, which allows you to deploy your FastAPI application to [FastAPI Cloud](https://fastapicloud.com). |
| 516 |
|
| 517 |
### Without `standard` Dependencies |
| 518 |
|
| 519 |
If you don't want to include the `standard` optional dependencies, you can install with `uv add fastapi` instead of `uv add "fastapi[standard]"`. |
| 520 |
|
| 521 |
### Without `fastapi-cloud-cli` |
| 522 |
|
| 523 |
If you want to install FastAPI with the standard dependencies but without the `fastapi-cloud-cli`, you can install with `uv add "fastapi[standard-no-fastapi-cloud-cli]"`. |
| 524 |
|
| 525 |
### Additional Optional Dependencies |
| 526 |
|
| 527 |
There are some additional dependencies you might want to install. |
| 528 |
|
| 529 |
Additional optional Pydantic dependencies: |
| 530 |
|
| 531 |
* [`pydantic-settings`](https://pydantic.dev/docs/validation/latest/concepts/pydantic_settings/) - for settings management. |
| 532 |
* [`pydantic-extra-types`](https://github.com/pydantic/pydantic-extra-types) - for extra types to be used with Pydantic. |
| 533 |
|
| 534 |
Additional optional FastAPI dependencies: |
| 535 |
|
| 536 |
* [`orjson`](https://github.com/ijl/orjson) - Required if you want to use `ORJSONResponse`. |
| 537 |
* [`ujson`](https://github.com/ultrajson/ultrajson) - Required if you want to use `UJSONResponse`. |
| 538 |
|
| 539 |
## License |
| 540 |
|
| 541 |
This project is licensed under the terms of the MIT license. |