"_[...] 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._"
@ -115,7 +115,7 @@ The key features are:
---
## **Typer**, the FastAPI of CLIs
## **Typer**, the FastAPI of CLIs { #typer-the-fastapi-of-clis }
@ -123,14 +123,14 @@ If you are building a <abbr title="Command Line Interface">CLI</abbr> app to be
**Typer** is FastAPI's little sibling. And it's intended to be the **FastAPI of CLIs**. ⌨️ 🚀
## Requirements
## Requirements { #requirements }
FastAPI stands on the shoulders of giants:
* <ahref="https://www.starlette.io/"class="external-link"target="_blank">Starlette</a> for the web parts.
* <ahref="https://docs.pydantic.dev/"class="external-link"target="_blank">Pydantic</a> for the data parts.
## Installation
## Installation { #installation }
Create and activate a <ahref="https://fastapi.tiangolo.com/virtual-environments/"class="external-link"target="_blank">virtual environment</a> and then install FastAPI:
**Note**: Make sure you put `"fastapi[standard]"` in quotes to ensure it works in all terminals.
## Example
## Example { #example }
### Create it
### Create it { #create-it }
Create a file `main.py` with:
@ -199,7 +199,7 @@ If you don't know, check the _"In a hurry?"_ section about <a href="https://fast
</details>
### Run it
### Run it { #run-it }
Run the server with:
@ -241,7 +241,7 @@ You can read more about it in the <a href="https://fastapi.tiangolo.com/fastapi-
</details>
### Check it
### Check it { #check-it }
Open your browser at <ahref="http://127.0.0.1:8000/items/5?q=somequery"class="external-link"target="_blank">http://127.0.0.1:8000/items/5?q=somequery</a>.
@ -258,7 +258,7 @@ You already created an API that:
* The _path_`/items/{item_id}` has a _path parameter_`item_id` that should be an `int`.
* The _path_`/items/{item_id}` has an optional `str`_query parameter_`q`.
### Interactive API docs
### Interactive API docs { #interactive-api-docs }
Now go to <ahref="http://127.0.0.1:8000/docs"class="external-link"target="_blank">http://127.0.0.1:8000/docs</a>.
@ -266,7 +266,7 @@ You will see the automatic interactive API documentation (provided by <a href="h
In summary, you declare **once** the types of parameters, body, etc. as function parameters.
@ -448,17 +448,17 @@ For a more complete example including more features, see the <a href="https://fa
* **Cookie Sessions**
* ...and more.
## Performance
## Performance { #performance }
Independent TechEmpower benchmarks show **FastAPI** applications running under Uvicorn as <ahref="https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-7"class="external-link"target="_blank">one of the fastest Python frameworks available</a>, only below Starlette and Uvicorn themselves (used internally by FastAPI). (*)
To understand more about it, see the section <ahref="https://fastapi.tiangolo.com/benchmarks/"class="internal-link"target="_blank">Benchmarks</a>.
When you install FastAPI with `pip install "fastapi[standard]"` it comes with the `standard` group of optional dependencies:
@ -478,15 +478,15 @@ Used by FastAPI:
* `fastapi-cli[standard]` - to provide the `fastapi` command.
* This includes `fastapi-cloud-cli`, which allows you to deploy your FastAPI application to <ahref="https://fastapicloud.com"class="external-link"target="_blank">FastAPI Cloud</a>.
### Without `standard` Dependencies
### Without `standard` Dependencies { #without-standard-dependencies }
If you don't want to include the `standard` optional dependencies, you can install with `pip install fastapi` instead of `pip install "fastapi[standard]"`.
### Without `fastapi-cloud-cli`
### Without `fastapi-cloud-cli` { #without-fastapi-cloud-cli }
If you want to install FastAPI with the standard dependencies but without the `fastapi-cloud-cli`, you can install with `pip install "fastapi[standard-no-fastapi-cloud-cli]"`.