FastAPI

0.135.0 · active · verified Wed Mar 25

High-performance Python web framework for building APIs, based on Starlette and Pydantic. Current version is 0.135.x (Mar 2026). Requires Python >=3.10 and Pydantic >=2.7.0. Pydantic v1 support fully removed.

Warnings

Install

Imports

Quickstart

Minimal FastAPI app with lifespan handler and Pydantic v2 model.

from contextlib import asynccontextmanager
from fastapi import FastAPI
from pydantic import BaseModel

@asynccontextmanager
async def lifespan(app: FastAPI):
    # startup logic here
    yield
    # shutdown logic here

app = FastAPI(lifespan=lifespan)

class Item(BaseModel):
    name: str
    price: float

@app.get('/')
def read_root():
    return {'status': 'ok'}

@app.post('/items')
def create_item(item: Item) -> Item:
    return item

# Run: fastapi dev main.py  (dev)
# Run: fastapi run main.py  (prod)

view raw JSON →