Pythonfastapiv0.135.2
PythonBeginner-friendly

fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production

apiasyncopenapipydanticweb-frameworkapplication-frameworkshttp-serverslibrariespython-moduleswww/http
The Problem

Building Python APIs with Flask meant adding separate libraries for validation, serialization, and auto-generated docs β€” and none of them talked to each other. Django REST Framework was powerful but heavy. FastAPI was designed around the insight that Python type hints contain everything needed to handle all three automatically.

Mental Model

In FastAPI, your function signatures are the API contract. Annotate a parameter as int and FastAPI validates the incoming value, rejects bad requests, and documents the type in the OpenAPI spec β€” all from the same annotation. Pydantic models define request/response shapes and handle serialization. The result is an API where the code and the docs are always in sync.

60-second start

Install fastapi

pip install fastapi
import fastapi

Use it when

Use FastAPI when building REST or GraphQL APIs in Python, especially when you need async support, automatic OpenAPI/Swagger docs, request validation, or are building microservices. It's the best choice for new Python API projects.

Skip it when

FastAPI is API-only β€” it has no templating, admin interface, or ORM. For full-stack web apps with server-rendered HTML, Django is better. For tiny internal tools, Flask's smaller learning curve might be preferable.

Alternatives
djangoFull-featured framework with built-in ORM, admin, auth β€” better for full-stack apps
flaskSimpler and more flexible; good for small APIs or when you want to choose every component yourself
litestarSimilar philosophy to FastAPI but with different design choices; worth evaluating for new projects

Ready to explore the full API?

See every class, function, and relationship in an interactive graph.