Pydantic Power-up: Performance Tips for Lightning-Fast Python Applications
summary
Pydantic V2 moves core validation into Rust and claims 5–50x speedups over V1; concrete tips include using model_validate_json to avoid Python materialization, reusing TypeAdapter instances to avoid repeated schema builds, and preferring concrete types like list over Sequence. Tagged (discriminated) unions let the validator pick one branch instead of trying all members, preventing exponential validation blowup and producing clearer errors. Roadmap items: SIMD/JIT accel, validating while parsing to keep data in Rust, and lazy materialization of attributes.
AI-written summary · about
chapters (9)
- 0:00Introduction to Pydantic
- 2:49Basic performance tips
- 5:42Tagged unions overview
- 8:36Union performance and errors
- 10:02Advanced union techniques
- 12:09Nested models and unions
- 14:01Future performance plans
- 14:52Contributing to Pydantic
- 18:43Logfire announcement and Q&A
related talks
27mFrom Pydantic V1 to V2
46mHow Pydantic V2 leverages Rust's Superpowers
26mIntro to Pydantic, run-time type checking for your dataclasses
23mRewrite everything in Rust? What we learned from introducing Rust in Strawberry-GraphQL
21mLet JSON Schema and Pydantic write your data models
31mPumping up Python modules using Rust
36mPumping up Python modules using Rust
28m"Validating Complex Types Using Pydantic"
