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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4be82a18a4a15ecc9b3ed1ace19e739e0cd61432c3ef0b4349eeb095cc7d9c4
|
|
| MD5 |
d77fbd42b423154e488604e32cd58a55
|
|
| BLAKE2b-256 |
92604838cef88eb1bf629fefbe7201c81c5f25a3c5984fce164cb8780134a0fe
|
Provenance
The following attestation bundles were made for pydantic_x-0.1.0.tar.gz:
Publisher:
publish.yml on Kubenew/Pydantic-X
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_x-0.1.0.tar.gz -
Subject digest:
a4be82a18a4a15ecc9b3ed1ace19e739e0cd61432c3ef0b4349eeb095cc7d9c4 - Sigstore transparency entry: 1342727235
- Sigstore integration time:
-
Permalink:
Kubenew/Pydantic-X@8e7dd654c3cb782a377987c91b3e102926c92ece -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/Kubenew
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8e7dd654c3cb782a377987c91b3e102926c92ece -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0586b0217ab8d08929e705d3c1191b663d790fa181bfee6be20de42a10807eb
|
|
| MD5 |
0358a452d7e2ebf2c168145460720df3
|
|
| BLAKE2b-256 |
e000a73d421bc96e300586f805ea1662572d4f0f3fe5465bb8a74d9a035e521d
|
Provenance
The following attestation bundles were made for pydantic_x-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Kubenew/Pydantic-X
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_x-0.1.0-py3-none-any.whl -
Subject digest:
d0586b0217ab8d08929e705d3c1191b663d790fa181bfee6be20de42a10807eb - Sigstore transparency entry: 1342727240
- Sigstore integration time:
-
Permalink:
Kubenew/Pydantic-X@8e7dd654c3cb782a377987c91b3e102926c92ece -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/Kubenew
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8e7dd654c3cb782a377987c91b3e102926c92ece -
Trigger Event:
release
-
Statement type: