FastAPI is a modern Python web framework for building APIs, created by Sebastian Ramirez. Its defining feature is the use of Python type hints to define request parameters, request bodies, and response models. FastAPI uses these annotations to automatically validate input, serialise output, and generate interactive API documentation (Swagger UI and ReDoc) — with no additional code.
FastAPI is built on Starlette (an ASGI framework) and Pydantic (a data validation library). It supports async def endpoints natively, making it highly performant for I/O-bound workloads. Benchmarks consistently place FastAPI among the fastest Python web frameworks, comparable to Node.js and Go frameworks in throughput. It also supports synchronous def endpoints, which it runs in a thread pool automatically.
FastAPI has seen explosive growth since its release in 2018, particularly for machine learning APIs, microservices, and any project that benefits from auto-generated documentation and type-safe request handling. It combines the ease of Flask with the performance of async frameworks and the type safety of static analysis. For new API projects in Python, FastAPI has become the default recommendation in much of the community.
Discussed in:
- Chapter 20: The Python Ecosystem — Web Frameworks