Data validation using Python type hints
Project description
Pydantic Validation
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
v2.12.3 (2025-10-17)
What's Changed
This is the third 2.13 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 aroundFieldInfoby @Viicos in #12411. This also add back support for mutations onFieldInfoclasses, that are reused asAnnotatedmetadata. 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.
Fixes
- Release a new
pydantic-coreversion, as a corrupted CPython 3.10manylinux2014_aarch64wheel got uploaded (pydantic-core#1843). - Fix issue with recursive generic models with a parent model class by @Viicos in #12398
v2.12.2 (2025-10-14)
What's Changed
Fixes
- Release a new
pydantic-coreversion, as a corrupted CPython 3.10manylinux2014_aarch64wheel 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)
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
- Do not evaluate annotations when inspecting validators and serializers by @Viicos in #12355
- Make sure
Noneis converted asNoneTypein Python 3.14 by @Viicos in #12370 - Backport V1 runtime warning when using Python 3.14 by @Viicos in #12367
- Fix error message for invalid validator signatures by @Viicos in #12366
- Populate field name in
ValidationInfofor validation of default value by @Viicos in pydantic-core#1826 - Encode credentials in
MultiHostUrlbuilder by @willswire in pydantic-core#1829 - Respect field serializers when using
serialize_as_anyserialization flag by @davidhewitt in pydantic-core#1829 - Fix various
RootModelserialization issues by @davidhewitt in pydantic-core#1836
New Contributors
- @willswire made their first contribution in pydantic-core#1829
v2.12.0 (2025-10-07)
What's Changed
This is the final 2.12 release. It features the work of 20 external contributors and provides useful new features, along with initial Python 3.14 support. Several minor changes (considered non-breaking changes according to our versioning policy) are also included in this release. Make sure to look into them before upgrading.
Note that Pydantic V1 is not compatible with Python 3.14 and greater.
Changes (see the alpha and beta releases for additional changes since 2.11):
Packaging
New Features
- Add
extraparameter to the validate functions by @anvilpete in #12233 - Add
exclude_computed_fieldsserialization option by @Viicos in #12334 - Add
preverse_empty_pathURL options by @Viicos in #12336 - Add
union_formatparameter to JSON Schema generation by @Viicos in #12147 - Add
__qualname__parameter forcreate_modelby @Atry in #12001
Fixes
- Do not try to infer name from lambda definitions in pipelines API by @Viicos in #12289
- Use proper namespace for functions in
TypeAdapterby @Viicos in #12324 - Use
Anyfor context type annotation inTypeAdapterby @inducer in #12279 - Expose
FieldInfoinpydantic.fields.__all__by @Viicos in #12339 - Respect
validation_aliasin@validate_callby @Viicos in #12340 - Use
Anyas context annotation in plugin API by @Viicos in #12341 - Use proper
stacklevelin warnings when possible by @Viicos in #12342
New Contributors
- @anvilpete made their first contribution in #12233
- @JonathanWindell made their first contribution in #12327
- @inducer made their first contribution in #12279
- @Atry made their first contribution in #12001
v2.12.0b1 (2025-10-03)
This is the first beta release of the upcoming 2.12 release.
What's Changed
Packaging
New Features
- Add support for
exclude_ifat the field level by @andresliszt in #12141 - Add
ValidateAsannotation helper by @Viicos in #11942 - Add configuration options for validation and JSON serialization of temporal types by @ollz272 in #12068
- Add support for PEP 728 by @Viicos in #12179
- Add field name in serialization error by @NicolasPllr1 in pydantic-core#1799
- Add option to preserve empty URL paths by @davidhewitt in pydantic-core#1789
Changes
- Raise error if an incompatible
pydantic-coreversion is installed by @Viicos in #12196 - Remove runtime warning for experimental features by @Viicos in #12265
- Warn if registering virtual subclasses on Pydantic models by @Viicos in #11669
Fixes
- Fix
__getattr__()behavior on Pydantic models when a property raised anAttributeErrorand extra values are present by @raspuchin in #12106 - Add test to prevent regression with Pydantic models used as annotated metadata by @Viicos in #12133
- Allow to use property setters on Pydantic dataclasses with
validate_assignmentset by @Viicos in #12173 - Fix mypy v2 plugin for upcoming mypy release by @cdce8p in #12209
- Respect custom title in functions JSON Schema by @Viicos in #11892
- Fix
ImportStringJSON serialization for objects with anameattribute by @chr1sj0nes in #12219 - Do not error on fields overridden by methods in the mypy plugin by @Viicos in #12290
New Contributors
- @raspuchin made their first contribution in #12106
- @chr1sj0nes made their first contribution in #12219
v2.12.0a1 (2025-07-26)
This is the first alpha release of the upcoming 2.12 release, which adds initial support for Python 3.14.
What's Changed
New Features
- Add
__pydantic_on_complete__()hook that is called once model is fully ready to be used by @DouweM in #11762 - Add initial support for Python 3.14 by @Viicos in #11991
- Add regex patterns to JSON schema for
Decimaltype by @Dima-Bulavenko in #11987 - Add support for
docattribute on dataclass fields by @Viicos in #12077 - Add experimental
MISSINGsentinel by @Viicos in #11883
Changes
- Allow config and bases to be specified together in
create_model()by @Viicos in #11714 - Move some field logic out of the
GenerateSchemaclass by @Viicos in #11733 - Always make use of
inspect.getsourcelines()for docstring extraction on Python 3.13 and greater by @Viicos in #11829 - Only support the latest Mypy version by @Viicos in #11832
- Do not implicitly convert after model validators to class methods by @Viicos in #11957
- Refactor
FieldInfocreation implementation by @Viicos in #11898 - Make
Secretcovariant by @bluenote10 in #12008 - Emit warning when field-specific metadata is used in invalid contexts by @Viicos in #12028
Fixes
- Properly fetch plain serializer function when serializing default value in JSON Schema by @Viicos in #11721
- Remove generics cache workaround by @Viicos in #11755
- Remove coercion of decimal constraints by @Viicos in #11772
- Fix crash when expanding root type in the mypy plugin by @Viicos in #11735
- Only mark model as complete once all fields are complete by @DouweM in #11759
- Do not provide
field_namein validator core schemas by @DouweM in #11761 - Fix issue with recursive generic models by @Viicos in #11775
- Fix qualified name comparison of private attributes during namespace inspection by @karta9821 in #11803
- Make sure Pydantic dataclasses with slots and
validate_assignmentcan be unpickled by @Viicos in #11769 - Traverse
function-beforeschemas during schema gathering by @Viicos in #11801 - Fix check for stdlib dataclasses by @Viicos in #11822
- Check if
FieldInfois complete after applying type variable map by @Viicos in #11855 - Do not delete mock validator/serializer in
model_rebuild()by @Viicos in #11890 - Rebuild dataclass fields before schema generation by @Viicos in #11949
- Always store the original field assignment on
FieldInfoby @Viicos in #11946 - Do not use deprecated methods as default field values by @Viicos in #11914
- Allow callable discriminator to be applied on PEP 695 type aliases by @Viicos in #11941
- Suppress core schema generation warning when using
SkipValidationby @ygsh0816 in #12002 - Do not emit typechecking error for invalid
Field()default withvalidate_defaultset toTrueby @Viicos in #11988 - Refactor logic to support Pydantic's
Field()function in dataclasses by @Viicos in #12051
Packaging
- Update project metadata to use PEP 639 by @Viicos in #11694
- Bump
mkdocs-llmstxtto v0.2.0 by @Viicos in #11725 - Bump
pydantic-coreto v2.35.1 by @Viicos in #11963 - Bump dawidd6/action-download-artifact from 10 to 11 by @dependabot[bot] in #12033
- Bump astral-sh/setup-uv from 5 to 6 by @dependabot[bot] in #11826
- Update mypy to 1.17.0 by @Viicos in #12076
New Contributors
- @parth-paradkar made their first contribution in #11695
- @dqkqd made their first contribution in #11739
- @fhightower made their first contribution in #11722
- @gbaian10 made their first contribution in #11766
- @DouweM made their first contribution in #11759
- @bowenliang123 made their first contribution in #11719
- @rawwar made their first contribution in #11799
- @karta9821 made their first contribution in #11803
- @jinnovation made their first contribution in #11834
- @zmievsa made their first contribution in #11861
- @Otto-AA made their first contribution in #11860
- @ygsh0816 made their first contribution in #12002
- @lukland made their first contribution in #12015
- @Dima-Bulavenko made their first contribution in #11987
- @GSemikozov made their first contribution in #12050
- @hannah-heywa made their first contribution in #12082
v2.11.7 (2025-06-14)
What's Changed
Fixes
v2.11.6 (2025-06-13)
What's Changed
Fixes
- Rebuild dataclass fields before schema generation by @Viicos in #11949
- Always store the original field assignment on
FieldInfoby @Viicos in #11946
v2.11.5 (2025-05-22)
What's Changed
Fixes
- Check if
FieldInfois complete after applying type variable map by @Viicos in #11855 - Do not delete mock validator/serializer in
model_rebuild()by @Viicos in #11890 - Do not duplicate metadata on model rebuild by @Viicos in #11902
v2.11.4 (2025-04-29)
What's Changed
Packaging
Changes
- Allow config and bases to be specified together in
create_model()by @Viicos in #11714. This change was backported as it was previously possible (although not meant to be supported) to providemodel_configas a field, which would make it possible to provide both configuration and bases.
Fixes
- Remove generics cache workaround by @Viicos in #11755
- Remove coercion of decimal constraints by @Viicos in #11772
- Fix crash when expanding root type in the mypy plugin by @Viicos in #11735
- Fix issue with recursive generic models by @Viicos in #11775
- Traverse
function-beforeschemas during schema gathering by @Viicos in #11801
v2.11.3 (2025-04-08)
What's Changed
Packaging
Fixes
v2.11.2 (2025-04-03)
What's Changed
Fixes
- Bump
pydantic-coreto v2.33.1 by @Viicos in #11678 - Make sure
__pydantic_private__exists before setting private attributes by @Viicos in #11666 - Do not override
FieldInfo._completewhen using field from parent class by @Viicos in #11668 - Provide the available definitions when applying discriminated unions by @Viicos in #11670
- Do not expand root type in the mypy plugin for variables by @Viicos in #11676
- Mention the attribute name in model fields deprecation message by @Viicos in #11674
- Properly validate parameterized mappings by @Viicos in #11658
v2.11.1 (2025-03-28)
What's Changed
Fixes
- Do not override
'definitions-ref'schemas containing serialization schemas or metadata by @Viicos in #11644
v2.11.0 (2025-03-27)
What's Changed
Pydantic v2.11 is a version strongly focused on build time performance of Pydantic models (and core schema generation in general). See the blog post for more details.
Packaging
New Features
- Add
encoded_string()method to the URL types by @YassinNouh21 in #11580 - Add support for
defer_buildwith@validate_calldecorator by @Viicos in #11584 - Allow
@with_configdecorator to be used with keyword arguments by @Viicos in #11608 - Simplify customization of default value inclusion in JSON Schema generation by @Viicos in #11634
- Add
generate_arguments_schema()function by @Viicos in #11572
Fixes
- Allow generic typed dictionaries to be used for unpacked variadic keyword parameters by @Viicos in #11571
- Fix runtime error when computing model string representation involving cached properties and self-referenced models by @Viicos in #11579
- Preserve other steps when using the ellipsis in the pipeline API by @Viicos in #11626
- Fix deferred discriminator application logic by @Viicos in #11591
New Contributors
v2.11.0b2 (2025-03-17)
What's Changed
Packaging
New Features
Fixes
New Contributors
v2.11.0b1 (2025-03-06)
What's Changed
Packaging
- Add a
check_pydantic_core_version()function by @Viicos in https://github.com/pydantic/pydantic/pull/11324 - Remove
greenletdevelopment dependency by @Viicos in https://github.com/pydantic/pydantic/pull/11351 - Use the
typing-inspectionlibrary by @Viicos in https://github.com/pydantic/pydantic/pull/11479 - Bump
pydantic-coretov2.31.1by @sydney-runkle in https://github.com/pydantic/pydantic/pull/11526
New Features
- Support unsubstituted type variables with both a default and a bound or constraints by @FyZzyss in https://github.com/pydantic/pydantic/pull/10789
- Add a
default_factory_takes_validated_dataproperty toFieldInfoby @Viicos in https://github.com/pydantic/pydantic/pull/11034 - Raise a better error when a generic alias is used inside
type[]by @Viicos in https://github.com/pydantic/pydantic/pull/11088 - Properly support PEP 695 generics syntax by @Viicos in https://github.com/pydantic/pydantic/pull/11189
- Properly support type variable defaults by @Viicos in https://github.com/pydantic/pydantic/pull/11332
- Add support for validating v6, v7, v8 UUIDs by @astei in https://github.com/pydantic/pydantic/pull/11436
- Improve alias configuration APIs by @sydney-runkle in https://github.com/pydantic/pydantic/pull/11468
Changes
- Rework
create_modelfield definitions format by @Viicos in https://github.com/pydantic/pydantic/pull/11032 - Raise a deprecation warning when a field is annotated as final with a default value by @Viicos in https://github.com/pydantic/pydantic/pull/11168
- Deprecate accessing
model_fieldsandmodel_computed_fieldson instances by @Viicos in https://github.com/pydantic/pydantic/pull/11169 - Breaking Change: Move core schema generation logic for path types inside the
GenerateSchemaclass by @sydney-runkle in https://github.com/pydantic/pydantic/pull/10846 - Remove Python 3.8 Support by @sydney-runkle in https://github.com/pydantic/pydantic/pull/11258
- Optimize calls to
get_type_refby @Viicos in https://github.com/pydantic/pydantic/pull/10863 - Disable
pydantic-corecore schema validation by @sydney-runkle in https://github.com/pydantic/pydantic/pull/11271
Performance
- Only evaluate
FieldInfoannotations if required during schema building by @Viicos in https://github.com/pydantic/pydantic/pull/10769 - Improve
__setattr__performance of Pydantic models by caching setter functions by @MarkusSintonen in https://github.com/pydantic/pydantic/pull/10868 - Improve annotation application performance by @Viicos in https://github.com/pydantic/pydantic/pull/11186
- Improve performance of
_typing_extramodule by @Viicos in https://github.com/pydantic/pydantic/pull/11255 - Refactor and optimize schema cleaning logic by @Viicos in https://github.com/pydantic/pydantic/pull/11244
- Create a single dictionary when creating a
CoreConfiginstance by @sydney-runkle in https://github.com/pydantic/pydantic/pull/11384 - Bump
pydantic-coreand thus useSchemaValidatorandSchemaSerializercaching by @sydney-runkle in https://github.com/pydantic/pydantic/pull/11402 - Reuse cached core schemas for parametrized generic Pydantic models by @MarkusSintonen in https://github.com/pydantic/pydantic/pull/11434
Fixes
- Improve
TypeAdapterinstance repr by @sydney-runkle in https://github.com/pydantic/pydantic/pull/10872 - Use the correct frame when instantiating a parametrized
TypeAdapterby @Viicos in https://github.com/pydantic/pydantic/pull/10893 - Infer final fields with a default value as class variables in the mypy plugin by @Viicos in https://github.com/pydantic/pydantic/pull/11121
- Recursively unpack
Literalvalues if using PEP 695 type aliases by @Viicos in https://github.com/pydantic/pydantic/pull/11114 - Override
__subclasscheck__onModelMetaclassto avoid memory leak and performance issues by @Viicos in https://github.com/pydantic/pydantic/pull/11116 - Remove unused
_extract_get_pydantic_json_schema()parameter by @Viicos in https://github.com/pydantic/pydantic/pull/11155 - Improve discriminated union error message for invalid union variants by @Viicos in https://github.com/pydantic/pydantic/pull/11161
- Unpack PEP 695 type aliases if using the
Annotatedform by @Viicos in https://github.com/pydantic/pydantic/pull/11109 - Add missing stacklevel in
deprecated_instance_propertywarning by @Viicos in https://github.com/pydantic/pydantic/pull/11200 - Copy
WithJsonSchemaschema to avoid sharing mutated data by @thejcannon in https://github.com/pydantic/pydantic/pull/11014 - Do not cache parametrized models when in the process of parametrizing another model by @Viicos in https://github.com/pydantic/pydantic/pull/10704
- Add discriminated union related metadata entries to the
CoreMetadatadefinition by @Viicos in https://github.com/pydantic/pydantic/pull/11216 - Consolidate schema definitions logic in the
_Definitionsclass by @Viicos in https://github.com/pydantic/pydantic/pull/11208 - Support initializing root model fields with values of the
roottype in the mypy plugin by @Viicos in https://github.com/pydantic/pydantic/pull/11212 - Fix various issues with dataclasses and
use_attribute_docstringsby @Viicos in https://github.com/pydantic/pydantic/pull/11246 - Only compute normalized decimal places if necessary in
decimal_places_validatorby @misrasaurabh1 in https://github.com/pydantic/pydantic/pull/11281 - Add support for
validation_aliasin the mypy plugin by @Viicos in https://github.com/pydantic/pydantic/pull/11295 - Fix JSON Schema reference collection with
"examples"keys by @Viicos in https://github.com/pydantic/pydantic/pull/11305 - Do not transform model serializer functions as class methods in the mypy plugin by @Viicos in https://github.com/pydantic/pydantic/pull/11298
- Simplify
GenerateJsonSchema.literal_schema()implementation by @misrasaurabh1 in https://github.com/pydantic/pydantic/pull/11321 - Add additional allowed schemes for
ClickHouseDsnby @Maze21127 in https://github.com/pydantic/pydantic/pull/11319 - Coerce decimal constraints to
Decimalinstances by @Viicos in https://github.com/pydantic/pydantic/pull/11350 - Use the correct JSON Schema mode when handling function schemas by @Viicos in https://github.com/pydantic/pydantic/pull/11367
- Improve exception message when encountering recursion errors during type evaluation by @Viicos in https://github.com/pydantic/pydantic/pull/11356
- Always include
additionalProperties: Truefor arbitrary dictionary schemas by @austinyu in https://github.com/pydantic/pydantic/pull/11392 - Expose
fallbackparameter in serialization methods by @Viicos in https://github.com/pydantic/pydantic/pull/11398 - Fix path serialization behavior by @sydney-runkle in https://github.com/pydantic/pydantic/pull/11416
- Do not reuse validators and serializers during model rebuild by @Viicos in https://github.com/pydantic/pydantic/pull/11429
- Collect model fields when rebuilding a model by @Viicos in https://github.com/pydantic/pydantic/pull/11388
- Allow cached properties to be altered on frozen models by @Viicos in https://github.com/pydantic/pydantic/pull/11432
- Fix tuple serialization for
Sequencetypes by @sydney-runkle in https://github.com/pydantic/pydantic/pull/11435 - Fix: do not check for
__get_validators__on classes where__get_pydantic_core_schema__is also defined by @tlambert03 in https://github.com/pydantic/pydantic/pull/11444 - Allow callable instances to be used as serializers by @Viicos in https://github.com/pydantic/pydantic/pull/11451
- Improve error thrown when overriding field with a property by @sydney-runkle in https://github.com/pydantic/pydantic/pull/11459
- Fix JSON Schema generation with referenceable core schemas holding JSON metadata by @Viicos in https://github.com/pydantic/pydantic/pull/11475
- Support strict specification on union member types by @sydney-runkle in https://github.com/pydantic/pydantic/pull/11481
- Implicitly set
validate_by_nametoTruewhenvalidate_by_aliasisFalseby @sydney-runkle in https://github.com/pydantic/pydantic/pull/11503 - Change type of
Anywhen synthesizingBaseSettings.__init__signature in the mypy plugin by @Viicos in https://github.com/pydantic/pydantic/pull/11497 - Support type variable defaults referencing other type variables by @Viicos in https://github.com/pydantic/pydantic/pull/11520
- Fix
ValueErroron year zero by @davidhewitt in https://github.com/pydantic/pydantic-core/pull/1583 dataclassInitVarshouldn't be required on serialization by @sydney-runkle in https://github.com/pydantic/pydantic-core/pull/1602
New Contributors
- @FyZzyss made their first contribution in https://github.com/pydantic/pydantic/pull/10789
- @tamird made their first contribution in https://github.com/pydantic/pydantic/pull/10948
- @felixxm made their first contribution in https://github.com/pydantic/pydantic/pull/11077
- @alexprabhat99 made their first contribution in https://github.com/pydantic/pydantic/pull/11082
- @Kharianne made their first contribution in https://github.com/pydantic/pydantic/pull/11111
- @mdaffad made their first contribution in https://github.com/pydantic/pydantic/pull/11177
- @thejcannon made their first contribution in https://github.com/pydantic/pydantic/pull/11014
- @thomasfrimannkoren made their first contribution in https://github.com/pydantic/pydantic/pull/11251
- @usernameMAI made their first contribution in https://github.com/pydantic/pydantic/pull/11275
- @ananiavito made their first contribution in https://github.com/pydantic/pydantic/pull/11302
- @pawamoy made their first contribution in https://github.com/pydantic/pydantic/pull/11311
- @Maze21127 made their first contribution in https://github.com/pydantic/pydantic/pull/11319
- @kauabh made their first contribution in https://github.com/pydantic/pydantic/pull/11369
- @jaceklaskowski made their first contribution in https://github.com/pydantic/pydantic/pull/11353
- @tmpbeing made their first contribution in https://github.com/pydantic/pydantic/pull/11375
- @petyosi made their first contribution in https://github.com/pydantic/pydantic/pull/11405
- @austinyu made their first contribution in https://github.com/pydantic/pydantic/pull/11392
- @mikeedjones made their first contribution in https://github.com/pydantic/pydantic/pull/11402
- @astei made their first contribution in https://github.com/pydantic/pydantic/pull/11436
- @dsayling made their first contribution in https://github.com/pydantic/pydantic/pull/11522
- @sobolevn made their first contribution in https://github.com/pydantic/pydantic-core/pull/1645
v2.11.0a2 (2025-02-10)
What's Changed
Pydantic v2.11 is a version strongly focused on build time performance of Pydantic models (and core schema generation in general). This is another early alpha release, meant to collect early feedback from users having issues with core schema builds.
Packaging
- Bump
rufffrom 0.9.2 to 0.9.5 by @Viicos in #11407 - Bump
pydantic-coreto v2.29.0 by @mikeedjones in #11402 - Use locally-built rust with symbols & pgo by @davidhewitt in #11403
Performance
- Create a single dictionary when creating a
CoreConfiginstance by @sydney-runkle in #11384
Fixes
- Use the correct JSON Schema mode when handling function schemas by @Viicos in #11367
- Fix JSON Schema reference logic with
exampleskeys by @Viicos in #11366 - Improve exception message when encountering recursion errors during type evaluation by @Viicos in #11356
- Always include
additionalProperties: Truefor arbitrary dictionary schemas by @austinyu in #11392 - Expose
fallbackparameter in serialization methods by @Viicos in #11398 - Fix path serialization behavior by @sydney-runkle in #11416
New Contributors
- @kauabh made their first contribution in #11369
- @jaceklaskowski made their first contribution in #11353
- @tmpbeing made their first contribution in #11375
- @petyosi made their first contribution in #11405
- @austinyu made their first contribution in #11392
- @mikeedjones made their first contribution in #11402
v2.11.0a1 (2025-01-30)
What's Changed
Pydantic v2.11 is a version strongly focused on build time performance of Pydantic models (and core schema generation in general). This is an early alpha release, meant to collect early feedback from users having issues with core schema builds.
Packaging
- Bump dawidd6/action-download-artifact from 6 to 7 by @dependabot in #11018
- Re-enable memray related tests on Python 3.12+ by @Viicos in #11191
- Bump astral-sh/setup-uv to 5 by @dependabot in #11205
- Bump
ruffto v0.9.0 by @sydney-runkle in #11254 - Regular
uv.lockdeps update by @sydney-runkle in #11333 - Add a
check_pydantic_core_version()function by @Viicos in #11324 - Remove
greenletdevelopment dependency by @Viicos in #11351 - Bump
pydantic-coreto v2.28.0 by @Viicos in #11364
New Features
- Support unsubstituted type variables with both a default and a bound or constraints by @FyZzyss in #10789
- Add a
default_factory_takes_validated_dataproperty toFieldInfoby @Viicos in #11034 - Raise a better error when a generic alias is used inside
type[]by @Viicos in #11088 - Properly support PEP 695 generics syntax by @Viicos in #11189
- Properly support type variable defaults by @Viicos in #11332
Changes
- Rework
create_modelfield definitions format by @Viicos in #11032 - Raise a deprecation warning when a field is annotated as final with a default value by @Viicos in #11168
- Deprecate accessing
model_fieldsandmodel_computed_fieldson instances by @Viicos in #11169 - Move core schema generation logic for path types inside the
GenerateSchemaclass by @sydney-runkle in #10846 - Move
dequeschema gen toGenerateSchemaclass by @sydney-runkle in #11239 - Move
Mappingschema gen toGenerateSchemato complete removal ofprepare_annotations_for_known_typeworkaround by @sydney-runkle in #11247 - Remove Python 3.8 Support by @sydney-runkle in #11258
- Disable
pydantic-corecore schema validation by @sydney-runkle in #11271
Performance
- Only evaluate
FieldInfoannotations if required during schema building by @Viicos in #10769 - Optimize calls to
get_type_refby @Viicos in #10863 - Improve
__setattr__performance of Pydantic models by caching setter functions by @MarkusSintonen in #10868 - Improve annotation application performance by @Viicos in #11186
- Improve performance of
_typing_extramodule by @Viicos in #11255 - Refactor and optimize schema cleaning logic by @Viicos and @MarkusSintonen in #11244
Fixes
- Add validation tests for
_internal/_validators.pyby @tkasuz in #10763 - Improve
TypeAdapterinstance repr by @sydney-runkle in #10872 - Revert "ci: use locally built pydantic-core with debug symbols by @sydney-runkle in #10942
- Re-enable all FastAPI tests by @tamird in #10948
- Fix typo in HISTORY.md. by @felixxm in #11077
- Infer final fields with a default value as class variables in the mypy plugin by @Viicos in #11121
- Recursively unpack
Literalvalues if using PEP 695 type aliases by @Viicos in #11114 - Override
__subclasscheck__onModelMetaclassto avoid memory leak and performance issues by @Viicos in #11116 - Remove unused
_extract_get_pydantic_json_schema()parameter by @Viicos in #11155 - Add FastAPI and SQLModel to third-party tests by @sydney-runkle in #11044
- Fix conditional expressions syntax for third-party tests by @Viicos in #11162
- Move FastAPI tests to third-party workflow by @Viicos in #11164
- Improve discriminated union error message for invalid union variants by @Viicos in #11161
- Unpack PEP 695 type aliases if using the
Annotatedform by @Viicos in #11109 - Include
openapi-python-clientcheck in issue creation for third-party failures, usemainbranch by @sydney-runkle in #11182 - Add pandera third-party tests by @Viicos in #11193
- Add ODMantic third-party tests by @sydney-runkle in #11197
- Add missing stacklevel in
deprecated_instance_propertywarning by @Viicos in #11200 - Copy
WithJsonSchemaschema to avoid sharing mutated data by @thejcannon in #11014 - Do not cache parametrized models when in the process of parametrizing another model by @Viicos in #10704
- Re-enable Beanie third-party tests by @Viicos in #11214
- Add discriminated union related metadata entries to the
CoreMetadatadefinition by @Viicos in #11216 - Consolidate schema definitions logic in the
_Definitionsclass by @Viicos in #11208 - Support initializing root model fields with values of the
roottype in the mypy plugin by @Viicos in #11212 - Fix various issues with dataclasses and
use_attribute_docstringsby @Viicos in #11246 - Only compute normalized decimal places if necessary in
decimal_places_validatorby @misrasaurabh1 in #11281 - Fix two misplaced sentences in validation errors documentation by @ananiavito in #11302
- Fix mkdocstrings inventory example in documentation by @pawamoy in #11311
- Add support for
validation_aliasin the mypy plugin by @Viicos in #11295 - Do not transform model serializer functions as class methods in the mypy plugin by @Viicos in #11298
- Simplify
GenerateJsonSchema.literal_schema()implementation by @misrasaurabh1 in #11321 - Add additional allowed schemes for
ClickHouseDsnby @Maze21127 in #11319 - Coerce decimal constraints to
Decimalinstances by @Viicos in #11350 - Fix
ValueErroron year zero by @davidhewitt in pydantic-core#1583
New Contributors
- @FyZzyss made their first contribution in #10789
- @tamird made their first contribution in #10948
- @felixxm made their first contribution in #11077
- @alexprabhat99 made their first contribution in #11082
- @Kharianne made their first contribution in #11111
- @mdaffad made their first contribution in #11177
- @thejcannon made their first contribution in #11014
- @thomasfrimannkoren made their first contribution in #11251
- @usernameMAI made their first contribution in #11275
- @ananiavito made their first contribution in #11302
- @pawamoy made their first contribution in #11311
- @Maze21127 made their first contribution in #11319
v2.10.6 (2025-01-23)
What's Changed
Fixes
- Fix JSON Schema reference collection with
'examples'keys by @Viicos in #11325 - Fix url python serialization by @sydney-runkle in #11331
v2.10.5 (2025-01-08)
What's Changed
Fixes
- Remove custom MRO implementation of Pydantic models by @Viicos in #11184
- Fix URL serialization for unions by @sydney-runkle in #11233
v2.10.4 (2024-12-18)
What's Changed
Packaging
- Bump
pydantic-coreto v2.27.2 by @davidhewitt in #11138
Fixes
- Fix for comparison of
AnyUrlobjects by @alexprabhat99 in #11082 - Properly fetch PEP 695 type params for functions, do not fetch annotations from signature by @Viicos in #11093
- Include JSON Schema input core schema in function schemas by @Viicos in #11085
- Add
lento_BaseUrlto avoid TypeError by @Kharianne in #11111 - Make sure the type reference is removed from the seen references by @Viicos in #11143
New Contributors
- @FyZzyss made their first contribution in #10789
- @tamird made their first contribution in #10948
- @felixxm made their first contribution in #11077
- @alexprabhat99 made their first contribution in #11082
- @Kharianne made their first contribution in #11111
v2.10.3 (2024-12-03)
What's Changed
Fixes
- Set fields when
defer_buildis set on Pydantic dataclasses by @Viicos in #10984 - Do not resolve the JSON Schema reference for
dictcore schema keys by @Viicos in #10989 - Use the globals of the function when evaluating the return type for
PlainSerializerandWrapSerializerfunctions by @Viicos in #11008 - Fix host required enforcement for urls to be compatible with v2.9 behavior by @sydney-runkle in #11027
- Add a
default_factory_takes_validated_dataproperty toFieldInfoby @Viicos in #11034 - Fix url json schema in
serializationmode by @sydney-runkle in #11035
v2.10.2 (2024-11-25)
What's Changed
Fixes
- Only evaluate FieldInfo annotations if required during schema building by @Viicos in #10769
- Do not evaluate annotations for private fields by @Viicos in #10962
- Support serialization as any for
Secrettypes andUrltypes by @sydney-runkle in #10947 - Fix type hint of
Field.defaultto be compatible with Python 3.8 and 3.9 by @Viicos in #10972 - Add hashing support for URL types by @sydney-runkle in #10975
- Hide
BaseModel.__replace__definition from type checkers by @Viicos in #10979
v2.10.1 (2024-11-21)
What's Changed
Packaging
- Bump
pydantic-coreversion tov2.27.1by @sydney-runkle in #10938
Fixes
- Use the correct frame when instantiating a parametrized
TypeAdapterby @Viicos in #10893 - Relax check for validated data in
default_factoryutils by @sydney-runkle in #10909 - Fix type checking issue with
model_fieldsandmodel_computed_fieldsby @sydney-runkle in #10911 - Use the parent configuration during schema generation for stdlib
dataclasses by @sydney-runkle in #10928 - Use the
globalsof the function when evaluating the return type of serializers andcomputed_fields by @Viicos in #10929 - Fix URL constraint application by @sydney-runkle in #10922
- Fix URL equality with different validation methods by @sydney-runkle in #10934
- Fix JSON schema title when specified as
''by @sydney-runkle in #10936 - Fix
pythonmode serialization forcomplexinference by @sydney-runkle in pydantic-core#1549
New Contributors
v2.10.0 (2024-11-20)
The code released in v2.10.0 is practically identical to that of v2.10.0b2.
See the v2.10 release blog post for the highlights!
What's Changed
Packaging
- Bump
pydantic-coretov2.27.0by @sydney-runkle in #10825 - Replaced pdm with uv by @frfahim in #10727
New Features
- Support
fractions.Fractionby @sydney-runkle in #10318 - Support
Hashablefor json validation by @sydney-runkle in #10324 - Add a
SocketPathtype forlinuxsystems by @theunkn0wn1 in #10378 - Allow arbitrary refs in JSON schema
examplesby @sydney-runkle in #10417 - Support
defer_buildfor Pydantic dataclasses by @Viicos in #10313 - Adding v1 / v2 incompatibility warning for nested v1 model by @sydney-runkle in #10431
- Add support for unpacked
TypedDictto type hint variadic keyword arguments with@validate_callby @Viicos in #10416 - Support compiled patterns in
protected_namespacesby @sydney-runkle in #10522 - Add support for
propertyNamesin JSON schema by @FlorianSW in #10478 - Adding
__replace__protocol for Python 3.13+ support by @sydney-runkle in #10596 - Expose public
sortmethod for JSON schema generation by @sydney-runkle in #10595 - Add runtime validation of
@validate_callcallable argument by @kc0506 in #10627 - Add
experimental_allow_partialsupport by @samuelcolvin in #10748 - Support default factories taking validated data as an argument by @Viicos in #10678
- Allow subclassing
ValidationErrorandPydanticCustomErrorby @Youssefares in pydantic/pydantic-core#1413 - Add
trailing-stringssupport toexperimental_allow_partialby @sydney-runkle in #10825 - Add
rebuild()method forTypeAdapterand simplifydefer_buildpatterns by @sydney-runkle in #10537 - Improve
TypeAdapterinstance repr by @sydney-runkle in #10872
Changes
- Don't allow customization of
SchemaGeneratoruntil interface is more stable by @sydney-runkle in #10303 - Cleanly
defer_buildonTypeAdapters, removing experimental flag by @sydney-runkle in #10329 - Fix
mroof generic subclass by @kc0506 in #10100 - Strip whitespaces on JSON Schema title generation by @sydney-runkle in #10404
- Use
b64decodeandb64encodeforBase64Bytestype by @sydney-runkle in #10486 - Relax protected namespace config default by @sydney-runkle in #10441
- Revalidate parametrized generics if instance's origin is subclass of OG class by @sydney-runkle in #10666
- Warn if configuration is specified on the
@dataclassdecorator and with the__pydantic_config__attribute by @sydney-runkle in #10406 - Recommend against using
Ellipsis(...) withFieldby @Viicos in #10661 - Migrate to subclassing instead of annotated approach for pydantic url types by @sydney-runkle in #10662
- Change JSON schema generation of
Literals andEnumsby @Viicos in #10692 - Simplify unions involving
AnyorNeverwhen replacing type variables by @Viicos in #10338 - Do not require padding when decoding
base64bytes by @bschoenmaeckers in pydantic/pydantic-core#1448 - Support dates all the way to 1BC by @changhc in pydantic/speedate#77
Performance
- Schema cleaning: skip unnecessary copies during schema walking by @Viicos in #10286
- Refactor namespace logic for annotations evaluation by @Viicos in #10530
- Improve email regexp on edge cases by @AlekseyLobanov in #10601
CoreMetadatarefactor with an emphasis on documentation, schema build time performance, and reducing complexity by @sydney-runkle in #10675
Fixes
- Remove guarding check on
computed_fieldwithfield_serializerby @nix010 in #10390 - Fix
Predicateissue inv2.9.0by @sydney-runkle in #10321 - Fixing
annotated-typesbound by @sydney-runkle in #10327 - Turn
tzdatainstall requirement into optionaltimezonedependency by @jakob-keller in #10331 - Use correct types namespace when building
namedtuplecore schemas by @Viicos in #10337 - Fix evaluation of stringified annotations during namespace inspection by @Viicos in #10347
- Fix
IncExtype alias definition by @Viicos in #10339 - Do not error when trying to evaluate annotations of private attributes by @Viicos in #10358
- Fix nested type statement by @kc0506 in #10369
- Improve typing of
ModelMetaclass.mroby @Viicos in #10372 - Fix class access of deprecated
computed_fields by @Viicos in #10391 - Make sure
inspect.iscoroutinefunctionworks on coroutines decorated with@validate_callby @MovisLi in #10374 - Fix
NameErrorwhen usingvalidate_callwith PEP 695 on a class by @kc0506 in #10380 - Fix
ZoneInfowith various invalid types by @sydney-runkle in #10408 - Fix
PydanticUserErroron emptymodel_configwith annotations by @cdwilson in #10412 - Fix variance issue in
_IncExtype alias, only allowTrueby @Viicos in #10414 - Fix serialization schema generation when using
PlainValidatorby @Viicos in #10427 - Fix schema generation error when serialization schema holds references by @Viicos in #10444
- Inline references if possible when generating schema for
json_schema_input_typeby @Viicos in #10439 - Fix recursive arguments in
Representationby @Viicos in #10480 - Fix representation for builtin function types by @kschwab in #10479
- Add python validators for decimal constraints (
max_digitsanddecimal_places) by @sydney-runkle in #10506 - Only fetch
__pydantic_core_schema__from the current class during schema generation by @Viicos in #10518 - Fix
stacklevelon deprecation warnings forBaseModelby @sydney-runkle in #10520 - Fix warning
stacklevelinBaseModel.__init__by @Viicos in #10526 - Improve error handling for in-evaluable refs for discriminator application by @sydney-runkle in #10440
- Change the signature of
ConfigWrapper.core_configto take the title directly by @Viicos in #10562 - Do not use the previous config from the stack for dataclasses without config by @Viicos in #10576
- Fix serialization for IP types with
mode='python'by @sydney-runkle in #10594 - Support constraint application for
Base64Etctypes by @sydney-runkle in #10584 - Fix
validate_callignoringFieldinAnnotatedby @kc0506 in #10610 - Raise an error when
Selfis invalid by @kc0506 in #10609 - Using
core_schema.InvalidSchemainstead of metadata injection + checks by @sydney-runkle in #10523 - Tweak type alias logic by @kc0506 in #10643
- Support usage of
typewithtyping.Selfand type aliases by @kc0506 in #10621 - Use overloads for
FieldandPrivateAttrfunctions by @Viicos in #10651 - Clean up the
mypyplugin implementation by @Viicos in #10669 - Properly check for
typing_extensionsvariant ofTypeAliasTypeby @Daraan in #10713 - Allow any mapping in
BaseModel.model_copy()by @Viicos in #10751 - Fix
isinstancebehavior for urls by @sydney-runkle in #10766 - Ensure
cached_propertycan be set on Pydantic models by @Viicos in #10774 - Fix equality checks for primitives in literals by @sydney-runkle in pydantic/pydantic-core#1459
- Properly enforce
host_requiredfor URLs by @Viicos in pydantic/pydantic-core#1488 - Fix when
coerce_numbers_to_strenabled and string has invalid Unicode character by @andrey-berenda in pydantic/pydantic-core#1515 - Fix serializing
complexvalues inEnums by @changhc in pydantic/pydantic-core#1524 - Refactor
_typing_extramodule by @Viicos in #10725 - Support intuitive equality for urls by @sydney-runkle in #10798
- Add
bytearraytoTypeAdapter.validate_jsonsignature by @samuelcolvin in #10802 - Ensure class access of method descriptors is performed when used as a default with
Fieldby @Viicos in #10816 - Fix circular import with
validate_callby @sydney-runkle in #10807 - Fix error when using type aliases referencing other type aliases by @Viicos in #10809
- Fix
IncExtype alias to be compatible with mypy by @Viicos in #10813 - Make
__signature__a lazy property, do not deepcopy defaults by @Viicos in #10818 - Make
__signature__lazy for dataclasses, too by @sydney-runkle in #10832 - Subclass all single host url classes from
AnyUrlto preserve behavior from v2.9 by @sydney-runkle in #10856
New Contributors
- @jakob-keller made their first contribution in #10331
- @MovisLi made their first contribution in #10374
- @joaopalmeiro made their first contribution in #10405
- @theunkn0wn1 made their first contribution in #10378
- @cdwilson made their first contribution in #10412
- @dlax made their first contribution in #10421
- @kschwab made their first contribution in #10479
- @santibreo made their first contribution in #10453
- @FlorianSW made their first contribution in #10478
- @tkasuz made their first contribution in #10555
- @AlekseyLobanov made their first contribution in #10601
- @NiclasvanEyk made their first contribution in #10667
- @mschoettle made their first contribution in #10677
- @Daraan made their first contribution in #10713
- @k4nar made their first contribution in #10736
- @UriyaHarpeness made their first contribution in #10740
- @frfahim made their first contribution in #10727
v2.10.0b2 (2024-11-13)
Pre-release, see the GitHub release for details.
v2.10.0b1 (2024-11-06)
Pre-release, see the GitHub release for details.
... see here for earlier changes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic-2.12.3.tar.gz.
File metadata
- Download URL: pydantic-2.12.3.tar.gz
- Upload date:
- Size: 819.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1da1c82b0fc140bb0103bc1441ffe062154c8d38491189751ee00fd8ca65ce74
|
|
| MD5 |
d01464f3a5256144116a8de55e2974b8
|
|
| BLAKE2b-256 |
f31e4f0a3233767010308f2fd6bd0814597e3f63f1dc98304a9112b8759df4ff
|
Provenance
The following attestation bundles were made for pydantic-2.12.3.tar.gz:
Publisher:
ci.yml on pydantic/pydantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic-2.12.3.tar.gz -
Subject digest:
1da1c82b0fc140bb0103bc1441ffe062154c8d38491189751ee00fd8ca65ce74 - Sigstore transparency entry: 619073001
- Sigstore integration time:
-
Permalink:
pydantic/pydantic@1a8850d101e67d2744ba8c6286e1172d7cd89d0b -
Branch / Tag:
refs/tags/v2.12.3 - Owner: https://github.com/pydantic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@1a8850d101e67d2744ba8c6286e1172d7cd89d0b -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydantic-2.12.3-py3-none-any.whl.
File metadata
- Download URL: pydantic-2.12.3-py3-none-any.whl
- Upload date:
- Size: 462.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6986454a854bc3bc6e5443e1369e06a3a456af9d339eda45510f517d9ea5c6bf
|
|
| MD5 |
30ccd2ead13779d453ab4dd292886d89
|
|
| BLAKE2b-256 |
a16b83661fa77dcefa195ad5f8cd9af3d1a7450fd57cc883ad04d65446ac2029
|
Provenance
The following attestation bundles were made for pydantic-2.12.3-py3-none-any.whl:
Publisher:
ci.yml on pydantic/pydantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic-2.12.3-py3-none-any.whl -
Subject digest:
6986454a854bc3bc6e5443e1369e06a3a456af9d339eda45510f517d9ea5c6bf - Sigstore transparency entry: 619073007
- Sigstore integration time:
-
Permalink:
pydantic/pydantic@1a8850d101e67d2744ba8c6286e1172d7cd89d0b -
Branch / Tag:
refs/tags/v2.12.3 - Owner: https://github.com/pydantic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@1a8850d101e67d2744ba8c6286e1172d7cd89d0b -
Trigger Event:
push
-
Statement type: