mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
794d0bccf93b006b388a565aabc523ab34920a8c
* feat: use partially get_origin and get_args from typing Rework of d86a184072655d93652d6ea941421005f34de962 by @hmvp We cannot directly use `typing.get_origin` and `typing.get_args` for our custom types for which args and origin are wrong by default. But at least we now have a unified behaviour, which can be improved in the near future * feat: add fallback in `get_args` for generics in python 3.9 * feat: add new `_evaluate` for python 3.9 In python 3.9, `typing._evaluate` has a new required positional argument `recursive_guard` * chore: add pragma no cover for python 3.9 fallbacks * chore: add change file * chore: add comments * feat(ci): add python 3.9 support * fix: mypy assumption is wrong
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, Optional
from pydantic import BaseModel
class User(BaseModel):
id: int
name = 'John Doe'
signup_ts: Optional[datetime] = None
friends: List[int] = []
external_data = {'id': '123', 'signup_ts': '2017-06-01 12:22', 'friends': [1, '2', b'3']}
user = User(**external_data)
print(user)
#> User id=123 name='John Doe' signup_ts=datetime.datetime(2017, 6, 1, 12, 22) friends=[1, 2, 3]
print(user.id)
#> 123
Contributing
For guidance on setting up a development environment and how to make a contribution to pydantic, see Contributing to Pydantic.
Reporting a Security Vulnerability
See our security policy.
Languages
Python
99.7%
Makefile
0.3%