https://github.com/samuelcolvin/pydantic
Data validation using Python type hints
https://github.com/samuelcolvin/pydantic
hints json-schema parsing pydantic python python310 python311 python312 python37 python38 python39 validation
Last synced: 8 days ago
JSON representation
Data validation using Python type hints
- Host: GitHub
- URL: https://github.com/samuelcolvin/pydantic
- Owner: pydantic
- License: mit
- Created: 2017-05-03T21:23:58.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T08:34:57.000Z (6 months ago)
- Last Synced: 2024-10-29T09:50:09.487Z (6 months ago)
- Topics: hints, json-schema, parsing, pydantic, python, python310, python311, python312, python37, python38, python39, validation
- Language: Python
- Homepage: https://docs.pydantic.dev
- Size: 154 MB
- Stars: 20,917
- Watchers: 117
- Forks: 1,881
- Open Issues: 444
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- Contributing: docs/contributing.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Citation: CITATION.cff
Awesome Lists containing this project
- awesome-recommendations - pydandic
- awesome-starts - samuelcolvin/pydantic - Data parsing and validation using Python type hints (Python)
- awesome-python-typing - pydantic - Data parsing using Python type hinting. Supports dataclasses. (Dynamic type checkers)
- starred-awesome - pydantic - Data validation using Python 3.6 type hinting (Python)
README
# Pydantic
[](https://github.com/pydantic/pydantic/actions?query=event%3Apush+branch%3Amain+workflow%3ACI)
[](https://coverage-badge.samuelcolvin.workers.dev/redirect/pydantic/pydantic)
[](https://pypi.python.org/pypi/pydantic)
[](https://anaconda.org/conda-forge/pydantic)
[](https://pepy.tech/project/pydantic)
[](https://github.com/pydantic/pydantic)
[](https://github.com/pydantic/pydantic/blob/main/LICENSE)
[](https://docs.pydantic.dev/latest/contributing/#badges)
[](https://docs.pydantic.dev/latest/llms.txt)Data validation using Python type hints.
Fast and extensible, Pydantic plays nicely with your linters/IDE/brain.
Define how data should be in pure, canonical Python 3.9+; validate it with Pydantic.## Pydantic Logfire :fire:
We've recently launched Pydantic Logfire to help you monitor your applications.
[Learn more](https://pydantic.dev/articles/logfire-announcement)## Pydantic V1.10 vs. V2
Pydantic V2 is a ground-up rewrite that offers many new features, performance improvements, and some breaking changes compared to Pydantic V1.
If you're using Pydantic V1 you may want to look at the
[pydantic V1.10 Documentation](https://docs.pydantic.dev/) or,
[`1.10.X-fixes` git branch](https://github.com/pydantic/pydantic/tree/1.10.X-fixes). Pydantic V2 also ships with the latest version of Pydantic V1 built in so that you can incrementally upgrade your code base and projects: `from pydantic import v1 as pydantic_v1`.## Help
See [documentation](https://docs.pydantic.dev/) 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](https://docs.pydantic.dev/install/) section in the documentation.## A Simple Example
```python
from datetime import datetime
from typing import Optional
from pydantic import BaseModelclass User(BaseModel):
id: int
name: str = '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](https://docs.pydantic.dev/contributing/).## Reporting a Security Vulnerability
See our [security policy](https://github.com/pydantic/pydantic/security/policy).