pydantic-core
raw JSON → 2.44.0 verified Tue May 12 auth: no python install: verified quickstart: verified
pydantic-core is the Rust-powered engine that underpins all validation and serialization in Pydantic V2+. Written in Rust via PyO3, it exposes SchemaValidator, SchemaSerializer, ValidationError, and the core_schema builder API to Python. End-users should interact with it only through the higher-level `pydantic` package; direct use is intended for library authors implementing custom types via __get_pydantic_core_schema__. The library releases in lockstep with pydantic — each pydantic-core version is pinned to exactly one pydantic version and does not follow SemVer independently. Current version is 2.44.0, released frequently (multiple times per month) alongside pydantic.
pip install pydantic-core Common errors
error ModuleNotFoundError: No module named 'pydantic_core._pydantic_core' ↓
cause This error occurs when the Python interpreter cannot find the compiled Rust extension module (_pydantic_core) that underpins pydantic-core. This is often due to a mismatch between the environment where the package was built (e.g., your local machine) and the environment where it's being run (e.g., a Docker container or AWS Lambda function) in terms of operating system, CPU architecture, or Python version.
fix
Ensure
pydantic-core is installed with the correct platform and Python version binaries for your target environment. For deployment in environments like AWS Lambda or Docker, use pip install --platform <platform> --python-version <python_version> --only-binary=:all: <package_name> or build your dependencies inside a compatible Linux Docker container. For example, for AWS Lambda x86_64 and Python 3.10: pip install pydantic-core --platform manylinux2014_x86_64 --python-version 3.10 -t . --only-binary=:all:. error pydantic_core._pydantic_core.ValidationError: 1 validation error for ... ↓
cause This exception is raised directly by the underlying Rust engine of `pydantic-core` when input data does not conform to the defined schema during validation. While `pydantic` typically wraps this error, seeing the `_pydantic_core` prefix indicates its origin deep within the Rust validation logic.
fix
Catch the
pydantic.ValidationError (which is aliased to pydantic_core.ValidationError) and inspect its errors() method to get detailed information about the validation failures, including the location (loc), error message (msg), input value (input), and error type. Adjust the input data or modify your Pydantic model's schema to resolve the validation issues based on these details. error AttributeError: module 'pydantic_core' has no attribute '...' (e.g., 'TuplePositionalSchema' or 'tuple_schema') ↓
cause This error typically occurs when attempting to directly access attributes, classes, or schema builders from the `pydantic_core` module that are not part of its public API, have been renamed, or were removed in a specific version. `pydantic-core` is primarily an internal engine for `pydantic`, and direct interaction is discouraged for most end-users.
fix
Avoid direct imports and usage of
pydantic_core internals unless you are a library author implementing custom types via __get_pydantic_core_schema__. For general data validation and serialization, use the higher-level pydantic API (e.g., pydantic.BaseModel, pydantic.TypeAdapter). If you are a library author, consult the pydantic-core.core_schema documentation for the correct, current schema builder functions and types for your specific pydantic-core version. Warnings
breaking pydantic-core does NOT follow SemVer. Each pydantic-core version is pinned to exactly one pydantic version. Never pin or upgrade pydantic-core independently of pydantic — doing so will cause immediate ImportError or runtime crashes. ↓
fix Always install and upgrade pydantic, not pydantic-core directly. Let pydantic's dependency constraint select the correct pydantic-core version automatically.
breaking The internal CoreSchema format (the dict structure produced by core_schema.*) is NOT considered stable API and may change between minor pydantic-core releases. Hardcoded CoreSchema dicts (without using core_schema builders) will silently break. ↓
fix Always use the core_schema builder functions (e.g. core_schema.str_schema(), core_schema.typed_dict_schema()) instead of hand-writing raw dicts. Never rely on __pydantic_core_schema__ dict structure being stable.
breaking On platforms without a pre-built binary wheel (e.g. ARM musl/Alpine, exotic BSDs, very old macOS), pip falls back to building from source and requires a compatible Rust toolchain (rustc + cargo). The build will fail with 'can't find Rust compiler' or Cargo compile errors if Rust is absent or too old. ↓
fix Always install from a pre-built wheel: keep pip up to date (`pip install --upgrade pip`) so it can resolve manylinux/musllinux wheels. For Docker, use a glibc-based image (e.g. python:3.x-slim, not python:3.x-alpine) or install Rust before pip install.
breaking Deploying to cross-compiled environments (e.g. AWS Lambda with --platform manylinux, Docker buildx for arm64) and building on a different host OS/arch causes 'No module named pydantic_core._pydantic_core' at runtime because the .so extension does not match the target platform ABI. ↓
fix Pass the correct --platform and --python-version flags to pip when building Lambda layers (e.g. `pip install --platform manylinux2014_x86_64 --only-binary=:all: pydantic-core`). Verify the .so suffix matches the target Python ABI using sysconfig.get_config_var('EXT_SUFFIX').
breaking Pydantic V1 is not compatible with Python 3.14 or greater. pydantic-core (V2) is required for Python 3.14+ support. ↓
fix Migrate to pydantic V2 (which uses pydantic-core). The compatibility shim `from pydantic import v1 as pydantic_v1` is available for incremental migration.
gotcha validate_json() on SchemaValidator is significantly faster than calling json.loads() followed by validate_python() because it avoids creating intermediate Python objects. Using validate_python(json.loads(data)) is a common performance mistake. ↓
fix Call v.validate_json(json_bytes_or_str) directly instead of v.validate_python(json.loads(json_bytes_or_str)).
gotcha Importing from pydantic_core._pydantic_core (the private Rust extension module) instead of pydantic_core is unsupported. The private module's API surface can change without notice. ↓
fix Import only from `pydantic_core` (e.g. `from pydantic_core import SchemaValidator, core_schema, ValidationError`). The public API is documented at docs.pydantic.dev/latest/api/pydantic_core/.
Install
pip install pydantic Install compatibility verified last tested: 2026-05-12
python os / libc variant status wheel install import disk
3.10 alpine (musl) pydantic - - 0.14s 27.7M
3.10 alpine (musl) pydantic-core - - 0.14s 23.9M
3.10 slim (glibc) pydantic - - 0.09s 27M
3.10 slim (glibc) pydantic-core - - 0.10s 24M
3.11 alpine (musl) pydantic - - 0.26s 30.3M
3.11 alpine (musl) pydantic-core - - 0.27s 25.9M
3.11 slim (glibc) pydantic - - 0.22s 30M
3.11 slim (glibc) pydantic-core - - 0.23s 25M
3.12 alpine (musl) pydantic - - 0.46s 22.0M
3.12 alpine (musl) pydantic-core - - 0.46s 17.8M
3.12 slim (glibc) pydantic - - 0.42s 22M
3.12 slim (glibc) pydantic-core - - 0.48s 17M
3.13 alpine (musl) pydantic - - 0.12s 21.6M
3.13 alpine (musl) pydantic-core - - 0.12s 17.4M
3.13 slim (glibc) pydantic - - 0.10s 21M
3.13 slim (glibc) pydantic-core - - 0.10s 17M
3.9 alpine (musl) pydantic - - 0.13s 27.2M
3.9 alpine (musl) pydantic-core - - 0.15s 23.4M
3.9 slim (glibc) pydantic - - 0.12s 27M
3.9 slim (glibc) pydantic-core - - 0.12s 23M
Imports
- SchemaValidator wrong
from pydantic_core._pydantic_core import SchemaValidatorcorrectfrom pydantic_core import SchemaValidator - SchemaSerializer
from pydantic_core import SchemaSerializer - ValidationError
from pydantic_core import ValidationError - core_schema
from pydantic_core import core_schema - PydanticCustomError
from pydantic_core import PydanticCustomError - PydanticSerializationUnexpectedValue
from pydantic_core import PydanticSerializationUnexpectedValue - CoreSchema (type alias)
from pydantic_core import CoreSchema
Quickstart verified last tested: 2026-04-23
from pydantic_core import SchemaValidator, ValidationError, core_schema
# Build a schema using the core_schema helpers
schema = core_schema.typed_dict_schema(
{
'name': core_schema.typed_dict_field(core_schema.str_schema()),
'age': core_schema.typed_dict_field(
core_schema.int_schema(ge=18)
),
'is_developer': core_schema.typed_dict_field(
core_schema.with_default_schema(
core_schema.bool_schema(), default=True
),
required=False,
),
}
)
v = SchemaValidator(schema)
# Validate a Python dict
result = v.validate_python({'name': 'Alice', 'age': 30})
print(result) # {'name': 'Alice', 'age': 30, 'is_developer': True}
# Validate JSON bytes directly (faster than json.loads + validate_python)
result_json = v.validate_json('{"name": "Bob", "age": 25}')
print(result_json)
# Catch validation errors
try:
v.validate_python({'name': 'Eve', 'age': 15})
except ValidationError as e:
print(e)
# 1 validation error for typed-dict
# age
# Input should be greater than or equal to 18 [type=greater_than_equal, ...]