FastAPI
raw JSON → 0.136.0 verified Tue May 12 auth: no python install: verified quickstart: verified
FastAPI is a modern, fast (high-performance) web framework for building APIs with Python 3.8+ based on standard Python type hints. It leverages Starlette for the web parts and Pydantic for data validation and serialization. It features automatic OpenAPI documentation (Swagger UI, ReDoc). The current version is 0.136.0, and it maintains a frequent release cadence, often with minor updates several times a month.
pip install "fastapi[standard]" uvicorn Common errors
error ModuleNotFoundError: No module named 'uvicorn' ↓
cause The Uvicorn ASGI server, necessary to run FastAPI applications, is not installed.
fix
Install Uvicorn using pip:
pip install "uvicorn[standard]" error TypeError: 'PydanticV1BaseModel' object is not subscriptable ↓
cause This error or similar (e.g., `NameError: name 'Field' is not defined` when using `pydantic.Field` for V2) often indicates a clash between FastAPI's expected Pydantic version (V2 for FastAPI >= 0.100.0) and an older Pydantic V1 syntax in your models, or vice-versa.
fix
Ensure your Pydantic version aligns with your FastAPI version. If using FastAPI >= 0.100.0, upgrade Pydantic to V2 (
pip install "pydantic>=2") and migrate your models. If staying on an older FastAPI, explicitly pin Pydantic to V1 (pip install "pydantic<2"). error fastapi.exceptions.HTTPException: 422 Unprocessable Entity ↓
cause The client sent data that does not match the Pydantic model defined in the path operation function's parameters, or fails its validation rules.
fix
Review the client's request payload and the Pydantic model definition for the route. Ensure data types, required fields, and any constraints (e.g., min_length, regex) match. The
detail field in the error response provides specific validation errors. error RuntimeError: There is no current event loop in this thread. ↓
cause Attempting to run asynchronous code (e.g., an `async def` function or `await`) in a synchronous context, or without an active `asyncio` event loop. This often happens when calling async FastAPI components from a non-async part of the code.
fix
Ensure your FastAPI application is always run with an ASGI server like Uvicorn, which properly manages the event loop. If calling async functions outside a path operation, ensure it's within an
async def function that is itself awaited, or use asyncio.run() for top-level execution where appropriate. error {'detail': [{'loc': ['body', 'name'], 'msg': 'field required', 'type': 'value_error.missing'}]} ↓
cause This is a Pydantic validation error indicating that a required field (e.g., 'name') was not provided in the request body, or its type was incorrect.
fix
Ensure your API request body includes all required fields with the correct data types, matching your Pydantic models.
Warnings
breaking FastAPI version 0.100.0 and above officially support Pydantic V2. Upgrading FastAPI may automatically upgrade Pydantic from V1 to V2, leading to significant breaking changes in model syntax, validators, and error handling. This is a major compatibility consideration. ↓
fix Consult the official Pydantic V2 migration guide and FastAPI's Pydantic V2 migration notes. Downgrade Pydantic to `<2.0.0` if staying on an older FastAPI, or refactor models and code for Pydantic V2.
gotcha Using blocking I/O operations (e.g., synchronous database calls, heavy computations) directly within `async def` FastAPI path operations can block the entire event loop, severely degrading performance and concurrency. ↓
fix Run blocking operations in a separate thread pool using `anyio.to_thread.run_sync()` or `loop.run_in_executor()`, or use async-native libraries (e.g., `asyncpg`, `databases`). For CPU-bound tasks, consider external workers.
gotcha To run FastAPI applications, an ASGI server like Uvicorn is required. For certain features, such as parsing form data, optional dependencies like `python-multipart` are also needed. Missing these will lead to runtime errors or incomplete functionality. ↓
fix Install `uvicorn` and other necessary optional dependencies. For a common setup, `pip install "fastapi[standard]" uvicorn` is recommended, as `[standard]` includes `python-multipart` and others.
deprecated The experimental `@app.vibe()` decorator, briefly introduced in v0.135.3 for 'vibe coding,' was removed just one patch version later in v0.135.4. Applications that adopted this feature during its short lifespan will fail to start on newer versions. ↓
fix Remove all usage of `@app.vibe()` from your application code. This feature was temporary and is no longer supported.
Install
pip install fastapi uvicorn[standard] Install compatibility verified last tested: 2026-05-12
python os / libc variant status wheel install import disk
3.10 alpine (musl) all - - 1.55s 80.3M
3.10 alpine (musl) standard - - 1.57s 80.2M
3.10 alpine (musl) standard - - 1.57s 80.4M
3.10 alpine (musl) fastapi - - 1.14s 31.8M
3.10 alpine (musl) fastapi - - 1.15s 49.5M
3.10 slim (glibc) all - - 1.16s 83M
3.10 slim (glibc) standard - - 1.17s 83M
3.10 slim (glibc) standard - - 1.16s 83M
3.10 slim (glibc) fastapi - - 0.84s 31M
3.10 slim (glibc) fastapi - - 0.89s 53M
3.11 alpine (musl) all - - 2.56s 88.1M
3.11 alpine (musl) standard - - 2.54s 87.9M
3.11 alpine (musl) standard - - 2.31s 88.2M
3.11 alpine (musl) fastapi - - 1.48s 34.8M
3.11 alpine (musl) fastapi - - 1.35s 53.7M
3.11 slim (glibc) all - - 2.00s 91M
3.11 slim (glibc) standard - - 1.97s 91M
3.11 slim (glibc) standard - - 2.06s 91M
3.11 slim (glibc) fastapi - - 1.15s 34M
3.11 slim (glibc) fastapi - - 1.21s 57M
3.12 alpine (musl) all - - 2.09s 80.7M
3.12 alpine (musl) standard - - 2.11s 80.6M
3.12 alpine (musl) standard - - 1.98s 80.8M
3.12 alpine (musl) fastapi - - 1.41s 26.3M
3.12 alpine (musl) fastapi - - 1.35s 47.2M
3.12 slim (glibc) all - - 2.07s 85M
3.12 slim (glibc) standard - - 2.26s 84M
3.12 slim (glibc) standard - - 2.09s 85M
3.12 slim (glibc) fastapi - - 1.48s 26M
3.12 slim (glibc) fastapi - - 1.38s 52M
3.13 alpine (musl) all - - 1.70s 80.3M
3.13 alpine (musl) standard - - 1.72s 80.2M
3.13 alpine (musl) standard - - 1.62s 80.5M
3.13 alpine (musl) fastapi - - 1.05s 26.0M
3.13 alpine (musl) fastapi - - 0.99s 46.8M
3.13 slim (glibc) all - - 1.79s 84M
3.13 slim (glibc) standard - - 1.80s 84M
3.13 slim (glibc) standard - - 1.71s 84M
3.13 slim (glibc) fastapi - - 1.07s 26M
3.13 slim (glibc) fastapi - - 1.01s 51M
3.9 alpine (musl) all - - 1.53s 83.0M
3.9 alpine (musl) standard - - 1.51s 78.8M
3.9 alpine (musl) standard - - 1.54s 78.9M
3.9 alpine (musl) fastapi - - 1.09s 31.1M
3.9 alpine (musl) fastapi - - 1.11s 48.6M
3.9 slim (glibc) all - - 1.32s 82M
3.9 slim (glibc) standard - - 1.32s 81M
3.9 slim (glibc) standard - - 1.39s 82M
3.9 slim (glibc) fastapi - - 0.97s 31M
3.9 slim (glibc) fastapi - - 1.09s 52M
Imports
- FastAPI
from fastapi import FastAPI - Depends
from fastapi import Depends - HTTPException
from fastapi import HTTPException - status wrong
from starlette import statuscorrectfrom fastapi import status - Body
from fastapi import Body - Query
from fastapi import Query - Path
from fastapi import Path - Response wrong
from starlette.responses import Responsecorrectfrom fastapi import Response
Quickstart verified last tested: 2026-04-23
import uvicorn
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
async def read_item(item_id: int, q: str | None = None):
return {"item_id": item_id, "q": q}
# To run this app:
# 1. Save it as main.py
# 2. Run from your terminal: uvicorn main:app --reload
# Then open http://127.0.0.1:8000/ or http://127.0.0.1:8000/docs