I came to Pydantic through FastAPI. I stayed because Pydantic is the cleanest solution to a problem that every Python codebase eventually faces: validating and transforming structured data with clear error messages.
Before Pydantic: a function that accepted a dictionary and validated its contents manually. Ten lines of isinstance checks, .get() with defaults, and manual error accumulation.
After Pydantic: a BaseModel subclass with field types, validators, and defaults. The validation happens automatically on instantiation. The error messages are structured and specific. The model is self-documenting.
For the Sabivox ML pipeline: every request to the inference API is validated by a Pydantic model. Invalid inputs produce specific error messages instead of cryptic TypeErrors deep in the model inference code.
Pydantic works outside FastAPI. Use it in your CLI scripts, data processing pipelines, and configuration loaders. Anywhere you have structured data, Pydantic makes it safer.
— Dick Bassey | DevDick | 2024