Skip to main content

Core functionality for Pydantic validation and serialization

Project description

pydantic-core

CI Coverage pypi versions license

This package provides the core functionality for pydantic validation and serialization.

Pydantic-core is currently around 17x faster than pydantic V1. See tests/benchmarks/ for details.

Example of direct usage

NOTE: You should not need to use pydantic-core directly; instead, use pydantic, which in turn uses pydantic-core.

from pydantic_core import SchemaValidator, ValidationError


v = SchemaValidator(
    {
        'type': 'typed-dict',
        'fields': {
            'name': {
                'type': 'typed-dict-field',
                'schema': {
                    'type': 'str',
                },
            },
            'age': {
                'type': 'typed-dict-field',
                'schema': {
                    'type': 'int',
                    'ge': 18,
                },
            },
            'is_developer': {
                'type': 'typed-dict-field',
                'schema': {
                    'type': 'default',
                    'schema': {'type': 'bool'},
                    'default': True,
                },
            },
        },
    }
)

r1 = v.validate_python({'name': 'Samuel', 'age': 35})
assert r1 == {'name': 'Samuel', 'age': 35, 'is_developer': True}

# pydantic-core can also validate JSON directly
r2 = v.validate_json('{"name": "Samuel", "age": 35}')
assert r1 == r2

try:
    v.validate_python({'name': 'Samuel', 'age': 11})
except ValidationError as e:
    print(e)
    """
    1 validation error for model
    age
      Input should be greater than or equal to 18
      [type=greater_than_equal, context={ge: 18}, input_value=11, input_type=int]
    """

Getting Started

You'll need rust stable installed, or rust nightly if you want to generate accurate coverage.

With rust and python 3.8+ installed, compiling pydantic-core should be possible with roughly the following:

# clone this repo or your fork
git clone git@github.com:pydantic/pydantic-core.git
cd pydantic-core
# create a new virtual env
python3 -m venv env
source env/bin/activate
# install dependencies and install pydantic-core
make install

That should be it, the example shown above should now run.

You might find it useful to look at python/pydantic_core/_pydantic_core.pyi and python/pydantic_core/core_schema.py for more information on the python API, beyond that, tests/ provide a large number of examples of usage.

If you want to contribute to pydantic-core, you'll want to use some other make commands:

  • make build-dev to build the package during development
  • make build-prod to perform an optimised build for benchmarking
  • make test to run the tests
  • make testcov to run the tests and generate a coverage report
  • make lint to run the linter
  • make format to format python and rust code
  • make to run format build-dev lint test

Profiling

It's possible to profile the code using the flamegraph utility from flamegraph-rs. (Tested on Linux.) You can install this with cargo install flamegraph.

Run make build-profiling to install a release build with debugging symbols included (needed for profiling).

Once that is built, you can profile pytest benchmarks with (e.g.):

flamegraph -- pytest tests/benchmarks/test_micro_benchmarks.py -k test_list_of_ints_core_py --benchmark-enable

The flamegraph command will produce an interactive SVG at flamegraph.svg.

Releasing

  1. Bump package version locally. Do not just edit Cargo.toml on Github, you need both Cargo.toml and Cargo.lock to be updated.
  2. Make a PR for the version bump and merge it.
  3. Go to https://github.com/pydantic/pydantic-core/releases and click "Draft a new release"
  4. In the "Choose a tag" dropdown enter the new tag v<the.new.version> and select "Create new tag on publish" when the option appears.
  5. Enter the release title in the form "v<the.new.version> "
  6. Click Generate release notes button
  7. Click Publish release
  8. Go to https://github.com/pydantic/pydantic-core/actions and ensure that all build for release are done successfully.
  9. Go to https://pypi.org/project/pydantic-core/ and ensure that the latest release is published.
  10. Done 🎉

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_core-2.26.0.tar.gz (411.2 kB view hashes)

Uploaded Source

Built Distributions

pydantic_core-2.26.0-pp310-pypy310_pp73-win_amd64.whl (2.0 MB view hashes)

Uploaded PyPy Windows x86-64

