Skip to main content

pydantic-x

Pydantic-X is a lightweight toolkit for Pydantic v2 that provides:

  • Sanitizers (trim, lower, strip HTML, normalize whitespace)
  • Schema versioning (versioned models + migration hooks)
  • Fast validation helpers (compiled TypeAdapter cache)

This is not a replacement for Pydantic.
It is a thin layer that helps you build production APIs with strict data control.

Install

pip install pydantic-x

Example: Sanitized Model

from pydanticx import SanitizedModel, sanitize

class User(SanitizedModel):
    name: str
    email: str

    model_config = {
        "sanitizers": {
            "name": [sanitize.trim, sanitize.collapse_spaces],
            "email": [sanitize.trim, sanitize.lower],
        }
    }

u = User.model_validate({"name": "  John   Smith  ", "email": "  TEST@EXAMPLE.COM "})
print(u.name)   # "John Smith"
print(u.email)  # "test@example.com"

Example: Versioned Schema + Migration

from pydanticx import VersionedModel, migrate

class UserV1(VersionedModel):
    schema_version: int = 1
    full_name: str

class UserV2(VersionedModel):
    schema_version: int = 2
    name: str

@migrate(from_version=1, to_version=2)
def migrate_user_v1_to_v2(data: dict) -> dict:
    return {
        "schema_version": 2,
        "name": data.get("full_name", "")
    }

obj = UserV2.validate_versioned({"schema_version": 1, "full_name": "Alice"})
print(obj.name)  # Alice

Example: Fast TypeAdapter Cache

from pydanticx.fast import validate_fast

result = validate_fast(dict[str, int], {"a": 1, "b": 2})

Notes

  • Works with Pydantic v2
  • No external dependencies beyond Pydantic

License

MIT

Metadata

Release files for pydantic-x 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-x 0.1.0
File Size Uploaded Provenance Actions
pydantic_x-0.1.0.tar.gz 5.1 kB With provenance Details for pydantic_x-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-x 0.1.0
File Interpreter ABI Platform Actions
pydantic_x-0.1.0-py3-none-any.whl Python 3 none any Details for pydantic_x-0.1.0-py3-none-any.whl

Total release size: 10.7 kB

Release files / pydantic_x-0.1.0.tar.gz

Download URL pydantic_x-0.1.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a4be82a18a4a15ecc9b3ed1ace19e739e0cd61432c3ef0b4349eeb095cc7d9c4
BLAKE2b-256 checksum
How to use checksums
92604838cef88eb1bf629fefbe7201c81c5f25a3c5984fce164cb8780134a0fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 20, 2026.

Transparency log

Release files / pydantic_x-0.1.0-py3-none-any.whl

Download URL pydantic_x-0.1.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0586b0217ab8d08929e705d3c1191b663d790fa181bfee6be20de42a10807eb
BLAKE2b-256 checksum
How to use checksums
e000a73d421bc96e300586f805ea1662572d4f0f3fe5465bb8a74d9a035e521d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 20, 2026.

Transparency log

Security for pydantic-x 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydantic_x-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page