Give AlbumentationsX a star on GitHub — it powers this leaderboard

Star on GitHub

pydantic

Data validation using Python type hints

Downloads: 0 (30 days)

Description

Pydantic Validation

CI Coverage pypi CondaForge downloads versions license Pydantic v2 llms.txt

Data validation using Python type hints.

Fast and extensible, Pydantic plays nicely with your linters/IDE/brain. Define how data should be in pure, canonical Python 3.9+; validate it with Pydantic.

Pydantic Logfire :fire:

We've recently launched Pydantic Logfire to help you monitor your applications. Learn more

Pydantic V1.10 vs. V2

Pydantic V2 is a ground-up rewrite that offers many new features, performance improvements, and some breaking changes compared to Pydantic V1.

If you're using Pydantic V1 you may want to look at the pydantic V1.10 Documentation or, 1.10.X-fixes git branch. Pydantic V2 also ships with the latest version of Pydantic V1 built in so that you can incrementally upgrade your code base and projects: from pydantic import v1 as pydantic_v1.

Help

See documentation for more details.

Installation

Install using pip install -U pydantic or conda install pydantic -c conda-forge. For more installation options to make Pydantic even faster, see the Install section in the documentation.

A Simple Example

from datetime import datetime
from typing import Optional
from pydantic import BaseModel

class User(BaseModel):
    id: int
    name: str = 'John Doe'
    signup_ts: Optional[datetime] = None
    friends: list[int] = []

external_data = {'id': '123', 'signup_ts': '2017-06-01 12:22', 'friends': [1, '2', b'3']}
user = User(**external_data)
print(user)
#> User id=123 name='John Doe' signup_ts=datetime.datetime(2017, 6, 1, 12, 22) friends=[1, 2, 3]
print(user.id)
#> 123

Contributing

For guidance on setting up a development environment and how to make a contribution to Pydantic, see Contributing to Pydantic.

Reporting a Security Vulnerability

See our security policy.

Changelog

<!-- markdownlint-disable no-bare-urls --> <!-- markdownlint-disable descriptive-link-text --> <!-- markdownlint-disable-next-line first-line-heading -->

v2.12.5 (2025-11-26)

GitHub release

This is the fifth 2.12 patch release, addressing an issue with the MISSING sentinel and providing several documentation improvements.

The next 2.13 minor release will be published in a couple weeks, and will include a new polymorphic serialization feature addressing the remaining unexpected changes to the serialize as any behavior.

  • Fix pickle error when using model_construct() on a model with MISSING as a default value by @ornariece in #12522.
  • Several updates to the documentation by @Viicos.

v2.12.4 (2025-11-05)

GitHub release

This is the fourth 2.12 patch release, fixing more regressions, and reverting a change in the build() method of the AnyUrl and Dsn types.

This patch release also fixes an issue with the serialization of IP address types, when serialize_as_any is used. The next patch release will try to address the remaining issues with serialize as any behavior by introducing a new polymorphic serialization feature, that should be used in most cases in place of serialize as any.

  • Fix issue with forward references in parent TypedDict classes by @Viicos in #12427.

    This issue is only relevant on Python 3.14 and greater.

  • Exclude fields with exclude_if from JSON Schema required fields by @Viicos in #12430

  • Revert URL percent-encoding of credentials in the build() method of the AnyUrl and Dsn types by @davidhewitt in pydantic-core#1833.

    This was initially considered as a bugfix, but caused regressions and as such was fully reverted. The next release will include an opt-in option to percent-encode components of the URL.

  • Add type inference for IP address types by @davidhewitt in pydantic-core#1868.

    The 2.12 changes to the serialize_as_any behavior made it so that IP address types could not properly serialize to JSON.

  • Avoid getting default values from defaultdict by @davidhewitt in pydantic-core#1853.

    This fixes a subtle regression in the validation behavior of the collections.defaultdict type.

  • Fix issue with field serializers on nested typed dictionaries by @davidhewitt in pydantic-core#1879.

  • Add more pydantic-core builds for the three-threaded version of Python 3.14 by @davidhewitt in pydantic-core#1864.

v2.12.3 (2025-10-17)

GitHub release

What's Changed

This is the third 2.12 patch release, fixing issues related to the FieldInfo class, and reverting a change to the supported after model validator function signatures.

  • Raise a warning when an invalid after model validator function signature is raised by @Viicos in #12414. Starting in 2.12.0, using class methods for after model validators raised an error, but the error wasn't raised concistently. We decided to emit a deprecation warning instead.
  • Add FieldInfo.asdict() method, improve documentation around FieldInfo by @Viicos in #12411. This also add back support for mutations on FieldInfo classes, that are reused as Annotated metadata. However, note that this is still not a supported pattern. Instead, please refer to the added example in the documentation.

The blog post section on changes was also updated to document the changes related to serialize_as_any.

v2.12.2 (2025-10-14)

GitHub release

What's Changed

Fixes

  • Release a new pydantic-core version, as a corrupted CPython 3.10 manylinux2014_aarch64 wheel got uploaded (pydantic-core#1843).
  • Fix issue with recursive generic models with a parent model class by @Viicos in #12398

v2.12.1 (2025-10-13)

GitHub release

What's Changed

This is the first 2.12 patch release, addressing most (but not all yet) regressions from the initial 2.12.0 release.

Fixes