Cloud Parts

Pydantic

A Python data validation library: declare a class with type hints, and it checks and converts incoming data, serializes it back to dicts or JSON, and describes it as JSON Schema.

Type
Open source
Made by
Pydantic Services Inc. (created by Samuel Colvin)
License
MIT
Facts checked
9 October 2026

What it is

You describe data as a class that subclasses BaseModel, with one type-hinted attribute per field, such as birthday: date or weight: Annotated[float, Gt(0)]. Creating an instance, or calling model_validate on a dict or model_validate_json on raw JSON, checks every field and converts what it sensibly can: by default the string "123" becomes the integer 123 and an ISO date string becomes a date. Anything that doesn’t fit raises one ValidationError listing every failing field and its location. Strict mode turns the conversions off. Fields the model doesn’t declare are ignored by default, or kept or rejected with extra='allow' or extra='forbid', so a request model works as a data transfer object: only the fields it lists get through. On the way out, model_dump() and model_dump_json() serialize a model, optionally leaving out unset, default or None fields, and model_json_schema() describes it as JSON Schema.

Since version 2 (June 2023) the validation logic lives in a separate package, pydantic-core, written in Rust with PyO3; Pydantic reads your type hints and builds a schema that the Rust validators run. TypeAdapter validates types that aren’t models, such as a TypedDict or dict[str, HttpUrl], Pydantic dataclasses wrap standard dataclasses, and @validate_call checks a function’s arguments. FastAPI uses Pydantic for all request and response validation and puts its JSON Schemas into the OpenAPI document. Version 2.14 (October 8, 2026) supports Python 3.10 to 3.15.

Why teams pick it

  • Schemas are ordinary Python type hints, so editors, mypy and Pyright understand the validated data
  • A Rust core: benchmarks in the V2 plan put it 4 to 50 times faster than Pydantic 1.9.1, and the docs show it beating hand-written validation code
  • Validation, serialization and JSON Schema from one class, which is what lets FastAPI generate OpenAPI from your models
  • Clear errors: one ValidationError lists every failing field, its location, the input and an error type

Watch out for

  • Lax conversion is the default, so "123" quietly becomes 123; you have to ask for strict mode where that matters
  • Unknown fields are dropped silently by default, so a misspelled optional field is ignored rather than reported unless you set extra='forbid'
  • Version 2 changed much of the API: Pydantic 1 code needs migrating (the bump-pydantic tool helps), and Pydantic 1 doesn’t support Python 3.14 or later

How it fits with other technologies

A request model as a data transfer object: extra fields dropped, every error listed · python

# pip install pydantic
from datetime import date
from pydantic import BaseModel, Field, ValidationError

class SignupRequest(BaseModel):  # the fields a caller may set, and nothing else
    email: str = Field(pattern=r"^[^@\s]+@[^@\s]+$")
    birthday: date
    plan: str = "free"

req = SignupRequest.model_validate_json(
    '{"email": "ada@example.com", "birthday": "1815-12-10", "is_admin": true}'
)
print(req)  # email='ada@example.com' birthday=datetime.date(1815, 12, 10) plan='free'
print(req.model_dump_json())  # {"email":"ada@example.com","birthday":"1815-12-10","plan":"free"}

try:
    SignupRequest(email="nope", birthday="yesterday")
except ValidationError as e:
    print(e.error_count(), [err["loc"] for err in e.errors()])  # 2 [('email',), ('birthday',)]

print(list(SignupRequest.model_json_schema()["properties"]))  # ['email', 'birthday', 'plan']

See it in a real stack

GraphQL API in Python →
Live model
What you’re watchingClients post GraphQL queries (blue) to one endpoint. Uvicorn hands each request to FastAPI over ASGI, FastAPI routes it to Strawberry’s router, and graphql-core validates and executes it; resolvers load rows through SQLAlchemy from PostgreSQL, and the answer travels back the same way. Pink queries fail validation, so graphql-core answers them with an error list and the database never sees them. Green requests are plain REST calls that FastAPI validates with Pydantic models.
Where it came from2017–2026

Python type hints arrived with PEP 484 in Python 3.5, but the interpreter doesn’t check them. Samuel Colvin started Pydantic in 2017 to use them at run time: declare a class with type hints, and incoming data is checked and converted against them. The first release, 0.0.1, went to PyPI in May 2017, and version 1.0 followed in October 2019. FastAPI, released at the end of 2018, chose Pydantic for all of its data handling, and its author contributed JSON Schema support and editor improvements back.

By 2022 Pydantic had 26 million downloads a month, but its core logic had barely changed since the first experiment. Colvin took a sabbatical to rewrite it: in July 2022 Colvin published the V2 plan, moving validation into pydantic-core, a Rust package built with PyO3, while keeping the Python API much the same. In February 2023 Colvin founded a company, Pydantic, with a seed round led by Sequoia, and Pydantic V2 was released on June 30, 2023.

The rewrite rippled through the ecosystem. FastAPI 0.100.0 supported Pydantic 2 in July 2023, and the Pydantic team built bump-pydantic to rewrite most model code automatically. Pydantic 1 stopped supporting new Python versions from 3.14, and FastAPI dropped it in December 2025.

Why it’s built this way

Type hints are the schema
Developers already write type hints, and type checkers and IDEs already understand them, so there’s no separate schema language to learn and keep in step with the code.
Convert by default, strict on request
Data from JSON, forms and query strings arrives as strings and numbers, so turning "2020-01-01T12:00" into a datetime is usually what you want. Strict mode exists for when it isn’t. Because JSON has no type for dates, UUIDs or bytes, Pydantic parses and validates JSON in one step, so it can still turn a JSON string into a datetime sensibly.
Rewrite the core in Rust, keep the Python API
Colvin wanted speed, a tree of small validators without Python’s function-call overhead, and Rust’s help with a complex codebase. The plan was that users would keep writing the same type-hinted classes while pydantic-core did the work underneath.

Timeline

  1. 2017

    Samuel Colvin publishes 0.0.1 on PyPI in May

  2. 2018

    FastAPI adopts Pydantic for all of its data handling

  3. 2019

    Version 1.0 in October

  4. 2022

    V2 plan in July: a Rust core, pydantic-core, built with PyO3

  5. 2023

    Company founded with a Sequoia-led seed round (February); Pydantic V2 released June 30

  6. 2026

    Pydantic 2.14 on October 8 drops Python 3.9 and adds Python 3.15

Sources7 · facts checked 9 October 2026

Improve this page on GitHub