Pydantic

Data validation and settings management using Python type hints, backed by a Rust core.

Library
PyPI
v2.13.5
28,891 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
93 /100 Excellent
Development Activity 100
Maintenance 96
Community 76
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
91 /100 Excellent
Architecture 93
Code Quality 90
Innovation 92
Learning Curve 88

Pydantic is the most widely used data validation library for Python. It lets you define data schemas as ordinary Python classes with type hints, then validates, parses, and serializes data against those schemas at runtime, catching malformed input before it reaches your business logic. Its validation engine is implemented in Rust (pydantic-core) and exposed through a pure-Python API, giving it both speed and Python’s usual ergonomics.

It underpins much of the modern Python web and data ecosystem: FastAPI uses it for request/response validation, SQLModel and various ORMs build on it for typed data access, and it’s a common building block wherever untrusted or external data needs to become trustworthy typed objects — API payloads, config files, CLI arguments, and LLM structured outputs.

What You Get

  • A BaseModel class that validates and parses data purely from Python type-hint annotations
  • A Rust-compiled validation and serialization core (pydantic-core) for near-native performance
  • Automatic JSON Schema generation for every model, ready for OpenAPI docs or LLM structured outputs
  • TypeAdapter for validating arbitrary types (dataclasses, TypedDicts, lists) without a BaseModel
  • Structured, machine-readable validation errors instead of ad hoc exception strings

Common Use Cases

  • Validating and parsing incoming API request/response bodies in FastAPI and similar frameworks
  • Loading and validating application configuration and environment variables via typed settings models
  • Coercing and validating third-party API responses or webhook payloads into typed Python objects
  • Defining structured output schemas for LLM function calling and tool use

Under The Hood

Architecture — Pydantic’s core validation and serialization logic is implemented in Rust in the pydantic-core subproject (pydantic-core/src), compiled to a native extension and exposed to Python via PyO3 bindings. The pure-Python pydantic package (pydantic/main.py’s BaseModel, pydantic/fields.py’s FieldInfo) builds a “core schema” description of each model by walking type annotations in pydantic/_internal/_generate_schema.py, which is then handed to pydantic-core to produce a compiled SchemaValidator/SchemaSerializer pair cached on the model class by pydantic/_internal/_model_construction.py’s ModelMetaclass. At runtime, validation and serialization calls go straight into the compiled Rust validators rather than walking Python-level type trees, which is the mechanism behind Pydantic v2’s speed. Generic models, dataclasses, and TypedDicts route through the same schema-generation path (pydantic/_internal/_generics.py, _dataclasses.py), and JSON Schema derivation (pydantic/json_schema.py) works off the same core schema graph.

Tech Stack — A pure-Python 3.10+ layer with three runtime dependencies (typing-extensions, annotated-types, typing-inspection) plus a version-pinned pydantic-core Rust extension (pydantic-core/Cargo.toml) built with PyO3/maturin-style tooling. Development is uv-managed (uv.lock, pyproject.toml dependency-groups) with pytest, pytest-benchmark and pytest-codspeed for performance-regression tracking, and mypy/pyright cross-checks exercised in tests/.

Code Quality — tests/ contains 170+ test files covering validators, serializers, JSON Schema generation, generics, dataclasses, and the mypy plugin. The project uses pytest-examples to execute every documentation code sample as a real test, pytest-benchmark/pytest-codspeed to guard against performance regressions, and a pre-commit config enforcing lint and format on every change. A dedicated deprecated/ subpackage isolates legacy v1-compatible APIs behind explicit deprecation warnings instead of silently changing behavior, and underscore-prefixed _internal/ modules keep the curated public surface (pydantic/init.py, 456 lines of explicit re-exports) distinct from implementation detail.

API Design — The primary API is a single BaseModel subclass with fields expressed as plain Python type hints, so a working model requires no boilerplate beyond annotations. Validators and serializers are opt-in decorators (functional_validators.py, functional_serializers.py) rather than mandatory ceremony, TypeAdapter provides ad hoc validation for non-BaseModel types, and failures (errors.py) return structured, machine-readable ErrorDetails rather than bare strings — a consistently ergonomic design that libraries like FastAPI and SQLModel build directly on top of.

Used by 116 apps in this directory

Python
67%
Apache 2.0

Agent Control

AI Agents

314

An open-source runtime control plane for AI agents — define safety guardrails once, apply them across agents built on LangChain, CrewAI, Google ADK, or AWS Strands, and update controls without redeploying code.

View details
74
Repo Health
71
Technical
67
Dependency
Built with
Python 67%
TypeScript 32%
Updated 4 days ago
Python
99%
MIT

Agent Lightning

AI Development

18,515

A Microsoft-built training framework that optimizes AI agents with reinforcement learning, automatic prompt optimization, or supervised fine-tuning — with near-zero code changes to your existing agent, in any framework.

View details
85
Repo Health
68
Technical
69
Dependency
Built with
Python 99%
Updated 4 days ago
TypeScript
56%
Other

agenta

AI Development · Developer Tools · Devops

4,788

The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
TypeScript 56%
Python 39%
Updated 5 days ago
Python
100%
Apache 2.0

Agno

AI Development · Automation · Devops

42,358

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
66
Dependency
Built with
Python 100%
Updated 4 days ago
Python
100%
Apache 2.0

Agno

AI Development · Automation · Devops

42,358

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
66
Dependency
Built with
Python 100%
Updated 4 days ago
Python
89%
Apache 2.0

Apache Airflow

Data Engineering

46,995

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
64
Dependency
Built with
Python 89%
Updated 4 days ago
Python
68%
MIT

ArchiveBox

Bookmarks Archiving

28,636

Self-hosted web archiving that saves HTML, PDFs, screenshots, media, and code in open formats you own forever

View details
88
Repo Health
84
Technical
69
Dependency
Built with
Python 68%
HTML 25%
Updated 4 days ago
Python
59%
Apache 2.0

argilla

AI Development · Data Engineering

5,125

Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.

View details
65
Repo Health
81
Technical
61
Dependency
Built with
Python 59%
Jupyter Notebook 21%
Updated 1 weeks ago
Python
59%
Other

Arkon

AI Assistants · Knowledge Management · Mcp

1,463

Self-hosted enterprise AI knowledge hub that compiles internal docs into a scoped, reviewable wiki and serves it to Claude and other LLMs through an MCP server.

View details
46
Repo Health
74
Technical
70
Dependency
Built with
Python 59%
TypeScript 41%
Updated 4 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers