Update dependency pydantic to v2 #113
Reference in New Issue
Block a user
Delete Branch "renovate/pydantic-2.x"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR contains the following updates:
==1.10.26→==2.12.5Release Notes
pydantic/pydantic (pydantic)
v2.12.5Compare Source
GitHub release
This is the fifth 2.12 patch release, addressing an issue with the
MISSINGsentinel 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.
model_construct()on a model withMISSINGas a default value by @ornariece in #12522.v2.12.4Compare Source
GitHub release
This is the fourth 2.12 patch release, fixing more regressions, and reverting a change in the
build()methodof the
AnyUrland Dsn types.This patch release also fixes an issue with the serialization of IP address types, when
serialize_as_anyis used. The next patch releasewill 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
TypedDictclasses by @Viicos in #12427.This issue is only relevant on Python 3.14 and greater.
Exclude fields with
exclude_iffrom JSON Schema required fields by @Viicos in #12430Revert URL percent-encoding of credentials in the
build()methodof the
AnyUrland Dsn types by @davidhewitt inpydantic-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_anybehavior 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.defaultdicttype.
Fix issue with field serializers on nested typed dictionaries by @davidhewitt in pydantic-core#1879.
Add more
pydantic-corebuilds for the three-threaded version of Python 3.14 by @davidhewitt in pydantic-core#1864.v2.12.3Compare Source
GitHub release
What's Changed
This is the third 2.12 patch release, fixing issues related to the
FieldInfoclass, and reverting a change to the supportedafter model validator function signatures.
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.
FieldInfo.asdict()method, improve documentation aroundFieldInfoby @Viicos in #12411.This also add back support for mutations on
FieldInfoclasses, that are reused asAnnotatedmetadata. However, note that this is stillnot 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.2Compare Source
GitHub release
What's Changed
Fixes
pydantic-coreversion, as a corrupted CPython 3.10manylinux2014_aarch64wheel got uploaded (pydantic-core#1843).v2.12.1Compare Source
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
Noneis converted asNoneTypein Python 3.14 by @Viicos in #12370ValidationInfofor validation of default value by @Viicos in pydantic-core#1826MultiHostUrlbuilder by @willswire in pydantic-core#1829serialize_as_anyserialization flag by @davidhewitt in pydantic-core#1829RootModelserialization issues by @davidhewitt in pydantic-core#1836New Contributors
v2.12.0Compare Source
GitHub release
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
extraparameter to the validate functions by @anvilpete in #12233exclude_computed_fieldsserialization option by @Viicos in #12334preverse_empty_pathURL options by @Viicos in #12336union_formatparameter to JSON Schema generation by @Viicos in #12147__qualname__parameter forcreate_modelby @Atry in #12001Fixes
TypeAdapterby @Viicos in #12324Anyfor context type annotation inTypeAdapterby @inducer in #12279FieldInfoinpydantic.fields.__all__by @Viicos in #12339validation_aliasin@validate_callby @Viicos in #12340Anyas context annotation in plugin API by @Viicos in #12341stacklevelin warnings when possible by @Viicos in #12342New Contributors
v2.11.10Compare Source
GitHub release
What's Changed
Fixes
v2.11.9Compare Source
GitHub release
What's Changed
Fixes
v2.11.8Compare Source
GitHub release
What's Changed
Fixes
v2.11.7Compare Source
GitHub release
What's Changed
Fixes
FieldInfoinstance if necessary duringFieldInfobuild by @Viicos in #11898v2.11.6Compare Source
GitHub release
What's Changed
Fixes
FieldInfoby @Viicos in #11946v2.11.5Compare Source
GitHub release
What's Changed
Fixes
FieldInfois complete after applying type variable map by @Viicos in #11855model_rebuild()by @Viicos in #11890v2.11.4Compare Source
GitHub release
What's Changed
Packaging
mkdocs-llmstxtto v0.2.0 by @Viicos in #11725Changes
create_model()by @Viicos in #11714.This change was backported as it was previously possible (although not meant to be supported)
to provide
model_configas a field, which would make it possible to provide both configurationand bases.
Fixes
function-beforeschemas during schema gathering by @Viicos in #11801v2.11.3Compare Source
GitHub release
What's Changed
Packaging
Fixes
v2.11.2Compare Source
GitHub release
What's Changed
Fixes
pydantic-coreto v2.33.1 by @Viicos in #11678__pydantic_private__exists before setting private attributes by @Viicos in #11666FieldInfo._completewhen using field from parent class by @Viicos in #11668v2.11.1Compare Source
GitHub release
What's Changed
Fixes
v2.11.0Compare Source
GitHub release
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
pydantic-coreto v2.33.0 by @Viicos in #11631New Features
encoded_string()method to the URL types by @YassinNouh21 in #11580defer_buildwith@validate_calldecorator by @Viicos in #11584@with_configdecorator to be used with keyword arguments by @Viicos in #11608generate_arguments_schema()function by @Viicos in #11572Fixes
New Contributors
v2.10.6Compare Source
GitHub release
What's Changed
Fixes
'examples'keys by @Viicos in #11325v2.10.5Compare Source
GitHub release
What's Changed
Fixes
v2.10.4Compare Source
GitHub release
What's Changed
Packaging
pydantic-coreto v2.27.2 by @davidhewitt in #11138Fixes
AnyUrlobjects by @alexprabhat99 in #11082lento_BaseUrlto avoid TypeError by @Kharianne in #11111New Contributors
v2.10.3Compare Source
GitHub release
What's Changed
Fixes
defer_buildis set on Pydantic dataclasses by @Viicos in #10984dictcore schema keys by @Viicos in #10989PlainSerializerandWrapSerializerfunctions by @Viicos in #11008default_factory_takes_validated_dataproperty toFieldInfoby @Viicos in #11034serializationmode by @sydney-runkle in #11035v2.10.2Compare Source
GitHub release
What's Changed
Fixes
Secrettypes andUrltypes by @sydney-runkle in #10947Field.defaultto be compatible with Python 3.8 and 3.9 by @Viicos in #10972BaseModel.__replace__definition from type checkers by @Viicos in #10979v2.10.1Compare Source
GitHub release
What's Changed
Packaging
pydantic-coreversion tov2.27.1by @sydney-runkle in #10938Fixes
TypeAdapterby @Viicos in #10893default_factoryutils by @sydney-runkle in #10909model_fieldsandmodel_computed_fieldsby @sydney-runkle in #10911dataclasses by @sydney-runkle in #10928globalsof the function when evaluating the return type of serializers andcomputed_fields by @Viicos in #10929''by @sydney-runkle in #10936pythonmode serialization forcomplexinference by @sydney-runkle in pydantic-core#1549New Contributors
v2.10.0Compare Source
The code released in v2.10.0 is practically identical to that of v2.10.0b2.
GitHub release
See the v2.10 release blog post for the highlights!
What's Changed
Packaging
pydantic-coretov2.27.0by @sydney-runkle in #10825New Features
fractions.Fractionby @sydney-runkle in #10318Hashablefor json validation by @sydney-runkle in #10324SocketPathtype forlinuxsystems by @theunkn0wn1 in #10378examplesby @sydney-runkle in #10417defer_buildfor Pydantic dataclasses by @Viicos in #10313TypedDictto type hint variadic keyword arguments with@validate_callby @Viicos in #10416protected_namespacesby @sydney-runkle in #10522propertyNamesin JSON schema by @FlorianSW in #10478__replace__protocol for Python 3.13+ support by @sydney-runkle in #10596sortmethod for JSON schema generation by @sydney-runkle in #10595@validate_callcallable argument by @kc0506 in #10627experimental_allow_partialsupport by @samuelcolvin in #10748ValidationErrorandPydanticCustomErrorby @Youssefares in pydantic/pydantic-core#1413trailing-stringssupport toexperimental_allow_partialby @sydney-runkle in #10825rebuild()method forTypeAdapterand simplifydefer_buildpatterns by @sydney-runkle in #10537TypeAdapterinstance repr by @sydney-runkle in #10872Changes
SchemaGeneratoruntil interface is more stable by @sydney-runkle in #10303defer_buildonTypeAdapters, removing experimental flag by @sydney-runkle in #10329mroof generic subclass by @kc0506 in #10100b64decodeandb64encodeforBase64Bytestype by @sydney-runkle in #10486@dataclassdecorator and with the__pydantic_config__attribute by @sydney-runkle in #10406Ellipsis(...) withFieldby @Viicos in #10661Literals andEnumsby @Viicos in #10692AnyorNeverwhen replacing type variables by @Viicos in #10338base64bytes by @bschoenmaeckers in pydantic/pydantic-core#1448Performance
CoreMetadatarefactor with an emphasis on documentation, schema build time performance, and reducing complexity by @sydney-runkle in #10675Fixes
computed_fieldwithfield_serializerby @nix010 in #10390Predicateissue inv2.9.0by @sydney-runkle in #10321annotated-typesbound by @sydney-runkle in #10327tzdatainstall requirement into optionaltimezonedependency by @jakob-keller in #10331namedtuplecore schemas by @Viicos in #10337IncExtype alias definition by @Viicos in #10339ModelMetaclass.mroby @Viicos in #10372computed_fields by @Viicos in #10391inspect.iscoroutinefunctionworks on coroutines decorated with@validate_callby @MovisLi in #10374NameErrorwhen usingvalidate_callwith PEP 695 on a class by @kc0506 in #10380ZoneInfowith various invalid types by @sydney-runkle in #10408PydanticUserErroron emptymodel_configwith annotations by @cdwilson in #10412_IncExtype alias, only allowTrueby @Viicos in #10414PlainValidatorby @Viicos in #10427json_schema_input_typeby @Viicos in #10439Representationby @Viicos in #10480max_digitsanddecimal_places) by @sydney-runkle in #10506__pydantic_core_schema__from the current class during schema generation by @Viicos in #10518stacklevelon deprecation warnings forBaseModelby @sydney-runkle in #10520stacklevelinBaseModel.__init__by @Viicos in #10526ConfigWrapper.core_configto take the title directly by @Viicos in #10562mode='python'by @sydney-runkle in #10594Base64Etctypes by @sydney-runkle in #10584validate_callignoringFieldinAnnotatedby @kc0506 in #10610Selfis invalid by @kc0506 in #10609core_schema.InvalidSchemainstead of metadata injection + checks by @sydney-runkle in #10523typewithtyping.Selfand type aliases by @kc0506 in #10621FieldandPrivateAttrfunctions by @Viicos in #10651mypyplugin implementation by @Viicos in #10669typing_extensionsvariant ofTypeAliasTypeby @Daraan in #10713BaseModel.model_copy()by @Viicos in #10751isinstancebehavior for urls by @sydney-runkle in #10766cached_propertycan be set on Pydantic models by @Viicos in #10774host_requiredfor URLs by @Viicos in pydantic/pydantic-core#1488coerce_numbers_to_strenabled and string has invalid Unicode character by @andrey-berenda in pydantic/pydantic-core#1515complexvalues inEnums by @changhc in pydantic/pydantic-core#1524_typing_extramodule by @Viicos in #10725bytearraytoTypeAdapter.validate_jsonsignature by @samuelcolvin in #10802Fieldby @Viicos in #10816validate_callby @sydney-runkle in #10807IncExtype alias to be compatible with mypy by @Viicos in #10813__signature__a lazy property, do not deepcopy defaults by @Viicos in #10818__signature__lazy for dataclasses, too by @sydney-runkle in #10832AnyUrlto preserve behavior from v2.9 by @sydney-runkle in #10856New Contributors
v2.9.2Compare Source
GitHub release
What's Changed
Fixes
Callablediscriminators by @sydney-runkle in #10400PlainValidatorby @Viicos in #10427Unionserialization warnings by @sydney-runkle in pydantic/pydantic-core#1449_IncExtype alias, only allowTrueby @Viicos in #10414ZoneInfovalidation with various invalid types by @sydney-runkle in #10408v2.9.1Compare Source
GitHub release
What's Changed
Fixes
annotated-typesbound to>=0.6.0by @sydney-runkle in #10327tzdatainstall requirement into optionaltimezonedependency by @jakob-keller in #10331IncExctype alias definition by @Viicos in #10339v2.9.0Compare Source
The code released in v2.10.0 is practically identical to that of v2.10.0b2.
GitHub release
See the v2.10 release blog post for the highlights!
What's Changed
Packaging
pydantic-coretov2.27.0by @sydney-runkle in #10825New Features
fractions.Fractionby @sydney-runkle in #10318Hashablefor json validation by @sydney-runkle in #10324SocketPathtype forlinuxsystems by @theunkn0wn1 in #10378examplesby @sydney-runkle in #10417defer_buildfor Pydantic dataclasses by @Viicos in #10313TypedDictto type hint variadic keyword arguments with@validate_callby @Viicos in #10416protected_namespacesby @sydney-runkle in #10522propertyNamesin JSON schema by @FlorianSW in #10478__replace__protocol for Python 3.13+ support by @sydney-runkle in #10596sortmethod for JSON schema generation by @sydney-runkle in #10595@validate_callcallable argument by @kc0506 in #10627experimental_allow_partialsupport by @samuelcolvin in #10748ValidationErrorandPydanticCustomErrorby @Youssefares in pydantic/pydantic-core#1413trailing-stringssupport toexperimental_allow_partialby @sydney-runkle in #10825rebuild()method forTypeAdapterand simplifydefer_buildpatterns by @sydney-runkle in #10537TypeAdapterinstance repr by @sydney-runkle in #10872Changes
SchemaGeneratoruntil interface is more stable by @sydney-runkle in #10303defer_buildonTypeAdapters, removing experimental flag by @sydney-runkle in #10329mroof generic subclass by @kc0506 in #10100b64decodeandb64encodeforBase64Bytestype by @sydney-runkle in #10486@dataclassdecorator and with the__pydantic_config__attribute by @sydney-runkle in #10406Ellipsis(...) withFieldby @Viicos in #10661Literals andEnumsby @Viicos in #10692AnyorNeverwhen replacing type variables by @Viicos in #10338base64bytes by @bschoenmaeckers in pydantic/pydantic-core#1448Performance
CoreMetadatarefactor with an emphasis on documentation, schema build time performance, and reducing complexity by @sydney-runkle in #10675Fixes
computed_fieldwithfield_serializerby @nix010 in #10390Predicateissue inv2.9.0by @sydney-runkle in #10321annotated-typesbound by @sydney-runkle in #10327tzdatainstall requirement into optionaltimezonedependency by @jakob-keller in #10331namedtuplecore schemas by @Viicos in #10337IncExtype alias definition by @Viicos in #10339ModelMetaclass.mroby @Viicos in #10372computed_fields by @Viicos in #10391inspect.iscoroutinefunctionworks on coroutines decorated with@validate_callby @MovisLi in #10374NameErrorwhen usingvalidate_callwith PEP 695 on a class by @kc0506 in #10380ZoneInfowith various invalid types by @sydney-runkle in #10408PydanticUserErroron emptymodel_configwith annotations by @cdwilson in #10412_IncExtype alias, only allowTrueby @Viicos in #10414PlainValidatorby @Viicos in #10427json_schema_input_typeby @Viicos in #10439Representationby @Viicos in #10480max_digitsanddecimal_places) by @sydney-runkle in #10506__pydantic_core_schema__from the current class during schema generation by @Viicos in #10518stacklevelon deprecation warnings forBaseModelby @sydney-runkle in #10520stacklevelinBaseModel.__init__by @Viicos in #10526ConfigWrapper.core_configto take the title directly by @Viicos in #10562mode='python'by @sydney-runkle in #10594Base64Etctypes by @sydney-runkle in #10584validate_callignoringFieldinAnnotatedby @kc0506 in #10610Selfis invalid by @kc0506 in #10609core_schema.InvalidSchemainstead of metadata injection + checks by @sydney-runkle in #10523typewithtyping.Selfand type aliases by @kc0506 in #10621FieldandPrivateAttrfunctions by @Viicos in #10651mypyplugin implementation by @Viicos in #10669typing_extensionsvariant ofTypeAliasTypeby @Daraan in #10713BaseModel.model_copy()by @Viicos in #10751isinstancebehavior for urls by @sydney-runkle in #10766cached_propertycan be set on Pydantic models by @Viicos in #10774host_requiredfor URLs by @Viicos in pydantic/pydantic-core#1488coerce_numbers_to_strenabled and string has invalid Unicode character by @andrey-berenda in pydantic/pydantic-core#1515complexvalues inEnums by @changhc in pydantic/pydantic-core#1524_typing_extramodule by @Viicos in #10725bytearraytoTypeAdapter.validate_jsonsignature by @samuelcolvin in #10802Fieldby @Viicos in #10816validate_callby @sydney-runkle in #10807IncExtype alias to be compatible with mypy by @Viicos in #10813__signature__a lazy property, do not deepcopy defaults by @Viicos in #10818__signature__lazy for dataclasses, too by @sydney-runkle in #10832AnyUrlto preserve behavior from v2.9 by @sydney-runkle in #10856New Contributors
v2.8.2Compare Source
GitHub release
What's Changed
Fixes
v2.8.1Compare Source
GitHub release
What's Changed
Packaging
rufftov0.5.0andpyrighttov1.1.369by @sydney-runkle in #9801pydantic-coretov2.20.1,pydantic-extra-typestov2.9.0by @sydney-runkle in #9832Fixes
to_snakefrom v2.7 -> v2.8 by @sydney-runkle in #9812v2.8.0Compare Source
GitHub release
The code released in v2.8.0 is functionally identical to that of v2.8.0b1.
What's Changed
Packaging
v1.1.367and add type checking tests for pipeline API by @adriangb in #9674pydantic.v1stub tov1.10.17by @sydney-runkle in #9707v2.8.0b1by @sydney-runkle in #9741pydantic-coretov2.20.0by @sydney-runkle in #9745pdmversion used forpdm.lockto v2.16.1 by @sydney-runkle in #9761ruffv0.4.8by @Viicos in #9585New Features
defer_buildforTypeAdapterby @MarkusSintonen in #8939deprecatedfield in json schema by @NeevCohen in #9298fail_fastfeature by @uriyyo in #9708ser_json_inf_nan='strings'mode to produce valid JSON by @josh-newman in pydantic/pydantic-core#1307Changes
Annotatedfield by @nix010 in #9170__validators__values increate_modelby @sydney-runkle in #9697smartunion matching logic by @sydney-runkle in pydantic/pydantic-core#1322You can read more about our
smartunion matching logic here. In some cases, if the old behavioris desired, you can switch to
left-to-rightmode and change the order of yourUnionmembers.Performance
Internal Improvements
_display_error_loc()by 25% inpydantic/v1/error_wrappers.pyby @misrasaurabh1 in #9653_get_all_json_refs()by 34% inpydantic/json_schema.pyby @misrasaurabh1 in #9650is_pydantic_dataclass()by 41% inpydantic/dataclasses.pyby @misrasaurabh1 in #9652to_snake()by 27% inpydantic/alias_generators.pyby @misrasaurabh1 in #9747unwrap_wrapped_function()by 93% inpydantic/_internal/_decorators.pyby @misrasaurabh1 in #9727Fixes
__spec__.parentwith__package__by @hramezani in #9331Sequencetype by @anesmemisevic in #9303_frame_depthby @Viicos in #9353ImportStringjson schema compatible by @amitschang in #9344PrivateAttr) from__init__signature in type checkers by @idan22moral in #9293TypeVardefaults robust to the CPythonPEP-696implementation by @AlexWaygood in #9426PlainSerializerwith builtin types by @Viicos in #9450strictspecification forStringConstraint(strict=False)by @vbmendes in #9476Selfwhere possible by @Viicos in #9479RootModel.model_constructsignature in themypyplugin by @Viicos in #9480validation_contextby @OhioDschungel6 in #9508dump_json/dump_pythonby @alexcouper in #9495Field()constructor by @bjmc in #9484TypeAdapterby @Viicos in #9570__setstate__of BaseModel by @anhpham1509 in #9584PEP 746by @adriangb in #9587TypeVarfields by @dmontagu in #9606regexflags in validation and json schema by @sydney-runkle in #9591IpvAnyAddressby @sydney-runkle in #9640__pydantic_extra__by @dmontagu in #9659Optional[Decimal]by @lazyhope in #9754validate_calltype params fix by @sydney-runkle in #9760re.Patternobject in regex patterns to allow for regex flags by @sydney-runkle in pydantic/pydantic-core#1318New Contributors
v2.7.4Compare Source
Github release
What's Changed
Packaging
pydantic.v1tov1.10.16reference by @sydney-runkle in #9639Fixes
recursive_guardas kwarg inFutureRef._evaluateby @vfazio in #9612v2.7.3Compare Source
GitHub release
What's Changed
Packaging
pydantic-coretov2.18.4by @sydney-runkle in #9550Fixes
v2.7.2Compare Source
GitHub release
What's Changed
Packaging
pydantic-coretov2.18.3by @sydney-runkle in #9515Fixes
__spec__.parentwith__package__by @hramezani in #9331ints with leading unary minus by @RajatRajdeep in pydantic/pydantic-core#1291strsubclass validation for enums by @sydney-runkle in pydantic/pydantic-core#1273BigInts inLiterals andEnums by @samuelcolvin in pydantic/pydantic-core#1297strsubclass as input by @davidhewitt in pydantic/pydantic-core#1296v2.7.1Compare Source
GitHub release
What's Changed
Packaging
pydantic-coretov2.18.2by @sydney-runkle in #9307New Features
Changes
…by @LouisGobert in #9214Fixes
validation_aliasbehavior withmodel_constructforAliasChoicesandAliasPathby @sydney-runkle in #9223typing.Literaland import it outside the TYPE_CHECKING block by @frost-nzcr4 in #9232Secretserialization schema, applicable for unions by @sydney-runkle in #9240strictapplication tofunction-afterwithuse_enum_valuesby @sydney-runkle in #9279model_constructon a class which definesmodel_post_initfails withAttributeErrorby @babygrimes in #9168model_json_schemawith config types by @NeevCohen in #9287intby @samuelcolvin in pydantic/pydantic-core#1269ints with leading unary plus by @cknv in pydantic/pydantic-core#1272extra != 'ignore'andfrom_attributes=Trueby @davidhewitt in pydantic/pydantic-core#1276Enum'smissingfunction asValidationErrorby @sydney-runkle in pydantic/pydantic-core#1274Iterablevalidation by @davidhewitt in pydantic/pydantic-core#1271New Contributors
v2.7.0Compare Source
GitHub release
The code released in v2.7.0 is practically identical to that of v2.7.0b1.
What's Changed
Packaging
pyproject.tomlsections by @Viicos in #8899pydantic-coretov2.18.1by @sydney-runkle in #9211jiterv0.2.0by @samuelcolvin in pydantic/pydantic-core#1250New Features
FieldInfo.descriptionby @Viicos in #6563with_configdecorator to comply with typing spec by @Viicos in #8611ByteSize.human_readableby @jks15satoshi in #8706Secretbase type by @conradogarciaberrotaran in #8519Sphinxinventories for cross references in docs by @Viicos in #8682deprecatedfields by @Viicos in #8237field_serializer('*')by @ornariece in #9001model_configis defined as a model property by @alexeyt101 in #9004create_model()to supporttyping.Annotatedas input by @wannieman98 in #8947ClickhouseDsnsupport by @solidguy7 in #9062re.Pattern[str]topatternfield by @jag-k in #9053serialize_as_anyruntime setting by @sydney-runkle in #8830typing.Selfby @Youssefares in #9023contextto serialization by @ornariece in #8965Finalized in v2.7.0, rather than v2.7.0b1:
warningsparameter for serialization utilities to allow raising a warning by @Lance-Drane in #9166Changes
model_constructbehavior withextraby @sydney-runkle in #8807RootModelsubclasses by @sydney-runkle in #8857PEP570syntax by @Viicos in #8940enumandtypeto the JSON schema for single item literals by @dmontagu in #8944update_json_schemainternal function by @sydney-runkle in #9125Performance
enumvalidator improvements by @samuelcolvin in #9045enumvalidation and serialization to Rust by @samuelcolvin in #9064aarch64(Note: SIMD on x86 will be implemented in a future release) by @samuelcolvin in in pydantic/jiter#65Cow<str>fromjiterby @davidhewitt in pydantic/pydantic-core#1231Fixes
Sequences by @sydney-runkle in #8614__qualname__by @anci3ntr0ck in #8642__pydantic_extra__annotation being a string or inherited by @alexmojaki in #8659NameEmailby @Holi0317 in #8650BaseModelby @bluenote10 in #8651mypyplugin andno_strict_optional = Trueby @dmontagu in #8666ByteSizeerrortypechange by @sydney-runkle in #8681__pydantic_config__ignored for TypeDict by @13sin in #8734pytest v8.0.0due topytest.warns()starting to work insidepytest.raises()by @mgorny in #8678is_valid_fieldfrom 1.x formypyplugin by @DanielNoord in #8738mypystrict equality flag by @dmontagu in #8799FieldInfo.__repr_args__by @sydney-runkle in #8801BaseModeltype annotations to be resolvable bytyping.get_type_hintsby @devmonkey22 in #7680AliasGeneratorby @sydney-runkle in #8810date->datetimetimezone assumption fix by @sydney-runkle in #8823ast.Strby @Viicos in #8837deprecateddecorators by @Viicos in #8877NameEmailif name includes an email address by @NeevCohen in #8860TypeAdapter's typing compatible with special forms by @adriangb in #8923enums by @dmontagu in #8920model_json_schemausage by @sydney-runkle in #8928mypyplugin by @dmontagu in #9008PlainSerializerusage with std type constructor by @sydney-runkle in #9031Model.__getattr__()by @NeevCohen in #9082ClassVarforward ref inherited from parent class by @alexmojaki in #9097Trueby @andresliszt in #8977dequewhen passed toSequence[blah blah blah]by @sydney-runkle in #9128model_post_initby @Viicos in #9134model_constructwithvalidation_aliasby @ornariece in #9144Literalnulltypes by @bruno-f-cruz in #9135New Contributors
v2.6.4Compare Source
GitHub release
What's Changed
Fixes
AliasGeneratorwithcomputed_fielddecorator by @sydney-runkle in #8806v2.6.3Compare Source
GitHub release
What's Changed
Packaging
pydantic-settingsversion in the docs by @hramezani in #8906Fixes
v2.6.2Compare Source
GitHub release
What's Changed
Packaging
pydantic-core2.16.3 by @sydney-runkle in #8879Fixes
v2.6.1Compare Source
GitHub release
What's Changed
Packaging
pydantic-core2.16.2 by @sydney-runkle in #8717Fixes
mypyplugin andno_strict_optional = Trueby @dmontagu in #8666ByteSizeerrortypechange by @sydney-runkle in #8681Fieldannotations in dataclasses by @sydney-runkle in #8679PlainValidatorby @sydney-runkle in #8710Unionby @davidhewitt in pydantic/pydantic-core#1174computed_fieldJSON serializerexclude_nonebehavior by @sydney-runkle in pydantic/pydantic-core#1187v2.6.0Compare Source
GitHub release
The code released in v2.6.0 is practically identical to that of v2.6.0b1.
What's Changed
Packaging
email-validatorversion >= 2.0 by @commonism in #6033pydantic-extra-types==2.4.1by @yezz123 in #8478pyright==1.1.345by @Viicos in #8453New Features
NatsDsnby @ekeew in #6874ConfigDict.ser_json_inf_nanby @davidhewitt in #8159types.OnErrorOmitby @adriangb in #8222AliasGeneratorusage by @sydney-runkle in #8282yyyy-MM-DDdatetime parsing by @sydney-runkle in #8404ByteSizeclass #8415 by @luca-matei in #8507ByteSizeby @geospackle in #8537eval_type_backportto handle union operator and builtin generic subscripting in older Pythons by @alexmojaki in #8209dataclassfieldsinitby @dmontagu in #8552ValidationErrorby @davidhewitt in pydantic/pydantic-core#1119Changes
selfinBaseModelconstructor, so no field name can ever conflict with it by @ariebovenberg in #8072@validate_callreturn a function instead of a custom descriptor - fixes binding issue with inheritance and addsself/clsargument to validation errors by @alexmojaki in #8268BaseModeldocstring from JSON schema description by @sydney-runkle in #8352classpropertydecorator formodel_computed_fieldsby @Jocelyn-Gas in #8437Performance
intextraction by @samuelcolvin in pydantic/pydantic-core#1155dataclassserialization speedups by @samuelcolvin in pydantic/pydantic-core#1162HashMapcreation when looking up small JSON objects inLazyIndexMapsby @samuelcolvin in pydantic/jiter#55Peakwith more efficientPeekby @davidhewitt in pydantic/jiter#48Fixes
getattrwarning in deprecatedBaseConfigby @tlambert03 in #7183model_fields, not whole__dict__by @alexmojaki in #7786mypyplugin by @dmontagu in #7411mypyerror on untypedClassVarby @vincent-hachin-wmx in #8138BaseModel.__eq__instead of whole__dict__by @QuentinSoubeyranAqemia in #7825strictdocstring inmodel_validatemethod. by @LukeTonin in #8223computed_fieldby @Viicos in #8227validate_calldecorator to be dynamically assigned to a class method by @jusexton in #8249unittest.mockdeprecation warnings by @ibleedicare in #8262JsonValuecontains subclassed primitive values by @jusexton in #8286mypyerror on free before validator (classmethod) by @sydney-runkle in #8285to_snakeconversion by @jevins09 in #8316ModelMetaclass.__prepare__by @slanzmich in #8305configspecification when initializing aTypeAdapterwhen the annotated type has config already by @sydney-runkle in #8365aliasindataclasssignature by @NeevCohen in #8387Field(...)in a forward ref by @dmontagu in #8494__dict__withmodel_constructcall by @sydney-runkle in #8500path_typecreation when globals does not contain__name__by @hramezani in #8470from __future__ import annotationsby @sydney-runkle in #8513@deprecatedby @Viicos in #8294model_constructcall by @sydney-runkle in #8525TypeAliasTypefor types with refs by @dmontagu in #8526pydantic.Field(repr=False)in dataclasses by @tigeryy2 in #8511dataclass_transformbehavior forRootModelby @Viicos in #8163exclude_nonefor json serialization ofcomputed_fields by @sydney-runkle in pydantic/pydantic-core#1098New Contributors
pydanticpydantic-corev2.5.3Compare Source
GitHub release
What's Changed
Packaging
pydantic-coreto 2.14.6Fixes
v2.5.2Compare Source
GitHub release
What's Changed
Packaging
pydantic-coreto 2.14.5New Features
ConfigDict.ser_json_inf_nanby @davidhewitt in #8159Fixes
Literalfrom JSON keys when used asdictkey by @sydney-runkle in pydantic/pydantic-core#1075custom_initon members ofUnionby @sydney-runkle in pydantic/pydantic-core#1076JsonValueboolserialization by @sydney-runkle in #8190LiteralinUnions by @sydney-runkle in pydantic/pydantic-core#1089v2.5.1Compare Source
GitHub release
What's Changed
Packaging
Fixes
ValidateCallWrappererror when creating a model which has a @validate_call wrapped field annotation by @sydney-runkle in #8110v2.5.0Compare Source
GitHub release
The code released in v2.5.0 is functionally identical to that of v2.5.0b1.
What's Changed
Packaging
pyright==1.1.335by @Viicos in #8075New Features
ValidationErrorerrors by @adriangb in #7806__doc__argument increate_model()by @chris-spann in #7863regex_engineflag - meaning you can use with the Rust or Python regex libraries in constraints by @utkini in #7768ComputedFieldInfoby @alexmojaki in #7889ruffformatter by @Luca-Blight in #7930validation_error_causeto config by @zakstucke in #7626CallableDiscriminatorandTagby @dmontagu in #7983CallableDiscriminatorrenamed toDiscriminatorby @dmontagu in #8047examplesandjson_schema_extrato@computed_fieldby @alexmojaki in #8013JsonValuetype by @dmontagu in #7998stras argument toDiscriminatorby @dmontagu in #8047SchemaSerializer.__reduce__method to enable pickle serialization by @edoakes in pydantic/pydantic-core#1006Changes
ultra_strictwith new smart union implementation, the way unions are validated has changed significantly to improve performance and correctness, we have worked hard to absolutely minimise the number of cases where behaviour has changed, see the PR for details - by @davidhewitt in pydantic/pydantic-core#867extra='allow'by @sydney-runkle in #7683Enumtypes with no cases by @sydney-runkle in #7927GenericbeforeBaseModelby @alexmojaki in #7891Performance
jiterby @samuelcolvin in pydantic/pydantic-core#974__getattr__for all package imports, improve import time by @samuelcolvin in #7947Fixes
mypyissue with subclasses ofRootModelby @sydney-runkle in #7677FieldInfowhen a forward ref gets evaluated by @dmontagu in #7698SecretStrfrom JSON (regression in v2.4) by @sydney-runkle in #7729defer_buildbehavior withTypeAdapterby @sydney-runkle in #7736mypyversions by @dmontagu in #7742TypeVarhandling when default is not set by @pmmmwh in #7719strictonEnumtype fields by @sydney-runkle in #7761weakref.refinstead of subclassing to fixcloudpickleserialization by @edoakes in #7780model_post_initin subclasses by @alexmojaki in #7775json_schema_extraby @alexmojaki in #7803strictspecification forUUIDtypes by @sydney-runkle in #7865pydantic.Field(kw_only=True)with inherited dataclasses by @PrettyWood in #7827validate_calldecorator for methods in classes with__slots__by @sydney-runkle in #7883dataclasses.fielddefault by @hramezani in #7898importlib_metadataon python 3.7 by @sydney-runkle in #7904|operator (Union) in PydanticRecursiveRef by @alexmojaki in #7892display_as_typeforTypeAliasTypein python 3.12 by @dmontagu in #7929NotRequiredgenerics inTypedDictby @sydney-runkle in #7932TypeAliasTypespecifications produce different schema definitions by @alexdrydew in #7893PrivateAttris passed fromAnnotateddefault position by @tabassco in #8004classmethodinstead ofclassmethod[Any, Any, Any]by @Mr-Pepe in #7979Optionalfield withvalidate_defaultonly performing one field validation by @sydney-runkle in pydantic/pydantic-core#1002definition-refbug withDictkeys by @sydney-runkle in pydantic/pydantic-core#1014booltypes withcoerce_numbers_to_str=Trueby @sydney-runkle in pydantic/pydantic-core#1017NaNin float and decimal constraints by @davidhewitt in pydantic/pydantic-core#1037lax_strandlax_intsupport for enum values not inherited from str/int by @michaelhly in pydantic/pydantic-core#1015UnionofListtypes by @sydney-runkle in pydantic/pydantic-core#1039max_digitsanddecimalsto pass if normalized or non-normalized input is valid by @sydney-runkle in pydantic/pydantic-core#1049ValidationErrormessages by @Iipin in pydantic/pydantic-core#1050'-'asdatetimeinput by @davidhewitt in pydantic/speedate#52 & pydantic/pydantic-core#1060New Contributors
pydanticpydantic-corev2.4.2Compare Source
GitHub release
What's Changed
Fixes
models_json_schemafor generic models by @adriangb in #7654New Contributors
v2.4.1Compare Source
GitHub release
The code released in v2.6.0 is practically identical to that of v2.6.0b1.
What's Changed
Packaging
email-validatorversion >= 2.0 by @commonism in #6033pydantic-extra-types==2.4.1by @yezz123 in #8478pyright==1.1.345by @Viicos in #8453New Features
NatsDsnby @ekeew in #6874ConfigDict.ser_json_inf_nanby @davidhewitt in #8159types.OnErrorOmitby @adriangb in #8222AliasGeneratorusage by @sydney-runkle in #8282yyyy-MM-DDdatetime parsing by @sydney-runkle in #8404ByteSizeclass #8415 by @luca-matei in #8507ByteSizeby @geospackle in #8537eval_type_backportto handle union operator and builtin generic subscripting in older Pythons by @alexmojaki in #8209dataclassfieldsinitby @dmontagu in #8552ValidationErrorby @davidhewitt in pydantic/pydantic-core#1119Changes
selfinBaseModelconstructor, so no field name can ever conflict with it by @ariebovenberg in #8072@validate_callreturn a function instead of a custom descriptor - fixes binding issue with inheritance and addsself/clsargument to validation errors by @alexmojaki in #8268BaseModeldocstring from JSON schema description by @sydney-runkle in #8352classpropertydecorator formodel_computed_fieldsby @Jocelyn-Gas in #8437Performance
intextraction by @samuelcolvin in pydantic/pydantic-core#1155dataclassserialization speedups by @samuelcolvin in pydantic/pydantic-core#1162HashMapcreation when looking up small JSON objects inLazyIndexMapsby @samuelcolvin in pydantic/jiter#55Peakwith more efficientPeekby @davidhewitt in pydantic/jiter#48Fixes
getattrwarning in deprecatedBaseConfigby @tlambert03 in #7183model_fields, not whole__dict__by @alexmojaki in #7786mypyplugin by @dmontagu in #7411mypyerror on untypedClassVarby @vincent-hachin-wmx in #8138BaseModel.__eq__instead of whole__dict__by @QuentinSoubeyranAqemia in #7825strictdocstring inmodel_validatemethod. by @LukeTonin in #8223computed_fieldby @Viicos in #8227validate_calldecorator to be dynamically assigned to a class method by @jusexton in #8249unittest.mockdeprecation warnings by @ibleedicare in #8262JsonValuecontains subclassed primitive values by @jusexton in #8286mypyerror on free before validator (classmethod) by @sydney-runkle in #8285to_snakeconversion by @jevins09 in #8316ModelMetaclass.__prepare__by @slanzmich in #8305configspecification when initializing aTypeAdapterwhen the annotated type has config already by @sydney-runkle in #8365aliasindataclasssignature by @NeevCohen in #8387Field(...)in a forward ref by @dmontagu in #8494__dict__withmodel_constructcall by @sydney-runkle in #8500path_typecreation when globals does not contain__name__by @hramezani in #8470from __future__ import annotationsby @sydney-runkle in #8513@deprecatedby @Viicos in #8294model_constructcall by @sydney-runkle in #8525TypeAliasTypefor types with refs by @dmontagu in #8526pydantic.Field(repr=False)in dataclasses by @tigeryy2 in #8511dataclass_transformbehavior forRootModelby @Viicos in #8163exclude_nonefor json serialization ofcomputed_fields by @sydney-runkle in pydantic/pydantic-core#1098New Contributors
pydanticpydantic-corev2.4.0Compare Source
GitHub release
What's Changed
Packaging
New Features
Base64Urltypes by @dmontagu in #7286numbertostrcoercion by @lig in #7508field_nameanddatain all validators if there is data and a field name by @samuelcolvin in #7542BaseModel.model_validate_stringsandTypeAdapter.validate_stringsby @hramezani in #7552pluginsexperimental implementation by @lig @samuelcolvin and @Kludex in #6820Changes
model_post_initin subclass with private attrs by @Viicos in #7302Extraas deprecated by @disrupted in #7299EncodedStra dataclass by @Kludex in #7396annotated_handlersto be public by @samuelcolvin in #7569Performance
CoreSchemaby @adriangb in #7523CoreSchemawalking by @adriangb in #7528dict.getanddict.setdefaultwith more verbose versions inCoreSchemabuilding hot paths by @adriangb in #7536CoreSchemadiscovery by @adriangb in #7535CoreSchemavalidation for faster startup times by @adriangb in #7565Fixes
TypedDictfrom grandparent classes by @dmontagu in #7272strictconfig overridable in field for Path by @hramezani in #7281ser_json_<timedelta|bytes>on default inGenerateJsonSchemaby @Kludex in #7269SkipValidationto referenced schemas by @adriangb in #7381__get_pydantic_core_schema__signature by @hramezani in #7415TypeAdapter) by @sydney-runkle in #7435TypeErroronmodel_validatorinwrapmode by @pmmmwh in #7496reprwork for instances that failed initialization when handlingValidationErrors by @dmontagu in #7439UUIDvalues havingUUID.version=Noneby @lig in #7566__iter__returning privatecached_propertyinfo by @sydney-runkle in #7570New Contributors
v2.3.0Compare Source
GitHub release
Field(..., exclude: bool)docs by @samuelcolvin in #7214Base64StrandBase64Bytesby @Kludex in #7192config.defer_buildfor serialization first cases by @samuelcolvin in #7024validators.mdto correctvalidate_defaultkwarg by @lmmx in #7229tzinfo.fromutcmethod forTzInfoinpydantic-coreby @lig in #7019__get_validators__by @hramezani in #7197v2.2.1Compare Source
GitHub release
Field(..., exclude: bool)docs by @samuelcolvin in #7214Base64StrandBase64Bytesby @Kludex in #7192config.defer_buildfor serialization first cases by @samuelcolvin in #7024validators.mdto correctvalidate_defaultkwarg by @lmmx in #7229tzinfo.fromutcmethod forTzInfoinpydantic-coreby @lig in #7019__get_validators__by @hramezani in #7197v2.2.0Compare Source
GitHub release
Field.includeby @hramezani in #6852Pathfields by @samuelcolvin in #6903ForwardRefwrapper for py 3.10.0 (shim until bpo-45166) by @randomir in #6919mainbranch for badge links by @Viicos in #6925ser_json_bytesregarding base64 encoding by @Viicos in #7052@validate_callto work on async methods by @adriangb in #7046SettingsandSettingsConfigDictby @JeanArhancet in #7002short_versionand use it in links by @hramezani in #7115RootModelby @Kludex in #7113Field.excludeby @Viicos in #7086validate_assignmentto useField.frozenby @Viicos in #7103_core_utilsby @samuelcolvin in #7040round_tripin Json type documentation by @jc-louis in #7137v2.1.1Compare Source
GitHub release
v2.1.0Compare Source
GitHub release
StringConstraintsfor use as Annotated metadata by @adriangb in #6605help(BaseModelSubclass)raises errors by @hramezani in #6758@model_validator(mode="after")by @ljodal in #6753contentSchemakeyword for JSON schema by @dmontagu in #6715version_info()by @samuelcolvin in #6785SkipJsonSchemaannotation by @Kludex in #6653GenericModeltoMOVED_IN_V2by @adriangb in #6776docs/usage/types/custom.mdby @hramezani in #6803float->Decimalcoercion precision loss by @adriangb in #6810annotated_types.MaxLenvalidator for custom sequence types by @ImogenBits in #6809InstanceOfby @dmontagu in #6829json_encodersby @adriangb in #6811WeakValueDictionaryto fix generic memory leak by @dmontagu in #6681config.defer_buildto optionally make model building lazy by @samuelcolvin in #6823UUIDserialization to pydantic-core by @davidhewitt in #6850json_encodersdocs by @adriangb in #6848staticmethod/classmethodorder with validate_call by @dmontagu in #6686Configby @samuelcolvin in #6847Field.excludetakes priority over call-timeinclude/excludeby @hramezani in #6851GenerateSchemapublic by @adriangb in #6737v2.0.3Compare Source
GitHub release
Field.aliasbehavior in Pydantic V2 by @hramezani in #6508alias_priorityby @tpdorsey in #6520pydantic-coreto v2.2.0 by @lig in #6589enumerror type docs by @lig in #6603max_lengthfor unicode strings by @lig in #6559pydantic.v1by @tpdorsey in #6604$refas an alias by @dmontagu in #6568AnyUrletc by @davidhewitt in #6618json_schema_extraonRootModelusingFieldby @lig in #6622transformdocstring by @StefanBRas in #6649v2.0.2Compare Source
GitHub release
RootModelwould change the value of__dict__, #6457 by @dmontaguconstrdocumentation, renamed oldregexto newpattern, #6452 by @miiliGenerateJsonSchema.generate_definitionssignature, #6436 by @dmontaguSee the full changelog here
v2.0.1Compare Source
GitHub release
First patch release of Pydantic V2
setattr(i.e.m.some_extra_field = 'extra_value')are added to
.model_extraifmodel_configextra='allowed'. Fixed #6333, #6365 by @aaraneySee the full changelog here
v2.0Compare Source
GitHub release
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
extraparameter to the validate functions by @anvilpete in #12233exclude_computed_fieldsserialization option by @Viicos in #12334preverse_empty_pathURL options by @Viicos in #12336union_formatparameter to JSON Schema generation by @Viicos in #12147__qualname__parameter forcreate_modelby @Atry in #12001Fixes
TypeAdapterby @Viicos in #12324Anyfor context type annotation inTypeAdapterby @inducer in #12279FieldInfoinpydantic.fields.__all__by @Viicos in #12339validation_aliasin@validate_callby @Viicos in #12340Anyas context annotation in plugin API by @Viicos in #12341stacklevelin warnings when possible by @Viicos in #12342New Contributors
Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Enabled.
♻ Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by Renovate Bot.