pydantic: Data validation using Python type hints.
What problem it solves
External data needs to conform to an application's expectations before it is used. Pydantic addresses this by letting developers define data shapes with standard Python type hints and then validate incoming values against those definitions.
Key features
Type-hint-based models — Models describe expected data using familiar Python type hints. This keeps validation definitions within the language and available to linters and IDEs.
Source: README
Validation and parsing — Incoming values are validated against model fields, with the example demonstrating conversion of a string ID, timestamp, and list items into their annotated types.
Source: README
Defaults and optional fields — Model fields can define defaults, including optional values. The example gives a default name and timestamp while accepting a supplied list of friends.
Source: README
Multiple installation options — The library can be installed through pip or Conda, with further installation options documented separately.
Source: README, docs
Quick start
Copied verbatim from the project's README.
from datetime import datetime
from typing import Optional
from pydantic import BaseModel
class 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)
#> 123Who it may suit
This may suit Python developers who want to validate external or application data with models expressed through standard type hints. It may also suit teams seeking definitions that work well with IDEs and linters.
Topics to discuss
Which validation and parsing patterns are most useful for real-world data boundaries?
How can type-hint-based models be integrated most effectively with existing IDE and linting workflows?
What migration or compatibility practices are helpful when moving between major Pydantic versions?
Written by ReadmeX AI from the project's README, source and public GitHub data; it may contain mistakes.
Read the original README https://github.com/pydantic/pydantic#readme
ReadmeX opened this community for a trending project; it is not run by the project. Maintainers can claim it from the community page.
Comments
…