sponsor
Follow FastAPI on LinkedIn to stay updated
FastAPI Search fastapi/fastapi
FastAPI Features Learn Reference FastAPI People Resources About Release Notes
Learn FastAPI Learn Tutorial - User Guide Table of contents
Python Types Intro Run the code
Concurrency and async / await Tutorial - User Guide Install FastAPI
Environment Variables Advanced User Guide
Virtual Environments
This tutorial shows you how to use FastAPI with most of its features, step by step.
Tutorial - User Guide
First Steps Each section gradually builds on the previous ones, but it's structured to separate topics, so that
Path Parameters you can go directly to any specific one to solve your specific API needs.
Query Parameters
It is also built to work as a future reference so you can come back and see exactly what you
Request Body
need.
Query Parameters and String
Validations
Path Parameters and Numeric
Validations Run the code
Query Parameter Models
All the code blocks can be copied and used directly (they are actually tested Python files).
Body - Multiple Parameters
Body - Fields To run any of the examples, copy the code to a file main.py , and start fastapi dev with:
Body - Nested Models
Declare Request Example Data
bash
Extra Data Types
Cookie Parameters
fast →
Header Parameters
Cookie Parameter Models
Header Parameter Models
Response Model - Return Type
Extra Models
Response Status Code
Form Data
Form Models
Request Files
Request Forms and Files
Handling Errors
Path Operation Configuration
JSON Compatible Encoder
Body - Updates
Dependencies
Security
It is HIGHLY encouraged that you write or copy the code, edit it and run it locally.
Middleware
Using it in your editor is what really shows you the benefits of FastAPI, seeing how little code you
CORS (Cross-Origin Resource
have to write, all the type checks, autocompletion, etc.
Sharing)
SQL (Relational) Databases
Bigger Applications - Multiple
Files
Background Tasks
Install FastAPI
Metadata and Docs URLs
The first step is to install FastAPI.
Static Files
Testing Make sure you create a virtual environment ↪, activate it, and then install FastAPI:
Debugging
Advanced User Guide
bash
fast →
Note
When you install with pip install "fastapi[standard]" it comes with some default optional standard
dependencies.
If you don't want to have those optional dependencies, you can instead install pip install fastapi .
Advanced User Guide
There is also an Advanced User Guide that you can read later after this Tutorial - User guide.
The Advanced User Guide builds on this one, uses the same concepts, and teaches you some
extra features.
But you should first read the Tutorial - User Guide (what you are reading right now).
It's designed so that you can build a complete application with just the Tutorial - User Guide, and
then extend it in different ways, depending on your needs, using some of the additional ideas
from the Advanced User Guide.
Previous Next
Virtual Environments First Steps
The FastAPI trademark is owned by @tiangolo and is registered in the US and across other regions
Made with Material for MkDocs
FastAPI CLI
Deployment
How To - Recipes