Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 4 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

Pydantic

Check incoming data in Python apps.

Forms, validation and schemasPYPI

GitHubWebsite

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/LICENSE

From 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

86 / 100
Gid Score, #31 overall
292M
downloads a week, pypi
29.6K
GitHub stars
538
agent projects use it
Pydantic: downloads per weekPyPI, pydantic 288,782,721
Pydantic: GitHub starspydantic/pydantic 29,639

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

282 projects, 9.3%
272 projects, 8.3%
203 projects, 8.3%
32 projects, 9.6%
31 projects, 6.5%
24 projects, 5.1%
23 projects, 8.2%
19 projects, 5.5%

Often used with

In 55.0% of its projects
In 54.8% of its projects
In 52.0% of its projects
In 34.8% of its projects
In 34.4% of its projects
In 34.0% of its projects
In 33.8% of its projects
In 29.7% of its projects

Pydantic in practice

Strengths

The schema is the type hints

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.

Most validation runs in Rust

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."

Docs benchmark beats hand-written parsing

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 "&gt;300% faster" in this example. The printed output reads "Pydantic 3.45x faster".

Strict mode that still works on JSON

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

V2 renamed the model methods

<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 migration tool is beta

The maintainers provide <code>bump-pydantic</code> to rewrite v1 code. They write that it is "still in beta".

Coercion is on by default

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)
#> 123

More about Pydantic

Funding
  • GitHub Sponsors: https://github.com/samuelcolvin
  • 21 GitHub sponsors

See all

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

See all

Head to head
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

MITGid 86292M/wk

Zod

Pick Zod when your app is written in TypeScript or JavaScript rather than Python; it is a TypeScript-first schema validation library.

jsonschema

Pick jsonschema when you already have JSON Schema files and only need to check data against them in Python.

MITGid 75164M/wk

email-validator

Pick email-validator alone when all you need is to check email addresses; Pydantic's EmailStr uses it anyway.

marshmallow

Lightweight library for converting complex datatypes to and from native Python datatypes.

MITGid 7022.4M/wk

fastjsonschema

Fast JSON schema validation for Python with optimized performance.

BSDGid 5730M/wk

cattrs

Structured data serialization for attrs and dataclasses with composition support.

MITGid 508.5M/wk

msgspec

Fast serialization and validation for JSON, MessagePack, YAML, TOML with schemas.

BSD-3-ClauseGid 589.8M/wk

schema

Lightweight Python library for validating data structures against defined schemas.

MITGid 555.3M/wk

Compare Pydantic with another tool

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.”

  1. 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/

  2. 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)
    

    From github.com/pydantic/pydantic/blob/main/README.md

  3. Catch ValidationError to show the user what to fix; e.errors() gives one entry per wrong field.

    From pydantic.dev/docs/validation/latest/get-started/

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## 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

Model.parse_obj(data), model.dict(), model.json(), Model.schema() (Pydantic 1 names)
Model.model_validate(data), model.model_dump(), model.model_dump_json(), Model.model_json_schema()

Version 2 renamed these methods; the old ones still run but warn (our run printed PydanticDeprecatedSince20 for parse_obj and dict).

from pydantic import BaseSettings
pip install pydantic-settings, then from pydantic_settings import BaseSettings

BaseSettings left the main package in version 2.

@validator('x') and class Config: orm_mode = True
@field_validator('x') and model_config = ConfigDict(from_attributes=True)

The old decorator is deprecated and orm_mode was renamed.

Using EmailStr after plain pip install pydantic
pip install 'pydantic[email]'

In our run the class definition failed with ImportError: email-validator is not installed.

note: Optional[str] (expecting the field to be optional)
note: Optional[str] = None, or note: str | None = None

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.