MCPcopy
hub / github.com/pydantic/pydantic

github.com/pydantic/pydantic @core-v2.46.4 sqlite

repository ↗ · DeepWiki ↗ · release core-v2.46.4 ↗ · compare 2 versions
10,960 symbols 44,452 edges 408 files 1,325 documented · 12%
README

Pydantic Validation

CI Coverage pypi CondaForge downloads versions license Pydantic v2 llms.txt

Data validation using Python type hints.

Fast and extensible, Pydantic plays nicely with your linters/IDE/brain. Define how data should be in pure, canonical Python 3.9+; validate it with Pydantic.

Pydantic Logfire :fire:

We've launched Pydantic Logfire to help you monitor your applications. Learn more

Pydantic V1.10 vs. V2

Pydantic V2 is a ground-up rewrite that offers many new features, performance improvements, and some breaking changes compared to Pydantic V1.

If you're using Pydantic V1 you may want to look at the pydantic V1.10 Documentation or, 1.10.X-fixes git branch. Pydantic V2 also ships with the latest version of Pydantic V1 built in so that you can incrementally upgrade your code base and projects: from pydantic import v1 as pydantic_v1.

Help

See documentation for more details.

Installation

Install using pip install -U pydantic or conda install pydantic -c conda-forge. For more installation options to make Pydantic even faster, see the Install section in the documentation.

A Simple Example

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

Contributing

For guidance on setting up a development environment and how to make a contribution to Pydantic, see Contributing to Pydantic.

Reporting a Security Vulnerability

See our security policy.

Core symbols most depended-on inside this repo

Field
called by 852
pydantic/fields.py
int_schema
called by 774
pydantic/json_schema.py
model_dump
called by 634
pydantic/main.py
errors
called by 566
pydantic/v1/error_wrappers.py
str_schema
called by 479
pydantic/json_schema.py
validate_python
called by 344
pydantic/type_adapter.py
model_fields_schema
called by 287
pydantic/json_schema.py
model_schema
called by 254
pydantic/json_schema.py

Shape

Function 5,445
Class 2,807
Method 2,305
Route 403

Languages

Python100%
TypeScript1%

Modules by API surface

tests/test_types.py482 symbols
tests/test_json_schema.py444 symbols
tests/test_main.py356 symbols
tests/test_dataclasses.py287 symbols
tests/test_validators.py266 symbols
tests/test_generics.py256 symbols
tests/test_edge_cases.py242 symbols
pydantic-core/python/pydantic_core/core_schema.py183 symbols
tests/test_serialize.py167 symbols
pydantic-core/tests/benchmarks/test_micro_benchmarks.py153 symbols
tests/test_discriminated_union.py151 symbols
pydantic/types.py135 symbols

Dependencies from manifests, versioned

prettier2.7.1 · 1×
pyodide0.28.3 · 1×

Datastores touched

(mongodb)Database · 1 repos
(mysql)Database · 1 repos
appDatabase · 1 repos
foobarDatabase · 1 repos
appDatabase · 1 repos
appDatabase · 1 repos
thingDatabase · 1 repos
dbnameDatabase · 1 repos

For agents

$ claude mcp add pydantic \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact