Pydantic and Data Validation
May 30, 2026 | 5 min read
Basic Validation
from pydantic import BaseModel
class Order(BaseModel):
id: int
quantity: int
price: float
def validate_orders(raw: list[dict]) -> list[Order]:
orders = []
for r in raw:
orders.append(Order(**r))
return orders
Nested Models
class Customer(BaseModel):
name: str
orders: list[Order]
def total_revenue(customers: list[Customer]) -> float:
total = 0.0
for c in customers:
for o in c.orders:
total += o.quantity * o.price
return total
Performance Notes
Pydantic v2 is Rust-accelerated. Pyvorin compiles the Python orchestration around Pydantic models, not the validation itself.