Pydantic

2.12.5 · active · verified Tue Mar 24

The most widely used Python data validation library. Powers OpenAI SDK, Anthropic SDK, LangChain, FastAPI, LlamaIndex, and hundreds of other libraries. V2 released June 2023 — a near-complete rewrite in Rust via pydantic-core, 4-50x faster than V1. Current version is 2.12.5 (Mar 2026). V1 security fixes ended June 2024. V3 planned roughly annually.

Warnings

Install

Imports

Quickstart

Pydantic V2 style model with field validator and config.

from pydantic import BaseModel, field_validator, ConfigDict

class User(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    name: str
    age: int

    @field_validator('age')
    @classmethod
    def age_positive(cls, v):
        assert v > 0, 'age must be positive'
        return v

user = User(name='Alice', age=30)
print(user.model_dump())  # not .dict()
print(user.model_dump_json())  # not .json()

view raw JSON →