Pydantic Validation
In a nutshell, Pydantic is dataclasses with runtime validation. It leverages type hints
to understand how validation (and serialization) should be performed. It is mostly useful
when dealing with external untrusted data, for example when defining an HTTP API.
It is generally not recommended to use Pydantic to define classes that are instantiated within the user code.
By doing so, you will lose flexibility (e.g. you cannot use types not supported by Pydantic, and it is harder to perform
post-init changes). It is usually better to use vanilla classes (or standard library dataclasses) in this case,
as a static type checker will already catch type mismatches.
Basic usage
Here is a simple example of using a Pydantic model:
from datetime import date
from pydantic import BaseModel, Field
Installs: 3.2K | GitHub stars: 161 | First seen: Jul 21, 2026


