Home

Pydantic

Pydantic is a Python library for data validation and settings management that leverages Python type annotations. It provides a way to declare data models with typed fields and then validate, coerce, and parse raw data into those models, producing structured error information when validation fails.

At the core is the BaseModel class. Fields are defined with type hints, and when data is

Validation and customization are central features. Pydantic supports validators via the @validator decorator, allowing pre- and

Usage and ecosystem: Pydantic is widely used for API data validation and configuration management. It is the

History: Pydantic was created by Samuel Colvin and published to simplify runtime data validation in Python.

passed
to
a
model,
Pydantic
validates
the
input,
converts
values
to
the
declared
types,
applies
defaults,
and
constructs
a
model
instance.
If
validation
cannot
be
performed,
a
ValidationError
is
raised
detailing
the
fields
that
failed
and
why.
post-processing
logic.
It
handles
nested
models,
lists,
dictionaries,
unions,
and
optional
fields,
and
offers
features
such
as
field
aliases,
default
factories,
and
configurable
handling
of
extra
fields.
Serialization
is
also
supported,
with
methods
to
convert
models
back
to
plain
data
structures
or
JSON.
In
Pydantic
v1,
these
are
typically
dict()
and
json();
in
v2,
model_dump()
and
model_dump_json()
are
provided,
with
options
to
include
aliases
or
exclude
certain
fields.
foundation
for
request
and
response
models
in
several
web
frameworks
and
is
known
for
its
clear
error
reporting
and
strong
typing
discipline.
The
project
is
open-source
and
MIT-licensed,
maintained
by
a
community
of
contributors.
The
library
has
evolved
through
multiple
releases,
with
a
major
rewrite
in
Pydantic
v2
around
2023,
focusing
on
performance
improvements
and
API
refinements
while
keeping
backward-compatible
concepts.