validatedata¶
An easier way to validate data in python.
Seven validation modes – one simple syntax.
`validator()` – One word: speed. Ideal for high‑throughput streaming. msgspec, handwritten code, and this function will compete for first place.
`validate_data_fast()` – same compiled speed but with full error messages (preview of the next‑gen engine).
`validate_data()` – general‑purpose validation with detailed errors, nested structures, and optional mutation.
`@validate` – decorator for function argument validation.
`@validate_types` – decorator that uses Python type annotations.
`FastModel` – declarative, typed models with compiled validation, rich error messages, and serialization.
`autovalidate` / `autovalidate_package` – automatically apply @validate_types to entire modules or packages.
Validatedata gives you expressive, inline validation rules without defining model classes. It fits naturally into any Python workflow – from lightweight scripts to high‑volume data processing.
New in v0.6: - `FastModel` – declarative models with compiled validation, cross‑field checks, and zero‑overhead serialization. - `validate_data_fast` – the speed of validator() combined with rich error messages. This is an experimental fast path that will eventually replace validate_data once the API stabilises. - `autovalidate` & `autovalidate_package` – automatically apply @validate_types to whole modules or packages. - Custom type registration – add your own type checkers with register_type / unregister_type. - `check_rule` – validate rule dicts before using them. - `VALID_RULE_KEYS` – introspection of all recognised rule keys.
Benchmarks (1 million repetitions)¶
Test |
validatedata |
manual |
pydantic v2 |
msgspec |
beartype |
fastjsonschema |
|---|---|---|---|---|---|---|
Scalar: type (int) |
0.0968s |
0.0779s |
0.3878s |
0.0947s |
0.3384s |
0.1444s |
Scalar: type + range |
0.1160s |
0.1267s |
0.1249s |
0.1276s |
0.3628s |
0.1447s |
Dict (valid) |
0.8388s |
0.8943s |
2.5218s |
1.2571s |
3.8539s |
|
Dict (invalid) |
0.2005s |
0.1830s |
2.5063s |
0.7378s |
3.1960s |
Note
The “manual” column represents hand‑written if statements – fastest but not reusable or composable. Validatedata’s small overhead buys you maintainability and expressiveness.
Key features
Compact pipe-syntax shorthand:
'str|strip|min:3|max:32'Mirror-structure rules that match the shape of your data
Rich built-in types:
email,url,ip,uuid,semver,slug,color,phone, and moreFunction and method decorators with async support
Conditional validation, transforms, and custom error messages
Auto‑validation of entire packages
Register your own custom types
Getting started
Guides
- Rules Reference
- Mirror-Structure Rules
- Decorators
- Auto‑validation
- Fast validation with error messages –
validate_data_fast - FastModel – Declarative Models
- Examples
- Fast validation with validator()
- User registration
- Flask route with the decorator
- Application config file
- Bulk data import (high‑performance)
- Bulk data import (with full error messages)
- Conditional fields on a checkout form
- Normalising data before saving
- Auto‑validation of a module
- Validating a whole package
- Using the fast validator with error messages
- Enforcing type hints with
enforce_hints - Using a custom decorator
- FastModel for structured data
Project