pydantic_core-2.26.0-pp310-pypy310_pp73-musllinux_1_1_x86_64.whl (2.1 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ x86-64

pydantic_core-2.26.0-pp310-pypy310_pp73-musllinux_1_1_armv7l.whl (2.1 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARMv7l

pydantic_core-2.26.0-pp310-pypy310_pp73-musllinux_1_1_aarch64.whl (2.0 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARM64

pydantic_core-2.26.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pydantic_core-2.26.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl (2.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

pydantic_core-2.26.0-pp310-pypy310_pp73-macosx_11_0_arm64.whl (1.8 MB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

pydantic_core-2.26.0-pp310-pypy310_pp73-macosx_10_12_x86_64.whl (1.9 MB view hashes)

Uploaded PyPy macOS 10.12+ x86-64

pydantic_core-2.26.0-pp39-pypy39_pp73-win_amd64.whl (2.0 MB view hashes)

Uploaded PyPy Windows x86-64

pydantic_core-2.26.0-pp39-pypy39_pp73-musllinux_1_1_x86_64.whl (2.1 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ x86-64

pydantic_core-2.26.0-pp39-pypy39_pp73-musllinux_1_1_armv7l.whl (2.1 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARMv7l

pydantic_core-2.26.0-pp39-pypy39_pp73-musllinux_1_1_aarch64.whl (2.0 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARM64

pydantic_core-2.26.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pydantic_core-2.26.0-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl (2.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

pydantic_core-2.26.0-pp39-pypy39_pp73-macosx_11_0_arm64.whl (1.8 MB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

pydantic_core-2.26.0-pp39-pypy39_pp73-macosx_10_12_x86_64.whl (1.9 MB view hashes)

Uploaded PyPy macOS 10.12+ x86-64

pydantic_core-2.26.0-cp313-none-win_arm64.whl (1.9 MB view hashes)

Uploaded CPython 3.13 Windows ARM64

pydantic_core-2.26.0-cp313-none-win_amd64.whl (2.0 MB view hashes)

Uploaded CPython 3.13 Windows x86-64

pydantic_core-2.26.0-cp313-none-win32.whl (1.8 MB view hashes)

Uploaded CPython 3.13 Windows x86

pydantic_core-2.26.0-cp313-cp313-musllinux_1_1_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.13 musllinux: musl 1.1+ x86-64

pydantic_core-2.26.0-cp313-cp313-musllinux_1_1_armv7l.whl (2.1 MB view hashes)

Uploaded CPython 3.13 musllinux: musl 1.1+ ARMv7l

pydantic_core-2.26.0-cp313-cp313-musllinux_1_1_aarch64.whl (2.0 MB view hashes)

Uploaded CPython 3.13 musllinux: musl 1.1+ ARM64

pydantic_core-2.26.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

pydantic_core-2.26.0-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.7 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ s390x

pydantic_core-2.26.0-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.0 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ppc64le

pydantic_core-2.26.0-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.8 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARMv7l

pydantic_core-2.26.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

pydantic_core-2.26.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl (2.0 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.5+ i686

pydantic_core-2.26.0-cp313-cp313-macosx_11_0_arm64.whl (1.8 MB view hashes)

Uploaded CPython 3.13 macOS 11.0+ ARM64

pydantic_core-2.26.0-cp313-cp313-macosx_10_12_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.13 macOS 10.12+ x86-64

pydantic_core-2.26.0-cp312-none-win_arm64.whl (1.9 MB view hashes)

Uploaded CPython 3.12 Windows ARM64

pydantic_core-2.26.0-cp312-none-win_amd64.whl (2.0 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

pydantic_core-2.26.0-cp312-none-win32.whl (1.8 MB view hashes)

Uploaded CPython 3.12 Windows x86

pydantic_core-2.26.0-cp312-cp312-musllinux_1_1_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

pydantic_core-2.26.0-cp312-cp312-musllinux_1_1_armv7l.whl (2.1 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ ARMv7l

pydantic_core-2.26.0-cp312-cp312-musllinux_1_1_aarch64.whl (2.0 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ ARM64

pydantic_core-2.26.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pydantic_core-2.26.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.7 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ s390x

pydantic_core-2.26.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.0 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

pydantic_core-2.26.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.8 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARMv7l

pydantic_core-2.26.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

pydantic_core-2.26.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl (2.0 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.5+ i686

pydantic_core-2.26.0-cp312-cp312-macosx_11_0_arm64.whl (1.8 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

pydantic_core-2.26.0-cp312-cp312-macosx_10_12_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

pydantic_core-2.26.0-cp311-none-win_arm64.whl (1.9 MB view hashes)

Uploaded CPython 3.11 Windows ARM64

pydantic_core-2.26.0-cp311-none-win_amd64.whl (2.0 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

pydantic_core-2.26.0-cp311-none-win32.whl (1.8 MB view hashes)

Uploaded CPython 3.11 Windows x86

pydantic_core-2.26.0-cp311-cp311-musllinux_1_1_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pydantic_core-2.26.0-cp311-cp311-musllinux_1_1_armv7l.whl (2.1 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARMv7l

pydantic_core-2.26.0-cp311-cp311-musllinux_1_1_aarch64.whl (2.0 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

pydantic_core-2.26.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pydantic_core-2.26.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.8 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

pydantic_core-2.26.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.0 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

pydantic_core-2.26.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.8 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

pydantic_core-2.26.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pydantic_core-2.26.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl (2.0 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.5+ i686

pydantic_core-2.26.0-cp311-cp311-macosx_11_0_arm64.whl (1.8 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pydantic_core-2.26.0-cp311-cp311-macosx_10_12_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

pydantic_core-2.26.0-cp310-none-win_amd64.whl (2.0 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

pydantic_core-2.26.0-cp310-none-win32.whl (1.8 MB view hashes)

Uploaded CPython 3.10 Windows x86

pydantic_core-2.26.0-cp310-cp310-musllinux_1_1_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pydantic_core-2.26.0-cp310-cp310-musllinux_1_1_armv7l.whl (2.1 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARMv7l

pydantic_core-2.26.0-cp310-cp310-musllinux_1_1_aarch64.whl (2.0 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

pydantic_core-2.26.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pydantic_core-2.26.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

pydantic_core-2.26.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

pydantic_core-2.26.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

pydantic_core-2.26.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pydantic_core-2.26.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (2.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ i686

pydantic_core-2.26.0-cp310-cp310-macosx_11_0_arm64.whl (1.8 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pydantic_core-2.26.0-cp310-cp310-macosx_10_12_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.10 macOS 10.12+ x86-64

pydantic_core-2.26.0-cp39-none-win_amd64.whl (2.0 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

pydantic_core-2.26.0-cp39-none-win32.whl (1.8 MB view hashes)

Uploaded CPython 3.9 Windows x86

pydantic_core-2.26.0-cp39-cp39-musllinux_1_1_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pydantic_core-2.26.0-cp39-cp39-musllinux_1_1_armv7l.whl (2.1 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARMv7l

pydantic_core-2.26.0-cp39-cp39-musllinux_1_1_aarch64.whl (2.0 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

pydantic_core-2.26.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pydantic_core-2.26.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

pydantic_core-2.26.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

pydantic_core-2.26.0-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

pydantic_core-2.26.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pydantic_core-2.26.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (2.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ i686

pydantic_core-2.26.0-cp39-cp39-macosx_11_0_arm64.whl (1.8 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pydantic_core-2.26.0-cp39-cp39-macosx_10_12_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.9 macOS 10.12+ x86-64

pydantic_core-2.26.0-cp38-none-win_amd64.whl (2.0 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

pydantic_core-2.26.0-cp38-none-win32.whl (1.8 MB view hashes)

Uploaded CPython 3.8 Windows x86

pydantic_core-2.26.0-cp38-cp38-musllinux_1_1_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pydantic_core-2.26.0-cp38-cp38-musllinux_1_1_armv7l.whl (2.1 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARMv7l

pydantic_core-2.26.0-cp38-cp38-musllinux_1_1_aarch64.whl (2.0 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

pydantic_core-2.26.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pydantic_core-2.26.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.8 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

pydantic_core-2.26.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.0 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

pydantic_core-2.26.0-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.8 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

pydantic_core-2.26.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pydantic_core-2.26.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl (2.0 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ i686

pydantic_core-2.26.0-cp38-cp38-macosx_11_0_arm64.whl (1.8 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pydantic_core-2.26.0-cp38-cp38-macosx_10_12_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.8 macOS 10.12+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page