How it works
In FastAPI an endpoint is a Python function whose parameters carry type hints or Pydantic models. FastAPI reads those hints to parse and validate the request, convert types, return clear errors and produce an OpenAPI description, which appears as interactive docs at /docs. Shared pieces such as a database session or the current user are injected with Depends.
It is built on Starlette (an ASGI toolkit) and Pydantic, supports async endpoints, and runs on an ASGI server such as Uvicorn. It has become a common way to put a Python machine-learning model or AI pipeline behind an HTTP API. It has no ORM, admin panel or templates of its own; SQLAlchemy or SQLModel usually fill the database gap.
FastAPI pros and cons
Pros
- Validation, conversion and docs come straight from type hints
- Automatic interactive API docs (Swagger UI and ReDoc)
- Async support and good performance for Python
- Natural fit for serving Python AI and data code
Cons
- No built-in ORM, admin or auth; you choose and wire them up
- Blocking libraries inside async endpoints can stall the server
- Large apps need their own structure and conventions
When to use FastAPI
Pick it when
- JSON APIs written in Python, especially with typed request bodies
- Putting machine-learning models or AI features behind an API
- Backends for mobile or single-page apps that need documented endpoints
Skip it when
- Content sites that need an admin panel and server-rendered pages, where Django fits better
FastAPI pricing
FastAPI vs the alternatives
Related terms
More in Backend and APIs
Frameworks