Data-class-based Python validation
Pydantic — created by Samuel Colvin in 2017 — is a Python library for data validation via type hints. Type hints as validation schema instead of external JSON Schema. Becomes popular thanks to FastAPI adoption (Sebastián Ramírez, 2018) using it as foundation.
from pydantic import BaseModel, EmailStr
from datetime import datetime
class User(BaseModel):
id: int
name: str
email: EmailStr
created_at: datetime
user = User(id=1, name="Anna", email="anna@example.com",
created_at="2023-01-15T10:30:00")
# Automatically validates types, parses datetime string, verifies email
Pydantic 2.0 and Rust
Pydantic 2.0, released on 30 June 2023, is a core rewrite in Rust via pydantic-core crate. Performance improvements of 5-50x on validation. Python API remains mostly backward-compatible (with migration guide).
MIT licence.
Functionality
- Models with type hints
- Custom field validators
- Serialisers (JSON, dict, custom)
- Aliases for field mappings
- Automatic JSON Schema generation
- Generics for parametric types
- Strict mode — no implicit coercion
Dependent ecosystem
- FastAPI — request/response validation
- SQLModel (Sebastián Ramírez, 2021) — ORM based on Pydantic + SQLAlchemy
- LangChain — LLM structured output
- Prefect, Argilla, thousands of modern libraries
In the Italian context
Pydantic is in the backend of every Italian FastAPI application; growing in ML/AI for LLM structured output.
References: Pydantic 2.0 (30 June 2023). Samuel Colvin. MIT licence. Rust core rewrite (pydantic-core). Backward-compat API. Foundation of FastAPI, SQLModel, LangChain.
