Skip to main content

Pydantic-X: faster validation helpers, schema versioning, and sanitizers for Pydantic v2.

Project description

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

Project details


Download files

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

Source Distribution

pydantic_x-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_x-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_x-0.1.0.tar.gz.

File metadata

  • Download URL: pydantic_x-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydantic_x-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a4be82a18a4a15ecc9b3ed1ace19e739e0cd61432c3ef0b4349eeb095cc7d9c4
MD5 d77fbd42b423154e488604e32cd58a55
BLAKE2b-256 92604838cef88eb1bf629fefbe7201c81c5f25a3c5984fce164cb8780134a0fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_x-0.1.0.tar.gz:

Publisher: publish.yml on Kubenew/Pydantic-X

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pydantic_x-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pydantic_x-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydantic_x-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0586b0217ab8d08929e705d3c1191b663d790fa181bfee6be20de42a10807eb
MD5 0358a452d7e2ebf2c168145460720df3
BLAKE2b-256 e000a73d421bc96e300586f805ea1662572d4f0f3fe5465bb8a74d9a035e521d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_x-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Kubenew/Pydantic-X

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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