mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
7d9614e3f8811c624cdce11867bb8bd607fef5b8
* Refactor ._iter() method: Moved all keys-related stuff (include, exclude, etc.) to ._iter() Removed redundant iteration through default values Almost all arguments checks moved out of loops, so checks happen once Fast yield from .__dict__ on plain .iter() (x10 boost) Removed redundant set(dict.keys()) in ._calculate_keys() * Moved back from nested generator checks to checks, optimized copy a bit * Bump pytest-mock from 1.12.0 to 1.12.1 (#1018) Bumps [pytest-mock](https://github.com/pytest-dev/pytest-mock) from 1.12.0 to 1.12.1. - [Release notes](https://github.com/pytest-dev/pytest-mock/releases) - [Changelog](https://github.com/pytest-dev/pytest-mock/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-mock/compare/v1.12.0...v1.12.1) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * __str__ and __repr__ inheritance for models, fix #1022 (#1023) * add testimonials section to docs with reference to python bytes podcast episode (#1025) * add testimonials section with reference to python bytes podcast episode * added description to changes directory * Bump twine from 3.0.0 to 3.1.0 (#1029) Bumps [twine](https://github.com/pypa/twine) from 3.0.0 to 3.1.0. - [Release notes](https://github.com/pypa/twine/releases) - [Changelog](https://github.com/pypa/twine/blob/master/docs/changelog.rst) - [Commits](https://github.com/pypa/twine/compare/3.0.0...3.1.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * Support typing.Literal in python 3.8 (#1027) * Support typing.Literal in python 3.8 * Improve import pattern for Literal * Update references to in docs * Try to get build to pass * Add support for mapping types as custom root (#958) * Add support for mapping types as custom root * Incorporate feedback * Add changes * Incorporate feedback * Add docs and tests * Fix linting issue * Incorporate more feedback * Add more specific match * Add parse_as_type function (#934) * Add parse_as_type function * Add changes * Incorporate feedback * Add naming tests * Fix double quotes * Fix docs example * Reorder parameters; add dataclass and mapping tests * Rename parse_as_type to parse_obj, and add parse_file * Incorporate feedback * Incorporate feedback * use custom root types * Add better support for validator reuse (#941) * Add better support for validator reuse * Clean up classmethod unpacking * Add changes * Fix coverage check * Make 3.8 compatible * Update changes/940-dmontagu.md Co-Authored-By: Samuel Colvin <s@muelcolvin.com> * Make allow_reuse discoverable by adding to error message * switch _check_validator_name to _prepare_validator * Add changes file * Delete unrelated files * Add check that k in fields before using alias Co-Authored-By: Samuel Colvin <samcolvin@gmail.com> * Remove redundant call to __iter__ Co-Authored-By: Samuel Colvin <samcolvin@gmail.com> * Use typing.AbstractSet * Update pydantic/main.py Co-Authored-By: Samuel Colvin <samcolvin@gmail.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Samuel Colvin <samcolvin@gmail.com> Co-authored-by: Colin Sullivan <csullivan@brandwatch.com> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
pydantic
Data validation and settings management using Python type hinting.
Fast and extensible, pydantic plays nicely with your linters/IDE/brain. Define how data should be in pure, canonical Python 3.6+; validate it with pydantic.
Help
See documentation for more details.
Installation
Install using pip install -U pydantic or conda install pydantic -c conda-forge.
For more installation options to make pydantic even faster,
see the Install section in the documentation.
A Simple Example
from datetime import datetime
from typing import List
from pydantic import BaseModel
class User(BaseModel):
id: int
name = 'John Doe'
signup_ts: datetime = None
friends: List[int] = []
external_data = {'id': '123', 'signup_ts': '2017-06-01 12:22', 'friends': [1, '2', b'3']}
user = User(**external_data)
print(user)
#> User id=123 name='John Doe' signup_ts=datetime.datetime(2017, 6, 1, 12, 22) friends=[1, 2, 3]
print(user.id)
#> 123
Contributing
For guidance on setting up a development environment and how to make a contribution to pydantic, see Contributing to Pydantic.
Reporting a Security Vulnerability
See our security policy.
Languages
Python
99.7%
Makefile
0.3%