NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI, #18 most downloaded on PyPI
Data validation using Python type hints
Latest stable
2.14.4
Last release 3 days ago
19 Nov 2026
Ships fairly regularly
a new release about every 3 weeks
Nearly every release is documented
notes for 60 of the last 60 stable releases
2 versions withdrawn
withdrawn after publishing
10 years old
212 releases · first in 2017
Drag across the ruler to compare, or tap a release to open it.
Convert schema_of to use AnalyzedType by @adriangb in https://github.com/pydantic/pydantic/pull/5355
ConfigWrapper by @samuelcolvin in https://github.com/pydantic/pydantic/pull/5411@model_validator by @adriangb in https://github.com/pydantic/pydantic/pull/5379validation_alias and serialization_alias to Field by @hramezani in https://github.com/pydantic/pydantic/pull/5433Full Changelog: https://github.com/pydantic/pydantic/compare/v2.0a1...v2.0a2
Your coding agent can read these notes before it upgrades. Set up the MCP server →
Second pre-release of Pydantic V2
See the full changelog here
First pre-release of Pydantic V2!
First pre-release of Pydantic V2!
See this post for more details.
Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.2...v2.0a1
This release contains three security fixes, that were also included in the pydantic.v1 namespace of the v2.14.2 release.
This is the last V1 Pydantic release. V1 support (including the pydantic.v1 namespace in Pydantic V2) fully ends after this release.
This release contains three security fixes, that were also included in the pydantic.v1 namespace of the v2.14.2 release.
Check unique_items in linear time for builtin scalar types by @Viicos in #14101. Addresses GHSA-49g6-96jj-f7r9.
Ignore internal __pydantic attributes when setting extra values on dataclasses by @Viicos in #14103. Addresses GHSA-r49w-vh47-r4hf.
Only accept . as the decimal separator in ISO 8601 durations by @Viicos in #14096. Addresses GHSA-jfv7-ghgv-gx4x.
Full Changelog: v1.10.26...v1.10.27
Fix syntax error under Python 3.7 by @Viicos in https://github.com/pydantic/pydantic/pull/12643
Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.25...v1.10.26
Add minimal support for Python 3.14 by @Viicos in https://github.com/pydantic/pydantic/pull/12636
Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.24...v1.10.25
Add user warning when using Python 3.14 by @Viicos in https://github.com/pydantic/pydantic/pull/12263 Pydantic V1 will *not* work with Python 3.14 and
Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.23...v1.10.24
Fix mypy plugin for mypy 1.18 by @cdce8p in https://github.com/pydantic/pydantic/pull/12207
Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.22...v1.10.23
Fix compatibility with typing-extensions by @Viicos in https://github.com/pydantic/pydantic/pull/11764
typing-extensions by @Viicos in https://github.com/pydantic/pydantic/pull/11764Fix compatibility with ForwardRef._evaluate and Python < 3.12.4 by @griels in https://github.com/pydantic/pydantic/pull/11232
Properly address Python 3.13 deprecation warnings.
This release provides proper support for Python 3.13, with (Cythonized) wheels published for this version.
As a consequence, Cython was updated from 0.29.x to 3.0.x.
3.0.x.pyproject.toml, make use of PEP 517 build options.build instead of direct setup.py invocations.Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.19...v1.10.20
Fix deprecation warning in V1 isinstance check by @alicederyn in https://github.com/pydantic/pydantic/pull/10645
isinstance check by @alicederyn in https://github.com/pydantic/pydantic/pull/10645Eval type fix in V1 by @sydney-runkle in https://github.com/pydantic/pydantic/pull/9751
to_lower_camel to __all__ in utils.py by @sydney-runkle (direct commit)mypy v1 plugin for mypy 1.11 release by @flaeppe in https://github.com/pydantic/pydantic/pull/10139.schema(by_alias=False) by @exs-dwoodward in https://github.com/pydantic/pydantic/pull/10146Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.17...v1.10.18
Advertise Python 3.12 for 1.10.x! Part Deux by @vfazio in https://github.com/pydantic/pydantic/pull/9644
v1 namespace to fix typing and object resolution in python>3.11 by @exs-dwoodward in https://github.com/pydantic/pydantic/pull/9660Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.16...v1.10.17
Import modules/objects directly from v1 namespace by @exs-dwoodward in https://github.com/pydantic/pydantic/pull/9162
v1 namespace by @exs-dwoodward in https://github.com/pydantic/pydantic/pull/9162recursive_guard as kwarg in FutureRef._evaluate by @vfazio in https://github.com/pydantic/pydantic/pull/9612Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.15...v1.10.16
Add pydantic.v1 namespace to Pydantic v1 by @exs-dmiketa in https://github.com/pydantic/pydantic/pull/9042
Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.14...v1.10.15
Update install.md by @dmontagu in https://github.com/pydantic/pydantic/pull/7690
cached_property handling in dataclasses when copied by @rdbisme in https://github.com/pydantic/pydantic/pull/8407Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.13...v1.10.14
Update pip commands to install 1.10 by @chbndrhnns in https://github.com/pydantic/pydantic/pull/6930
validate_email by @hramezani in https://github.com/pydantic/pydantic/pull/7673Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.12...v1.10.13
pydantic.validate_email, #7673 by @hramezaniDeque's maxlen property dropped on V1 validation by @maciekglowka in https://github.com/pydantic/pydantic/pull/6586
Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.11...v1.10.12
maxlen property being dropped on deque validation. Happened only if the deque item has been typed. Changes the _validate_sequence_like func, #6581 by @maciekglowkaFix import of create_model in tools.py by @SharathHuddar in https://github.com/pydantic/pydantic/pull/6364
Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.10...v1.10.11
Fix racy doctests by @K900 in https://github.com/pydantic/pydantic/pull/6103
Json field support to settings management by @hramezani in https://github.com/pydantic/pydantic/pull/6250Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.9...v1.10.10
Add Pydantic classifier by @hramezani in https://github.com/pydantic/pydantic/pull/5847
Full Changelog: https://github.com/pydantic/pydantic/compare/v1.10.8...v1.10.9
Fix a bug in Literal usage with typing-extension==4.6.0, #5826 by @hramezani
Literal usage with typing-extension==4.6.0, #5826 by @hramezaniAnyClassMethod for changes in python/typeshed#9771, #5505 by @ITProKyleFull Changelog: https://github.com/pydantic/pydantic/compare/v1.10.7...v1.10.8
Fix creating schema from model using ConstrainedStr with regex as dict key, #5223 by @matejetz
ConstrainedStr with regex as dict key, #5223 by @matejetzfrom_orm in their own classes, #5187 by @dmontaguInitVar usage with pydantic dataclasses, mypy version 1.1.1 and the custom mypy plugin, #5162 by @cdce8pFull Changelog: https://github.com/pydantic/pydantic/compare/v1.10.6...v1.10.7
Implement logic to support creating validators from non standard callables by using defaults to identify them and unwrapping functools.partial and fun
functools.partial and functools.partialmethod when checking the signature, #5126 by @JensHeinrichdataclass_transform decorator for pydantic dataclasses, #5111 by @cdce8pValidationError, not ConfigError, when a discriminator value is unhashable, #4773 by @kurtmckeeFull Changelog: https://github.com/pydantic/pydantic/compare/v1.10.5...v1.10.6
Fix broken parametrized bases handling with GenericModels with complex sets of models, #5052 by @MarkusSintonen
GenericModels with complex sets of models, #5052 by @MarkusSintonenRecursionError when deep-copying dataclass types wrapped by pydantic, #4949 by @mbillingrX | Y union syntax breaking GenericModel, #4146 by @thenxFull Changelog: https://github.com/pydantic/pydantic/compare/v1.10.4...v1.10.5
Change dependency to typing-extensions>=4.2.0, #4885 by @samuelcolvin
typing-extensions>=4.2.0, #4885 by @samuelcolvinFull Changelog: https://github.com/pydantic/pydantic/compare/v1.10.3...v1.10.4
fix parsing of custom root models, #4883 by @gou177
schema and schema_json on models where a model instance is a one of default values, #4781 by @BobroniumDataclassProxy, #4695 by @PrettyWoodpostgresql+psycopg as allowed scheme for PostgreDsn to make it usable with SQLAlchemy 2, #4689 by @morianpatternProperties and additionalProperties, #4641 by @jpariseunique_items, #4568 by @mfulgoGenericModel with Callable param raising a TypeError, #4551 by @mfulgoStrictStr type annotation, #4538 by @sispdataclass_transform keyword argument name from field_descriptors to field_specifiers, #4500 by @samuelcolvin__post_init__ when dataclasses are inherited, #4487 by @PrettyWoodFull Changelog: https://github.com/pydantic/pydantic/compare/v1.10.2...v1.10.3
NOTE: v1.10.3 was "yanked" from PyPI due to #4885 which is fixed in v1.10.4
schema and schema_json on models where a model instance is a one of default values, #4781 by @BobroniumDataclassProxy, #4695 by @PrettyWoodpostgresql+psycopg as allowed scheme for PostgreDsn to make it usable with SQLAlchemy 2, #4689 by @morianpatternProperties and additionalProperties, #4641 by @jpariseunique_items, #4568 by @mfulgoGenericModel with Callable param raising a TypeError, #4551 by @mfulgoStrictStr type annotation, #4538 by @sispdataclass_transform keyword argument name from field_descriptors to field_specifiers, #4500 by @samuelcolvin__post_init__ when dataclasses are inherited, #4487 by @PrettyWoodPrevent long (length > 4_300) strings/bytes as input to int fields, see python/cpython#95778 and CVE-2020-10735, #1477 by @samuelcolvin
4_300) strings/bytes as input to int fields, see python/cpython#95778 and CVE-2020-10735, #1477 by @samuelcolvintomllib on Python 3.11 when parsing mypy configuration, #4476 by @hauntsaninjaGenericModel cache to detect order of arguments in Union models, #4474 by @sveinugulist and dict as default_factory, #4457 by @samuelcolvinFull Changelog: https://github.com/pydantic/pydantic/compare/v1.10.1...v1.10.2
Add __hash__ method to pydancic.color.Color class, #4454 by @czaki
__hash__ method to pydancic.color.Color class, #4454 by @czakiFull Changelog: https://github.com/pydantic/pydantic/compare/v1.10.0...v1.10.1
__hash__ method to pydantic.color.Color class, #4454 by @czakiFinally, config customization directly via a dict is now possible, #2557 by @PrettyWood BREAKING CHANGES:
See #4419 for feedback and discussion, docs are live at pydantic-docs.helpmanual.io.
dataclass decorator to really act like its standard lib equivalent.
It hence keeps __eq__, __hash__, ... and makes comparison with its non-validated version possible.
It also fixes usage of frozen dataclasses in fields and usage of default_factory in nested dataclasses.
The support of Config.extra has been added.
Finally, config customization directly via a dict is now possible, #2557 by @PrettyWood
<br/><br/>
BREAKING CHANGES:
compiled boolean (whether pydantic is compiled with cython) has been moved from main.py to version.pyConfig.extra is supported, dataclass ignores by default extra arguments (like BaseModel)__set_name__ protocol in BaseModel for PrivateAttrs, #4407 by @tlambert03parse_env_var in Config, #4406 by @acmiyaguchimaster to main, #4405 by @hramezaniStrictStr does not raise ValidationError when max_length is present in Field, #4388 by @hramezaniSecretStr and SecretBytes hashable, #4387 by @chbndrhnnsStrictBytes does not raise ValidationError when max_length is present in Field, #4380 by @JeanArhancettype, #4375 by @hramezanire.Pattern, #4366 by @hramezani__post_init_post_parse__ is incorrectly passed keyword arguments when no __post_init__ is defined, #4361 by @hramezaniForwardRef and Callable from pydantic.typing instead of typing and also expose MappingIntStrAny, #4358 by @aminalaeeAny types from the dataclass decorator so it can be used with the disallow_any_expr mypy option, #4356 by @DetachHeadpydantic/pydantic, #4348 by @yezz123Extra.forbid is validated multiple times, #4343 by @detachheadoneOf instead of anyOf when generating OpenAPI schema definitions, #4335 by @MaxwellPayneJson type. Json[list[str]] will be now inferred as list[str],
Json[Any] should be used instead of plain Json.
Runtime behaviour is not changed, #4332 by @Bobroniumalias is not None check, rather than bool(alias), #4253 by @sergeytsaplinForwardRefs in Field.outer_type_, #4249 by @JacobHayes__dataclass_transform__ has been replaced by typing_extensions.dataclass_transform, which is the preferred way to mark pydantic models as a dataclass under PEP 681, #4241 by @multimericConfig when validating nested NamedTuple fields, #4219 by @synekBaseModel.construct to work with aliased Fields, #4192 by @kylebamossmart_deepcopy and revert to deepcopy if so, #4184 by @coneybeareConfig.anystr_upper and to_upper kwarg to constr and conbytes, #4165 by @sathelerset and frozenset when they include default values, #4155 by @aminalaee@validator are classmethods, #4102 by @DMRobertsonType[] in schema, #4051 by @aminalaeedefault value in JSON Schema when const=True, #4031 by @aminalaeeallow_inf_nan, #3994 by @tiangoloenv_prefix had characters in common with env_nested_delimiter, #3975 by @arsenroncreate_model, #3945 by @hot123sBaseModel, #3920 by @irgoliccockroachdb, cockroachdb+psycopg2 and cockroachdb+asyncpg, #3839 by @blubber__init__ method in models, #3824 by @patrick91BaseModel instances, #3777 by @PrettyWoodConstrainedDate and condate, #3740 by @hottwajkw_only in dataclasses, #3670 by @detachheadColor class, #3646 by @aminalaeeto_lower_camel() for "non pascal case" camel case, #3463 by @schlerpdefault and default_factory arguments in Mypy plugin, #3430 by @klaa97inspect.signature for BaseModel, #3413 by @fix-inspect-signatureSecretField abstract class so that all the current and future secret fields like SecretStr and SecretBytes will derive from it, #3409 by @expobrainPostgresDsn, #3337 by @rglskSecretsSettingsSource to respect config.case_sensitive, #3273 by @JeanArhancetConfigError when multiple fields are incorrectly set for a single validator, #3215 by @SunsetOrangeFields inside Annotated for TypedDicts required, #3133 by @ezegomezint_validator, #3112 by @ojii__rich_repr__ method to Representation class which enables pretty printing with Rich, #3099 by @willmcguganAnyUrl and descendent types, #3061 by @FaresAhmedbvalidate_arguments decorator now supports alias, #3019 by @MAD-py__dict__ and __weakref__ attributes in AnyUrl and IP address fields, #2890 by @nuno-andreFinal in a field type annotation, #2766 by @uriyyotyping_extensions>=4.1.0 to guarantee dataclass_transform is available, #4424 by @commonismcopy_on_model_validation to reflect recent changes, #4369 by @samuelcolvin__slots__ is passed to create_model, __slots__ is then ignored, #4432 by @samuelcolvinBaseSettings.Config to avoid mypy errors, also correct mypy version compatibility notice in docs, #4450 by @samuelcolvinFull Changelog: https://github.com/pydantic/pydantic/compare/v1.9.0...v1.10.0
Runtime warning if __slots__ is passed to create_model, __slots__ is then ignored, #4432 by @samuelcolvin
__slots__ is passed to create_model, __slots__ is then ignored, #4432 by @samuelcolvinFull Changelog https://github.com/pydantic/pydantic/compare/v1.10.0a2...v1.10.0b1
Update requirement to typing_extensions>=4.1.0 to guarantee dataclass_transform is available, #4424 by @commonism
typing_extensions>=4.1.0 to guarantee dataclass_transform is available, #4424 by @commonismcopy_on_model_validation to reflect recent changes, #4369 by @samuelcolvinFull Changelog https://github.com/pydantic/pydantic/compare/v1.10.0a1...v1.10.0a2
Finally, config customization directly via a dict is now possible, #2557 by @PrettyWood BREAKING CHANGES:
dataclass decorator to really act like its standard lib equivalent.
It hence keeps __eq__, __hash__, ... and makes comparison with its non-validated version possible.
It also fixes usage of frozen dataclasses in fields and usage of default_factory in nested dataclasses.
The support of Config.extra has been added.
Finally, config customization directly via a dict is now possible, #2557 by @PrettyWood
BREAKING CHANGES:
compiled boolean (whether pydantic is compiled with cython) has been moved from main.py to version.pyConfig.extra is supported, dataclass ignores by default extra arguments (like BaseModel)__set_name__ protocol in BaseModel for PrivateAttrs, #4407 by @tlambert03master to main, #4405 by @hramezaniStrictStr does not raise ValidationError when max_length is present in Field, #4388 by @hramezaniSecretStr and SecretBytes hashable, #4387 by @chbndrhnnsStrictBytes does not raise ValidationError when max_length is present in Field, #4380 by @JeanArhancettype, #4375 by @hramezanire.Pattern, #4366 by @hramezani__post_init_post_parse__ is incorrectly passed keyword arguments when no __post_init__ is defined, #4361 by @hramezaniForwardRef and Callable from pydantic.typing instead of typing and also expose MappingIntStrAny, #4358 by @aminalaeeAny types from the dataclass decorator so it can be used with the disallow_any_expr mypy option, #4356 by @DetachHeadpydantic/pydantic, #4348 by @yezz123Extra.forbid is validated multiple times, #4343 by @detachheadoneOf instead of anyOf when generating OpenAPI schema definitions, #4335 by @MaxwellPayneJson type. Json[list[str]] will be now inferred as list[str],
Json[Any] should be used instead of plain Json.
Runtime behaviour is not changed, #4332 by @Bobroniumalias is not None check, rather than bool(alias), #4253 by @sergeytsaplinForwardRefs in Field.outer_type_, #4249 by @JacobHayes__dataclass_transform__ has been replaced by typing_extensions.dataclass_transform, which is the preferred way to mark pydantic models as a dataclass under PEP 681, #4241 by @multimericConfig when validating nested NamedTuple fields, #4219 by @synekBaseModel.construct to work with aliased Fields, #4192 by @kylebamossmart_deepcopy and revert to deepcopy if so, #4184 by @coneybeareConfig.anystr_upper and to_upper kwarg to constr and conbytes, #4165 by @sathelerset and frozenset when they include default values, #4155 by @aminalaee@validator are classmethods, #4102 by @DMRobertsonType[] in schema, #4051 by @aminalaeedefault value in JSON Schema when const=True, #4031 by @aminalaeeallow_inf_nan, #3994 by @tiangoloenv_prefix had characters in common with env_nested_delimiter, #3975 by @arsenroncreate_model, #3945 by @hot123sBaseModel, #3920 by @irgoliccockroachdb, cockroachdb+psycopg2 and cockroachdb+asyncpg, #3839 by @blubber__init__ method in models, #3824 by @patrick91BaseModel instances, #3777 by @PrettyWoodConstrainedDate and condate, #3740 by @hottwajkw_only in dataclasses, #3670 by @detachheadColor class, #3646 by @aminalaeeto_lower_camel() for "non pascal case" camel case, #3463 by @schlerpdefault and default_factory arguments in Mypy plugin, #3430 by @klaa97inspect.signature for BaseModel, #3413 by @fix-inspect-signatureSecretField abstract class so that all the current and future secret fields like SecretStr and SecretBytes will derive from it, #3409 by @expobrainPostgresDsn, #3337 by @rglskSecretsSettingsSource to respect config.case_sensitive, #3273 by @JeanArhancetConfigError when multiple fields are incorrectly set for a single validator, #3215 by @SunsetOrangeFields inside Annotated for TypedDicts required, #3133 by @ezegomezint_validator, #3112 by @ojii__rich_repr__ method to Representation class which enables pretty printing with Rich, #3099 by @willmcguganAnyUrl and descendent types, #3061 by @FaresAhmedbvalidate_arguments decorator now supports alias, #3019 by @MAD-py__dict__ and __weakref__ attributes in AnyUrl and IP address fields, #2890 by @nuno-andreFinal in a field type annotation, #2766 by @uriyyoFull Changelog: https://github.com/pydantic/pydantic/compare/v1.9.0...v1.10a1
Revert Breaking Change: _v1.9.1_ introduced a breaking change where model fields were deep copied by default, this release reverts the default behavio…
Revert Breaking Change: v1.9.1 introduced a breaking change where model fields were
deep copied by default, this release reverts the default behaviour to match v1.9.0 and before,
while also allow deep-copy behaviour via copy_on_model_validation = 'deep'. See #4092 for more information.
Config.copy_on_model_validation is now a str which must be
'none', 'deep', or 'shallow' corresponding to not copying, deep copy & shallow copy; default 'shallow',
#4093 by @timkpaineThank you to pydantic's sponsors: @tiangolo, @stellargraph, @JonasKs, @grillazz, @Mazyod, @kevinalh, @chdsbd, @povilasb, @povilasb, @jina-ai, @mainfra
Thank you to pydantic's sponsors: @tiangolo, @stellargraph, @JonasKs, @grillazz, @Mazyod, @kevinalh, @chdsbd, @povilasb, @povilasb, @jina-ai, @mainframeindustries, @robusta-dev, @SendCloud, @rszamszur, @jodal, @hardbyte, @corleyma, @daddycocoaman, @Rehket, @jokull, @reillysiemens, @westonsteimel, @primer-io, @koxudaxi, @browniebroke, @stradivari96, @adriangb, @kamalgill, @jqueguiner, @dev-zero, @datarootsio, @RedCarpetUp for their kind support.
generics._generic_types_cache and generics._assigned_parameters
to avoid unlimited increase in memory usage, #4083 by @samuelcolvin__isinstancecheck__ on pydantic models when the type is not a model, may also avoid memory "leaks", #4081 by @samuelcolvinFieldInfo that caused problems with PEP 593 type aliases, #4067 by @adriangb__dataclass_transform__ when using pydantic.dataclasses.dataclass, #4006 by @giuliano-oliveiraClassVars in models, #3679 by @samuelcolvinConfig.copy_on_model_validation does a deep copy and not a shallow one, #3641 by @PrettyWoodread_text(encoding='utf-8') for setup.py, #3625 by @hswong3iThank you to pydantic's sponsors: @sthagen, @timdrijvers, @toinbis, @koxudaxi, @ginomempin, @primer-io, @and-semakin, @westonsteimel, @reillysiemens,
Thank you to pydantic's sponsors: @sthagen, @timdrijvers, @toinbis, @koxudaxi, @ginomempin, @primer-io, @and-semakin, @westonsteimel, @reillysiemens, @es3n1n, @jokull, @JonasKs, @Rehket, @corleyma, @daddycocoaman, @hardbyte, @datarootsio, @jodal, @aminalaee, @rafsaf, @jqueguiner, @chdsbd, @kevinalh, @Mazyod, @grillazz, @JonasKs, @simw, @leynier, @xfenix for their kind support.
Config.smart_union for better union logic, #2092 by @PrettyWoodfoo___bar, #3159 by @Air-Mark__dataclass_transform__, #2721 by @tiangoloupdate_forward_refs to Config.json_encodes prevent name clashes in types defined via strings, #3583 by @samuelcolvin0.910, 0.920, 0.921 & 0.930, #3573 & #3594 by @PrettyWood, @christianbundy, @samuelcolvinjson() by default, #3542 by @PrettyWood__root__ attribute from BaseModel, #3540 by @laydayextra fields with model __repr__, #3234 by @cocolmanConfig.copy_on_model_validation always have all fields, #3201 by @PrettyWoodDecimal-specific validation configurations in Field(), additionally to using condecimal(),
to allow better support from editors and tooling, #3507 by @tiangoloarm64 binaries suitable for MacOS with an M1 CPU to PyPI, #3498 by @samuelcolvinNone was considered invalid when using a Union type containing Any or object, #3444 by @tharradinefield argument (of type
pydantic.fields.ModelField) to __modify_schema__() if present, #3434 by @jasujmtyping.ClassVar string type annotation, #3401 by @uriyyotyping_extensions.TypedDict, #3374 by @BvB93name_must_contain_space to value_must_equal_bar, #3327 by @michaelrios28AmqpDsn class, #3254 by @kludexEnum value as default in generated JSON schema, #3190 by @joaommartinsvalidate_arguments now supports extra customization (used to always be Extra.forbid), #3161 by @PrettyWoodpydantic.utils.is_valid_field so that it ignores untyped private variables, #3146 by @hi-ogawavalidate_arguments issue with Config.validate_all, #3135 by @PrettyWoodobject type, #3062 by @PrettyWood_special properties on parent classes, #3043 by @zulrangTypedDict class for error objects, #3038 by @matthewhughes934create_model_from_typeddict mypy compliant, #3008 by @PrettyWoodPrivateAttr, #2989 by @hmvpUnion type with a complex subfield, #2936 by @cbartzStrictStr permitting Enum values where the enum inherits from str, #2929 by @samuelcolvinSecretsSettingsSource parse values being assigned to fields of complex types when sourced from a secrets file,
just as when sourced from environment variables, #2917 by @davidmreedpydantic-mypy plugin compatible with pyproject.toml configuration, consistent with mypy changes.
See the doc for more information, #2908 by @jrwalkJson[T], #2860 by @geekingfrogDeque fields, #2810 by @sergejkozinLiteral, #2794 by @PrettyWoodNamedTuple and TypedDict when they're used directly as the type of fields
within Pydantic models, #2760 by @jameysharpmypy plugin fails on construct method call for BaseSettings derived classes, #2753 by @uriyyopydantic.create_model function, #2748 by @uriyyoschema to schema_ to avoid shadowing of global variable name, #2724 by @shahriyarr__dataclass_transform__, #2721 by @tiangoloBaseConfig and handle max_length = 0, #2719 by @PrettyWoodorm_mode checking to allow recursive ORM mode parsing with dicts, #2718 by @nuno-andreNamedTuple and has a default value, #2707 by @PrettyWoodEnum fields now properly support extra kwargs in schema generation, #2697 by @sammchardyuniqueItems option to ConstrainedList, #2618 by @nuno-andre__version__ attribute to pydantic module, #2572 by @paxcodespostgresql+asyncpg, postgresql+pg8000, postgresql+psycopg2, postgresql+psycopg2cffi, postgresql+py-postgresql
and postgresql+pygresql schemes for PostgresDsn, #2567 by @postgres-asyncpgdecimal_places argument is specified, #2524 by @cwe5590collections.abc.Callable to be used as type in python 3.9, #2519 by @daviskirksetup.py
to allow for custom CFLAGS when compiling, #2517 by @peterroelantsdefault_factory to run it only once even if Config.validate_all is set, #2515 by @PrettyWoodAnyUrl hosts. This allows urls with DNS labels
looking like IPs to validate as they are perfectly valid host names, #2512 by @sbv-csisminItems and maxItems in generated JSON schema for fixed-length tuples, #2497 by @PrettyWoodstrict argument to conbytes, #2489 by @koxudaxiGetterDict to docs, #2463 by @nuno-andreKafkaDsn type, HttpUrl now has default port 80 for http and 443 for https, #2447 by @MihanixAPastDate and FutureDate types, #2425 by @KludexGeneric fields with subtypes, #2375 by @maximbergNameEmail to str, #2341 by @alecgeronaConfig.smart_union to prevent coercion in Union if possible, see
the doc for more information, #2092 by @PrettyWoodtyping.Counter as a model field type, #2060 by @uriyyo__bases__ when constructing new parameterised classes, so that A <: B => A[int] <: B[int], #2007 by @diabolo-danFileUrl type that allows URLs that conform to RFC 8089.
Add host_required parameter, which is True by default (AnyUrl and subclasses), False in RedisDsn, FileUrl, #1983 by @vgerakconfrozenset(), analogous to conset() and conlist(), #1897 by @PrettyWoodroot_validator if overridden, #1895 by @PrettyWoodrepr (defaults to True) parameter to Field, to hide it from the default representation of the BaseModel, #1831 by @fnepsupport generic models with discriminated union, #3551 by @PrettyWood
json() by default, #3542 by @PrettyWood__root__ attribute from BaseModel, #3540 by @laydayextra fields with model __repr__, #3234 by @cocolmanConfig.copy_on_model_validation always have all fields, #3201 by @PrettyWoodFull Changelog: https://github.com/samuelcolvin/pydantic/compare/v1.9.0a1...v1.9.0a2
Discussion and feedback: #3538
Thank you to pydantic's sponsors: @timdrijvers, @toinbis, @koxudaxi, @ginomempin, @primer-io, @and-semakin, @westonsteimel, @reillysiemens, @es3n1n, @
See Changelog.
Thank you to pydantic's sponsors: @timdrijvers, @toinbis, @koxudaxi, @ginomempin, @primer-io, @and-semakin, @westonsteimel, @reillysiemens, @es3n1n, @jokull, @JonasKs, @Rehket, @corleyma, @daddycocoaman, @hardbyte, @datarootsio, @jodal, @aminalaee, @rafsaf, @jqueguiner, @chdsbd, @kevinalh, @Mazyod, @grillazz, @JonasKs for their kind support.
Config.smart_union for better union logic, #2092 by @PrettyWoodfoo___bar, #3159 by @Air-Mark__dataclass_transform__, #2721 by @tiangoloDecimal-specific validation configurations in Field(), additionally to using condecimal(),
to allow better support from editors and tooling, #3507 by @tiangoloarm64 binaries suitable for MacOS with an M1 CPU to PyPI, #3498 by @samuelcolvinNone was considered invalid when using a Union type containing Any or object, #3444 by @tharradinefield argument (of type
pydantic.fields.ModelField) to __modify_schema__() if present, #3434 by @jasujmtyping.ClassVar string type annotation, #3401 by @uriyyotyping_extensions.TypedDict, #3374 by @BvB93name_must_contain_space to value_must_equal_bar, #3327 by @michaelrios28AmqpDsn class, #3254 by @kludexEnum value as default in generated JSON schema, #3190 by @joaommartinsvalidate_arguments now supports extra customization (used to always be Extra.forbid), #3161 by @PrettyWoodpydantic.utils.is_valid_field so that it ignores untyped private variables, #3146 by @hi-ogawavalidate_arguments issue with Config.validate_all, #3135 by @PrettyWoodobject type, #3062 by @PrettyWood_special properties on parent classes, #3043 by @zulrangTypedDict class for error objects, #3038 by @matthewhughes934create_model_from_typeddict mypy compliant, #3008 by @PrettyWoodPrivateAttr, #2989 by @hmvpUnion type with a complex subfield, #2936 by @cbartzStrictStr permitting Enum values where the enum inherits from str, #2929 by @samuelcolvinSecretsSettingsSource parse values being assigned to fields of complex types when sourced from a secrets file,
just as when sourced from environment variables, #2917 by @davidmreedpydantic-mypy plugin compatible with pyproject.toml configuration, consistent with mypy changes.
See the doc for more information, #2908 by @jrwalkJson[T], #2860 by @geekingfrogDeque fields, #2810 by @sergejkozinLiteral, #2794 by @PrettyWoodNamedTuple and TypedDict when they're used directly as the type of fields
within Pydantic models, #2760 by @jameysharpmypy plugin fails on construct method call for BaseSettings derived classes, #2753 by @uriyyopydantic.create_model function, #2748 by @uriyyoschema to schema_ to avoid shadowing of global variable name, #2724 by @shahriyarr__dataclass_transform__, #2721 by @tiangoloBaseConfig and handle max_length = 0, #2719 by @PrettyWoodorm_mode checking to allow recursive ORM mode parsing with dicts, #2718 by @nuno-andreNamedTuple and has a default value, #2707 by @PrettyWoodEnum fields now properly support extra kwargs in schema generation, #2697 by @sammchardyuniqueItems option to ConstrainedList, #2618 by @nuno-andre__version__ attribute to pydantic module, #2572 by @paxcodespostgresql+asyncpg, postgresql+pg8000, postgresql+psycopg2, postgresql+psycopg2cffi, postgresql+py-postgresql
and postgresql+pygresql schemes for PostgresDsn, #2567 by @postgres-asyncpgdecimal_places argument is specified, #2524 by @cwe5590collections.abc.Callable to be used as type in python 3.9, #2519 by @daviskirksetup.py
to allow for custom CFLAGS when compiling, #2517 by @peterroelantsdefault_factory to run it only once even if Config.validate_all is set, #2515 by @PrettyWoodAnyUrl hosts. This allows urls with DNS labels
looking like IPs to validate as they are perfectly valid host names, #2512 by @sbv-csisminItems and maxItems in generated JSON schema for fixed-length tuples, #2497 by @PrettyWoodstrict argument to conbytes, #2489 by @koxudaxiGetterDict to docs, #2463 by @nuno-andreKafkaDsn type, HttpUrl now has default port 80 for http and 443 for https, #2447 by @MihanixAPastDate and FutureDate types, #2425 by @KludexGeneric fields with subtypes, #2375 by @maximbergNameEmail to str, #2341 by @alecgeronaConfig.smart_union to prevent coercion in Union if possible, see
the doc for more information, #2092 by @PrettyWoodtyping.Counter as a model field type, #2060 by @uriyyo__bases__ when constructing new parameterised classes, so that A <: B => A[int] <: B[int], #2007 by @diabolo-danFileUrl type that allows URLs that conform to RFC 8089.
Add host_required parameter, which is True by default (AnyUrl and subclasses), False in RedisDsn, FileUrl, #1983 by @vgerakconfrozenset(), analogous to conset() and conlist(), #1897 by @PrettyWoodroot_validator if overridden, #1895 by @PrettyWoodrepr (defaults to True) parameter to Field, to hide it from the default representation of the BaseModel, #1831 by @fnep.dict / .json export time, #660 by @daviskirkFull List of changes: https://github.com/samuelcolvin/pydantic/compare/v1.8.2...v1.9.0a1
A security vulnerability, level "moderate" is fixed in v1.8.2. Please upgrade ASAP. See security advisory CVE-2021-29510.
See Changelog.
A security vulnerability, level "moderate" is fixed in v1.8.2. Please upgrade ASAP. See security advisory CVE-2021-29510.
date and datetime parsing so passing either 'infinity' or float('inf')
(or their negative values) does not cause an infinite loop,
see security advisory CVE-2021-29510Literal of an enum member, #2536 by @PrettyWoodjson_encoders in class kwargs, #2521 by @layday__eq__, #2483 by @PrettyWoodAnnotated in validate_arguments and in generic models with python 3.9, #2483 by @PrettyWoodBug fixes for regressions and new features in v1.8
See Changelog.
Bug fixes for regressions and new features in v1.8
Config.field to update elements of a Field, #2461 by @samuelcolvinBaseModel field and a custom root type, #2449 by @PrettyWoodPattern encoder to fastapi, #2444 by @PrettyWoodmultiple_of argument is specified, #2442 by @tobi-lipede-oodleRecursionError when using some types like Enum or Literal with generic models, #2436 by @PrettyWood__hash__ in subclasses of a model, #2422 by @PrettyWoodmypy complaints on Path and UUID related custom types, #2418 by @PrettyWoodBreaking Change, remove old deprecation aliases from v1, #2415 by @samuelcolvin:
See Changelog.
Thank you to pydantic's sponsors: @jorgecarleitao, @BCarley, @chdsbd, @tiangolo, @matin, @linusg, @kevinalh, @koxudaxi, @timdrijvers, @mkeen, @meadsteve, @ginomempin, @primer-io, @and-semakin, @tomthorogood, @AjitZK, @westonsteimel, @Mazyod, @christippett, @CarlosDomingues, @Kludex, @r-m-n for their kind support.
NamedTuple and TypedDict, #2216 by @PrettyWoodAnnotated hints on model fields, #2147 by @JacobHayesfrozen parameter on Config to allow models to be hashed, #1880 by @rhuilleSchema which was replaced by FieldConfig.case_insensitive which was replaced by Config.case_sensitive (default False)Config.allow_population_by_alias which was replaced by Config.allow_population_by_field_namemodel.fields which was replaced by model.__fields__model.to_string() which was replaced by str(model)model.__values__ which was replaced by model.__dict__each_item.
There were indeed some edge cases with some compound types where the validated items were the last sublevel ones, #1933 by @PrettyWoodutils.lenient_issubclass to handle typing.GenericAlias objects like list[str] in python >= 3.9, #2399 by @daviskirkdataclass by allowing the usage of pydantic Field or 'metadata' kwarg of dataclasses.field, #2384 by @PrettyWoodtyping-extensions a required dependency, #2368 by @samuelcolvinresolve_annotations more lenient, allowing for missing modules, #2363 by @samuelcolvinMapping subclasses from always being coerced to dict, #2325 by @ofekNone for type Optional[conset / conlist], #2320 by @PrettyWoodpython_requires metadata to require >=3.6.1, #2306 by @hukkinj1Decimal with, or without any decimal places, #2293 by @hultner__fields_set__ in BaseModel.copy(update=…), #2290 by @PrettyWoodBaseModel.construct(), #2281 by @PrettyWoodvalidate_decorator so **kwargs doesn't exclude values when the keyword
has the same name as the *args or **kwargs names, #2251 by @cybojenixvalidate_arguments, as per behaviour with native functions, #2249 by @cybojenixcon* type functions, #2242 by @tayoogunbiyi__root__) when using parse_obj() with nested models, #2238 by @PrettyWood__root__) with from_orm(), #2237 by @PrettyWoodNamedTuple and TypedDict types.
Those two types are now handled and validated when used inside BaseModel or pydantic dataclass.
Two utils are also added create_model_from_namedtuple and create_model_from_typeddict, #2216 by @PrettyWoodUnion[Type[...], ...], #2213 by @PrettyWoodTypeError when a root_validator does not return a dict (e.g. None), #2209 by @masalim2FrozenSet[str] type annotation to the allowed_schemes argument on the strict_url field type, #2198 by @Midnighterallow_mutation constraint to Field, #2195 by @sblack-usuField with a default_factory to be used as an argument to a function
decorated with validate_arguments, #2176 by @thomascobbLiteral field type, #2166 by @PrettyWoodtyping.Annotated hints on model fields. A Field may now be set in the type hint with Annotated[..., Field(...); all other annotations are ignored but still visible with get_type_hints(..., include_extras=True), #2147 by @JacobHayesStrictBytes type as well as strict=False option to ConstrainedBytes, #2136 by @rlizzoConfig.anystr_lower and to_lower kwarg to constr and conbytes, #2134 by @tayoogunbiyityping.Tuple type, #2132 by @PrettyWoodvalidate to functions decorated with validate_arguments
to validate parameters without actually calling the function, #2127 by @PrettyWoodNone, NoneType or Literal[None], #2095 by @PrettyWoodCallable with a default value, #2094 by @PrettyWoodcreate_model return type annotation to return type which inherits from __base__ argument, #2071 by @uriyyojson_encoders inheritance, #2064 by @art049ClassVars in sub-models without having to re-annotate them, #2061 by @laydayPattern type, #2045 by @PrettyWoodNonNegativeInt, NonPositiveInt, NonNegativeFloat, NonPositiveFloat, #1975 by @mdavis-xyzKeyError to be raised when building schema from multiple BaseModel with the same names declared in separate classes, #1912 by @JSextonnrediss (Redis over SSL) protocol to RedisDsn
Allow URLs without user part (e.g., rediss://:pass@localhost), #1911 by @TrDexfrozen boolean parameter to Config (default: False).
Setting frozen=True does everything that allow_mutation=False does, and also generates a __hash__() method for the model. This makes instances of the model potentially hashable if all the attributes are hashable, #1880 by @rhuillePaymentCardNumber type, #1416 by @AlexanderSovRecursionError while using recursive GenericModels, #1370 by @xpptenum for typing.Literal in JSON schema, #1350 by @PrettyWoodupdate_forward_refs and silently behaved incorrectly, #1201 by @PrettyWooda: List[T] are considered to be concrete. This allows these models to be subclassed and composed as expected, #947 by @daviskirkConfig.copy_on_model_validation flag. When set to False, pydantic will keep models used as fields
untouched on validation instead of reconstructing (copying) them, #265 by @PrettyWood…cause an infinite loop, see security advisory CVE-2021-29510.
Security fix: Fix date and datetime parsing so passing either 'infinity' or float('inf') (or their negative values) does not cause an infinite loop, see security advisory CVE-2021-29510.
Thank you to pydantic's sponsors: @timdrijvers, @BCarley, @chdsbd, @tiangolo, @matin, @linusg, @kevinalh, @jorgecarleitao, @koxudaxi, @primer-api, @mk
See Changelog.
Thank you to pydantic's sponsors: @timdrijvers, @BCarley, @chdsbd, @tiangolo, @matin, @linusg, @kevinalh, @jorgecarleitao, @koxudaxi, @primer-api, @mkeen, @meadsteve for their kind support.
underscore_attrs_are_private with generic models, #2138 by @PrettyWoodroot_validator when validate_assignment is on, #2116 by @PrettyWoodpydantic.dataclasses.dataclass dynamically created from a built-in dataclasses.dataclass, #2111 by @aimestereo__doc__ as private attribute when Config.underscore_attrs_are_private is set, #2090 by @PrettyWoodThank you to pydantic's sponsors: @timdrijvers, @BCarley, @chdsbd, @tiangolo, @matin, @linusg, @kevinalh, @jorgecarleitao, @koxudaxi, @primer-api, @mk
See Changelog.
Thank you to pydantic's sponsors: @timdrijvers, @BCarley, @chdsbd, @tiangolo, @matin, @linusg, @kevinalh, @jorgecarleitao, @koxudaxi, @primer-api, @mkeen for their kind support.
GenericModel concrete model creation, allow GenericModel concrete name reusing in module, #2078 by @MrMrRobatvalidate_assignment is set, #2073 by @PrettyWooddataclass when converted into pydantic dataclass, #2065 by @PrettyWoodThank you to pydantic's sponsors: @timdrijvers, @BCarley, @chdsbd, @tiangolo, @matin, @linusg, @kevinalh, @jorgecarleitao, @koxudaxi, @primer-api, @mk
See Changelog.
Thank you to pydantic's sponsors: @timdrijvers, @BCarley, @chdsbd, @tiangolo, @matin, @linusg, @kevinalh, @jorgecarleitao, @koxudaxi, @primer-api, @mkeen for their kind support.
validate_arguments when passing configuration as argument, #2055 by @laydayPrivateAttr, #2048 by @aphedgesunderscore_attrs_are_private causing TypeError when overriding __init__, #2047 by @samuelcolvinvalidate_assignment=True, #2044 by @johnsabathdataclass can inherit from stdlib dataclass and Config.arbitrary_types_allowed is supported, #2042 by @PrettyWoodBreaking Change: remove __field_defaults__, add default_factory support with BaseModel.construct. Use .get_default() method on fields in __fields__ at…
See Changelog.
Thank you to pydantic's sponsors: @timdrijvers, @BCarley, @chdsbd, @tiangolo, @matin, @linusg, @kevinalh, @jorgecarleitao, @koxudaxi, @primer-api for their kind support.
BaseSettings, thanks @mdgilene__field_defaults__, add default_factory support with BaseModel.construct.
Use .get_default() method on fields in __fields__ attribute instead, #1732 by @PrettyWoodvalues parameter type in BaseModel.__setattr__,
when validate_assignment = True in model config, #1999 by @me-ranshfields.Undefined to be a singleton object, fixing inherited generic model schemas, #1981 by @daviskirkmin_length/max_length constraints with secret types, #1974 by @uriyyoroot_validators when validate_assignment is on, #1971 by @PrettyWooddeque to field types, #1935 by @wozniaktyBaseSettings to read "secret files", #1820 by @mdgileneparse_raw_as utility function, #1812 by @PrettyWooddotenv files (e.g. ~/.env), #1803 by @PrettyWoodparse_file to show that the argument
should be a file path not a file-like object, #1794 by @mdavis-xyzBaseModel is named Model, #1770 by @selimbLiteral Enums when use_enum_values is True, #1747 by @noelevansZ for UTC
or an offset for absolute positive or negative time shifts. Or the timezone data can be omitted, #1744 by @noelevans__init__ with python 3.6 signature for ForwardRef, #1738 by @sirtelemakEnum and IntEnum as valid types for fields, #1735 by @PrettyWood__module__ argument of create_model from None to 'pydantic.main'.
Set reference of created concrete model to it's module to allow pickling (not applied to models created in
functions), #1686 by @MrMrRobatconfig to @validate_arguments, #1663 by @samuelcolvinenv in their Config. Previously only env_prefix configuration option was applicable, #1561 by @ojomioref_template when creating schema $refs, #1479 by @kilo59__call__ stub to PyObject so that mypy will know that it is callable, #1352 by @brianmaissypydantic.dataclasses.dataclass decorator now supports built-in dataclasses.dataclass.
It is hence possible to convert an existing dataclass easily to add pydantic validation.
Moreover nested dataclasses are also supported, #744 by @PrettyWood…cause an infinite loop, see security advisory CVE-2021-29510.
Security fix: Fix date and datetime parsing so passing either 'infinity' or float('inf') (or their negative values) does not cause an infinite loop, see security advisory CVE-2021-29510.
Thank you to pydantic's sponsors: @matin, @tiangolo, @chdsbd, @jorgecarleitao, and 1 anonymous sponsor for their kind support.
See Changelog.
Thank you to pydantic's sponsors: @matin, @tiangolo, @chdsbd, @jorgecarleitao, and 1 anonymous sponsor for their kind support.
changes:
default_factory, #1710 by @PrettyWoodThank you to pydantic's sponsors: @matin, @tiangolo, @chdsbd, @jorgecarleitao, and 1 anonymous sponsor for their kind support.
See Changelog.
Thank you to pydantic's sponsors: @matin, @tiangolo, @chdsbd, @jorgecarleitao, and 1 anonymous sponsor for their kind support.
changes:
conlist and conset to not have always=True, #1682 by @samuelcolvinAnyUrl (can't exceed 65536) ports are 16 insigned bits: 0 <= port <= 2**16-1 src: rfc793 header format, #1654 by @flapiliregex anchoring semantics, #1648 by @yurikhanchain.from_iterable in class_validators.py. This is a faster and more idiomatic way of using itertools.chain.
Instead of computing all the items in the iterable and storing them in memory, they are computed one-by-one and never
stored as a huge list. This can save on both runtime and memory space, #1642 by @cool-RRconset(), analogous to conlist(), #1623 by @patrickkwangdotenv files, #1615 by @PrettyWoodSchemaExtraCallable is always defined to get type hints on BaseConfig, #1614 by @PrettyWoodAnyType alias for Type[Any], #1598 by @samuelcolvin__modify_schema__ on Enums apply to the enum schema rather than fields that use the enum, #1581 by @therefromhere__all__ key when used in conjunction with index keys in advanced include/exclude of fields that are sequences, #1579 by @xspirusList field defined in a parent class when each_item=True. Added an example to the docs illustrating this, #1566 by @samueldeklundschema.field_class_to_schema to support frozenset in schema, #1557 by @wangpeibao__modify_schema__ only for the field schema, #1552 by @PrettyWoodfield.validate_always in fields.py so the always parameter of validators work on inheritance, #1545 by @dcHHHb'\x12\x34\x56\x78' * 4. This was done to support BINARY(16) columns in sqlalchemy, #1541 by @shawnwalldefault_factory can return a singleton, #1523 by @therefromhereNameEmail.__eq__ so duplicate NameEmail instances are evaluated as equal, #1514 by @stephen-bunndefault_factory by calling it only once
if possible and by not setting a default value in the schema, #1491 by @PrettyWoodBaseModel.__signature__ class-only, so getting __signature__ from model instance will raise AttributeError, #1466 by @MrMrRobat'format': 'password' in the schema for secret types, #1424 by @atheuzConstrainedFloat so that exclusiveMinimum and
minimum are not included in the schema if they are equal to -math.inf and
exclusiveMaximum and maximum are not included if they are equal to math.inf, #1417 by @vdwees__root__ dicts in .dict() (and, by extension, in .json()), #1414 by @patrickkwangconst validator to post-validators so it validates the parsed value, #1410 by @selimbLiteral['foo', Literal['bar']], #1364 by @DBCerigouser_required = True from RedisDsn, neither user nor password are required, #1275 by @samuelcolvinallOf from schema for fields with Union and custom Field, #1209 by @mostaphaRoudsari$ref
property to point to the enum definition, #1173 by @calvinwyoungSignature generation with extra: allow never uses a field name, #1418 by @prettywood
See Changelog.
extra: allow never uses a field name, #1418 by @prettywoodField default value, #1412 by @prettywoodMake includes/excludes arguments for .dict(), ._iter(), ..., immutable, #1404 by @AlexECX
See Changelog.
.dict(), ._iter(), ..., immutable, #1404 by @AlexECXmodel._iter(), regardless of by_alias, #1397 by @AlexECXmodel.copy() does make a shallow copy of attributes, #1383 by @samuelcolvinmodel_name argument of main.create_model() to __model_name to allow using model_name as a field name, #1367 by @kittipatvtyping_extensions dependency for python 3.8, #1342 by @prettywoodSecretStr and SecretBytes initialization idempotent, #1330 by @atheuzPaymentCardNumber, PaymentCardBrand now inherits from str, #1317 by @samuelcolvinBaseModel inherit from Representation to make mypy happy when overriding __str__, #1310 by @FuegoFroNone as input to all optional list fields, #1307 by @prettywooddatetime field to default_factory example, #1301 by @StephenBrown2'__all__', #1286 by @masalim2Optional, so that these are valid mypy annotations, #1248 by @kokespattern_validator() accept pre-compiled Pattern objects. Fix str_validator() return type to str, #1237 by @adamgregupdate_forward_refs() method of BaseModel now copies __dict__ of class module instead of modifying it, #1228 by @paul-ilyin@validate_arguments, #1222 by @samuelcolvindefault_factory argument to Field to create a dynamic default value by passing a zero-argument callable, #1210 by @prettywoodNewType of List, Optional, etc, #1207 by @Kazyroot_validator, #1192 by @samuelcolvinvalidate_arguments function decorator which checks the arguments to a function matches type annotations, #1179 by @samuelcolvin__signature__ to models, #1034 by @MrMrRobat._iter() method, 10x speed boost for dict(model), #1017 by @MrMrRobatBreaking Change: alias precedence logic changed so aliases on a field always take priority over an alias from alias_generator to avoid buggy/unexpecte…
See Changelog.
alias_generator to avoid buggy/unexpected behaviour,
see here for details, #1178 by @samuelcolvincls argument in validators during assignment, #1172 by @samuelcolvinPaymentCardNumber, #1166 by @cuencandres__get_validators__ like a custom data type, #1159 by @tiangoloIterable, #1152 by @tiangolourl_regex to accept schemas with +, - and . after the first character, #1142 by @samuelcolvinversion_info() to version.py, suggest its use in issues, #1138 by @samuelcolvinEmailStr and NameEmail to accept instances of themselves in cython, #1126 by @koxudaxiConfig.schema_extra callable, #1125 by @therefromhere__all__ to __init__.py to prevent "implicit reexport" errors from mypy, #1072 by @samuelcolvinBaseSettings, #1011 by @acnebsChange schema and schema_model to handle dataclasses by using their __pydantic_model__ feature, #792 by @aviramha
See Changelog.
schema and schema_model to handle dataclasses by using their __pydantic_model__ feature, #792 by @aviramharoot_validator to be skipped if values validation fails using keyword skip_on_failure=True, #1049 by @aviramhaConfig.schema_extra to be a callable so that the generated schema can be post-processed, #1054 by @selimb__schema_attributes__ is True, #1064 by @samuelcolvinBaseModel.parse_file to use Config.json_loads, #1067 by @kierandarcyJson fields, #1073 by @volker48CYTHON_NTHREADS environment variable, #1074 by @samuelcolvin__eq__ to SecretStr and SecretBytes to allow "value equals", #1079 by @sbv-trueenergyConfig inheritance on BaseSettings when used with env_prefix, #1091 by @samuelcolvin__modify_schema__ when it conflicted with field_class_to_schema*, #1102 by @samuelcolvinBaseSettings subclass attributes, #1105 by @tribalsAdd benchmarks for cattrs, #513 by @sebastianmika
See Changelog.
cattrs, #513 by @sebastianmikaexclude_none option to dict() and friends, #587 by @niknetnikovalideer, #670 by @gsakkisparse_obj_as and parse_file_as functions for ad-hoc parsing of data into arbitrary pydantic-compatible types, #934 by @dmontaguallow_reuse argument to validators, thus allowing validator reuse, #940 by @dmontaguByteSize type for converting byte string (1GB) to plain bytes, #977 by @dgasmith@root_validator(pre=True), #984 by @samuelcolvin__str__ and __repr__ inheritance for models, #1022 by @samuelcolvintyping.Literal for Python 3.8, #1026 by @dmontaguOptional with name: Optional[AnyType] = Field(...) and refactor ModelField creation to preserve required parameter value, #1031 by @tiangoloFix bug where use of complex fields on sub-models could cause fields to be incorrectly configured, #1015 by @samuelcolvin
See Changelog.
Add a mypy plugin for type checking BaseModel.__init__ and more, #722 by @dmontagu
See Changelog.
BaseModel.__init__ and more, #722 by @dmontaguGenericModel.__class_getitem__ to prevent PyCharm warnings, #936 by @dmontaguAny to allow None, also support TypeVar thus allowing use of un-parameterised collection types
e.g. Dict and List, #962 by @samuelcolvinFieldInfo on subfields to fix schema generation for complex nested types, #965 by @samuelcolvinBreaking Change: deprecate the Model.fields property, use Model.__fields__ instead, #883 by @samuelcolvin
See Changelog.
Model.fields property, use Model.__fields__ instead, #883 by @samuelcolvinalias_generator, #904 by @samuelcolvinskip_defaults to exclude_unset, and add ability to exclude actual defaults, #915 by @dmontagu**kwargs to pydantic.main.ModelMetaclass.__new__ so __init_subclass__ can take custom parameters on extended
BaseModel classes, #867 by @retniktFutureWarning instead of DeprecationWarning when alias instead of env is used for settings models, #881 by @samuelcolvinBaseSettings inheritance and alias getting set to None, #882 by @samuelcolvin__repr__ and __str__ methods to be consistent across all public classes, add __pretty__ to support
python-devtools, #884 by @samuelcolvincase_insensitive on BaseSettings config, #885 by @samuelcolvinBaseSettings merge environment variables and in-code values recursively, as long as they create a valid object
when merged together, to allow splitting init arguments, #888 by @idmitrievskyModel.construct() to be more user-friendly, document construct() usage, #898 by @samuelcolvinconstruct() method, #907 by @ashearsField constraints on complex types, raise an error if constraints are not enforceable,
also support tuples with an ellipsis Tuple[X, ...], Sequence and FrozenSet in schema, #909 by @samuelcolvinstr/repr logic for ModelField, #912 by @samuelcolvinConstrainedList, update schema generation to reflect min_items and max_items Field() arguments, #917 by @samuelcolvininclude and exclude arguments of dict(), #921 by @samuelcolvinValidationError.json() by using pydantic_encoder, #922 by @samuelcolvinremove_untouched, improve error message for types with no validators, #926 by @retniktMark StrictBool typecheck as bool to allow for default values without mypy errors, #690 by @dmontagu
StrictBool typecheck as bool to allow for default values without mypy errors, #690 by @dmontaguGenericModel subclasses, #859 by @dmontaguif TYPE_CHECKING: to the excluded lines for test coverage, #874 by @dmontaguallow_population_by_alias to allow_population_by_field_name, remove unnecessary warning about it, #875 by @samuelcolvinsee HISTORY.md
see HISTORY.rst
see HISTORY.rst
Schema to Field, make it a function to placate mypy, #577 by @samuelcolvinbool, #617 by @dmontaguget_validators is no longer recognised, use __get_validators__.
Config.ignore_extra and Config.allow_extra are no longer recognised, use Config.extra, #720 by @samuelcolvinBaseSettings; case_insensitive renamed to case_sensitive,
default changed to case_sensitive = False, env_prefix default changed to '' - e.g. no prefix, #721 by @dmontaguroot_validator and rename root errors from __obj__ to __root__, #729 by @samuelcolvindict(model) so that sub-models are no longer
converted to dictionaries, #733 by @samuelcolvininitvars support to post_init_post_parse, #748 by @Raphael-C-AlmeidaBaseModel.json() only serialize the __root__ key for models with custom root, #752 by @dmontaguURL parsing logic, #755 by @samuelcolvinBaseSettings now uses the special env settings to define which environment variables to
read, not aliases, #847 by @samuelcolvinassert statements inside validators, #653 by @abduscopydantic.dataclasses.dataclass and subclassing pydantic.BaseModel, #710 by @maddosaurusjson_loads and json_dumps Config properties, #714 by @samuelcolvinmypy integration, #735 by @dmontagu__repr__ method to ErrorWrapper, #738 by @samuelcolvinFrozenSet members in dataclasses, and a better error when attempting to use types from the typing module that are not supported by Pydantic, #745 by @djpettipydantic.typing, #761 by @samuelcolvinErrorWrapper, ValidationError and datetime parsing, #763 by @samuelcolvindatetime/date/time/timedelta types: more descriptive errors,
change errors to value_error not type_error, support bytes, #766 by @samuelcolvinLiteral types with multiple allowed values, #770 by @dmontagutitle field in JSON schema by converting underscore to space, #772 by @skewtymypy --no-implicit-reexport for dataclasses, also respect --no-implicit-reexport in pydantic itself, #783 by @samuelcolvinPaymentCardNumber type, #790 by @matinadditionalProperties to false in schema for models with extra fields disallowed, #796 by @Code0x58EmailStr validation method now returns local part case-sensitive per RFC 5321, #798 by @henriklindgrenConstrainedFloat, ConstrainedInt and ConstrainedStr and added
StrictFloat and StrictInt classes, #799 by @DerRiddaNone and Optional, replace whole with each_item (inverse meaning, default False)
on validators, #803 by @samuelcolvinType[T] type hints, #807 by @timonbimonchange_exceptions, change how pydantic error are constructed, #819 by @samuelcolvinBaseModel-type model field causes a ValidationError during parsing, #820 by @dmontagugetter_dict on Config, modify GetterDict to be more like a Mapping object and thus easier to work with, #821 by @samuelcolvinTypeVar param on base GenericModel class, #842 by @zpencerqModel._schema_cache -> Model.__schema_cache__, Model._json_encoder -> Model.__json_encoder__,
Model._custom_root_type -> Model.__custom_root_type__, #851 by @samuelcolvinfix __post_init__ usage with dataclass inheritance, fix #739 by @samuelcolvin
__post_init__ usage with dataclass inheritance, fix #739 by @samuelcolvinSchema on GenericModel fields, #754 by @amitblOne column per quarter.