Pydantic models are classes (subclassing BaseModel) that define the structure, types, and validation rules for data. FastAPI uses them everywhere — for request bodies, response shapes, and settings — making them the heart of its type-driven design.
Defining a model
pydantic BaseModel, EmailStr, Field
():
name:
email: EmailStr
age: = Field(ge=, le=)
is_active: =
tags: [] = []
