API Reference

FastAPI

Modern, fast Python web framework for building APIs with automatic OpenAPI docs and type validation.

Official Documentation ↗
CompatibilityThis documentation covers version v0.111. Check the official docs for the latest API surface.

Installation

pippip install fastapi uvicorn

Methods

FastAPI is a modern Python web framework for building high-performance APIs. It leverages Python type hints for automatic request validation, response serialization, and OpenAPI documentation generation. FastAPI is ASGI-based and supports async/await for concurrent request handling.

Key Features

  • Automatic docs: Interactive Swagger UI and ReDoc at /docs and /redoc
  • Type validation: Pydantic-based request/response validation from type hints
  • Async support: Native async/await for concurrent I/O operations
  • Dependency injection: Built-in DI system for database, auth, and shared logic
  • High performance: On par with NodeJS and Go frameworks
  • OpenAPI 3.1: Full OpenAPI and JSON Schema compliance

Errors

The following points are quoted verbatim from the official documentation. 来源:https://fastapi.tiangolo.com/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:35.578Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://fastapi.tiangolo.com/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:35.578Z.

FAQ

How does FastAPI compare to Flask?
FastAPI provides automatic type validation, OpenAPI/Swagger docs, and async support out of the box. Flask requires extensions for these features. FastAPI is also faster, benchmarking at par with NodeJS and Go frameworks.
What is the ASGI server requirement?
FastAPI requires an ASGI server like Uvicorn (dev) or Hypercorn/Gunicorn with uvicorn worker (prod). This enables async/await support for concurrent request handling and WebSockets.
How do I handle database connections?
Use SQLAlchemy 2.0 with async sessions, or SQLModel (built on Pydantic + SQLAlchemy). For NoSQL, Motor (MongoDB) or Redis async. Dependency injection manages connection lifecycle per request.