1. License
“to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software”
MIT allows use in paid and closed-source products.
github.com/pydantic/pydantic/blob/main/LICENSE3. Used by agents' projects
Dependency in 538 public GitHub projects set up for AI coding agents that we scanned (8.6%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
pydantic.dev/docs/validation/llms.txtFrom the package registry and GitHub, checked daily; card checked Nov 10, 2026. Tap a verdict to see its source.How we checkedReport an error
What Pydantic does
Pydantic is a free Python library that checks data before your app uses it. You describe what a sign-up form, a file or a reply from another service should look like. Pydantic accepts the data, fixes simple things like the text "34" into the number 34, or lists exactly what is wrong. Many Python tools, including FastAPI, are built on it.
What people build with it
Check sign-up forms before saving
A new user types a name, an email and an age; your app saves only data that fits and shows a clear message for each wrong field.
Notice when another service changes
Your app reads orders or prices from someone else's service; a check on each reply tells you the day its format changes, instead of saving broken data.
Read uploaded data files safely
People upload a file with contacts or settings; your app checks every entry and reports the missing or wrong ones by name.
Describe your data to other tools
The same description can be turned into a standard format file, so documentation pages, form builders and AI models know which fields you expect.
Load app settings from the server
Database address, upload limit and secret keys come from the server's settings; the app refuses to start if one is missing or wrong.
Check an AI model's answer Idea
You ask an AI model to fill in a support ticket; your app accepts the answer only if every field is there and in range.
Pydantic popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Pydantic is used
- Pydantic is a dependency in 538 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (33.1% of the 1,623 Python ones), #3 of 63 in forms, validation and schemas.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 3,899; those are left out of every share on this page.
- The most used alternative in our scan is jsonschema (104 projects).
- Projects that use it most often also use Uvicorn (55.0%), FastAPI (54.8%), python-dotenv (52.0%).
- It is more common in projects set up for OpenClaw (9.6%) than for OpenAI Codex (5.1%).
By coding agent
Often used with
Pydantic in practice
Strengths
Fields are declared with standard annotations. The site says this means "less to learn, less code to write", and it points to integration with IDEs and static analysis tools.
Validation for most types is implemented in Rust inside <code>pydantic-core</code>. The docs say this puts Pydantic "among the fastest data validation libraries for Python."
The docs include a benchmark that parses JSON from GitHub's emoji API and validates the URLs. They note that dedicated code "should be much faster than a general-purpose validator" in general, but say Pydantic is ">300% faster" in this example. The printed output reads "Pydantic 3.45x faster".
Strict mode refuses to convert types, but JSON has no datetime, UUID or bytes types. <code>model_validate_json</code> parses and validates JSON in one step, so a string can still become a <code>datetime</code> under strict rules.
Watch out for
<code>dict()</code>, <code>json()</code>, <code>parse_obj()</code> and <code>copy()</code> became <code>model_dump()</code>, <code>model_dump_json()</code>, <code>model_validate()</code> and <code>model_copy()</code>. The old names still work where possible, but they emit <code>DeprecationWarning</code>s.
The maintainers provide <code>bump-pydantic</code> to rewrite v1 code. They write that it is "still in beta".
Pydantic converts common wrong types instead of rejecting them. For example, a numeric string passed to an <code>int</code> field is parsed as an int. If you need exact types, turn on strict mode.
Validate and coerce external data into a model
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)
#> 123More about Pydantic
Funding
- GitHub Sponsors: https://github.com/samuelcolvin
- 21 GitHub sponsors
Agent Skills for it
- pydantic-ai: Build production-ready AI agents with PydanticAI — type-safe tool use, structured outputs, dependency injection, and multi-model support.
- pydantic: Python data validation using type hints and runtime type checking with Pydantic v2's Rust-powered core for high-performance validation in Fa
- pydantic-models-py: Create Pydantic models following the multi-model pattern with Base, Create, Update, Response, and InDB variants. Use when defining API reque
Head to head
- Pydantic vs jsonschema used together in 71 projects
Packages around it
- python-dotenv: .env file loader
- uvicorn: ASGI server
- fastapi: Web API framework
- requests: HTTP client
- numpy: Numeric arrays
- pydantic-settings: Settings from env vars
More in Forms, validation and schemas
Alternatives
Pydantic This page
Pick Zod when your app is written in TypeScript or JavaScript rather than Python; it is a TypeScript-first schema validation library.
Pick jsonschema when you already have JSON Schema files and only need to check data against them in Python.
Pick email-validator alone when all you need is to check email addresses; Pydantic's EmailStr uses it anyway.
Lightweight library for converting complex datatypes to and from native Python datatypes.
Fast JSON schema validation for Python with optimized performance.
Structured data serialization for attrs and dataclasses with composition support.
Fast serialization and validation for JSON, MessagePack, YAML, TOML with schemas.
Lightweight Python library for validating data structures against defined schemas.
Get started
Tell your AI assistant
“Use the Python library Pydantic v2 (pin pydantic[email]==2.14.3, Python 3.10+) to check the sign-up form data with a BaseModel and model_validate, and return the messages from ValidationError.errors() for each wrong field.”
Install Pydantic into your project's Python environment (Python 3.10 or newer). Add the email extra if you check email addresses.
pip install pydantic # with the `email` extra: pip install 'pydantic[email]'From pydantic.dev/docs/validation/latest/get-started/install/
Describe your data as a class with typed fields and pass the incoming data to it.
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)Catch ValidationError to show the user what to fix; e.errors() gives one entry per wrong field.
Rules for your agent
## Pydantic
- Write V2 code. Use `model_dump()`, `model_dump_json()`, `model_validate()`, `model_copy()` and `model_json_schema()`, not the V1 names `dict()`, `json()`, `parse_obj()` or `copy()`.
- For raw JSON input, call `Model.model_validate_json(data)` instead of the deprecated `parse_raw`/`parse_file`. Otherwise, load the data first and pass it to `model_validate`.
- To build models from ORM objects, set `from_attributes=True` in the model config and use `model_validate`, not `from_orm`.
- Lax mode coerces input by default. Pass `strict=True` to `model_validate` when inputs must match the declared types exactly.
- Catch `ValidationError` and read `e.errors()` for per-field `type`, `loc` and `msg`.
- Validation uses aliases by default (`validate_by_alias` is True, `validate_by_name` is False). Enable `validate_by_name` if callers pass field names.
- Use `@field_serializer` or `@model_serializer` for custom output. `json_encoders` in the model config is deprecated.
Mistakes to avoid
Version 2 renamed these methods; the old ones still run but warn (our run printed PydanticDeprecatedSince20 for parse_obj and dict).
BaseSettings left the main package in version 2.
The old decorator is deprecated and orm_mode was renamed.
In our run the class definition failed with ImportError: email-validator is not installed.
Without a default the field is still required; Optional only allows None as a value.
Questions
Can I use it in a paid, closed-source app?
Yes. It is MIT-licensed; keep the copyright and license notice with its files.
My code uses parse_obj() and .dict(). Is that still right?
Those are Pydantic 1 names. In version 2 they are model_validate() and model_dump(); the old names still run but warn that they are deprecated.
Is there a tool to move old code to version 2?
Yes, bump-pydantic. The docs say it is still in beta.
Will a minor update break my code?
The project says it will not break things on purpose in 2.x minor releases, but error message texts may change; check the error type, not the message.
Does it send my data anywhere?
No. Checks run inside your app; sending failed checks to Logfire is a separate, optional service.