mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
938335c46f7e31da71e5c2a45eb3cf1ad51030b5
Voluptuous, despite the name, is a Python data validation library. - GitHub: https://github.com/alecthomas/voluptuous - PyPi: https://pypi.org/project/voluptuous Package | Version | Relative Performance | Mean validation time --- | --- | --- | --- valideer | `0.4.2` | | 104.2μs attrs + cattrs | `19.3.0` | 1.1x slower | 114.4μs pydantic | `1.4a1` | 1.2x slower | 124.3μs marshmallow | `3.5.0` | 1.8x slower | 190.1μs voluptuous | `0.11.7` | 2.2x slower | 227.6μs trafaret | `2.0.2` | 2.4x slower | 253.0μs django-rest-framework | `3.11.0` | 8.5x slower | 881.8μs cerberus | `1.3.2` | 19.1x slower | 1993.8μs
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%