Validr
A simple, fast, extensible python library for data validation.
- Simple and readable schema
- 10X faster than jsonschema, 40X faster than schematics
- Can validate and serialize any object
- Easy to create custom validators
- Accurate and friendly error messages
简单,快速,可拓展的数据校验库。
- 简洁,易读的 Schema
- 比 jsonschema 快 10 倍,比 schematics 快 40 倍
- 能够校验&序列化任意类型对象
- 易于拓展自定义校验器
- 准确友好的错误提示
Overview
from validr import T, modelclass, asdict
@modelclass
class Model:
"""Base Model"""
class Person(Model):
name=T.str.maxlen(16).desc('at most 16 chars')
website=T.url.optional.desc('website is optional')
guyskk = Person(name='guyskk', website='https://github.com/guyskk')
print(asdict(guyskk))
Install
Note: Only support Python 3.5+
pip install validr
When you have c compiler in your system, validr will be c speedup mode. Otherwise validr will fallback to pure python mode.
To force c speedup mode:
VALIDR_SETUP_MODE=c pip install validr
To force pure python mode:
VALIDR_SETUP_MODE=py pip install validr
Document
https://github.com/guyskk/validr/wiki
Performance
benchmark result in Travis-CI:
--------------------------timeits---------------------------
voluptuous:default 10000 loops cost 0.368s
schema:default 1000 loops cost 0.318s
json:loads-dumps 100000 loops cost 1.380s
validr:default 100000 loops cost 0.719s
validr:model 100000 loops cost 1.676s
jsonschema:draft3 10000 loops cost 0.822s
jsonschema:draft4 10000 loops cost 0.785s
schematics:default 1000 loops cost 0.792s
---------------------------scores---------------------------
voluptuous:default 375
schema:default 43
json:loads-dumps 1000
validr:default 1918
validr:model 823
jsonschema:draft3 168
jsonschema:draft4 176
schematics:default 17
Develop
Validr is implemented by Cython since v0.14.0, it's 5X faster than pure Python implemented.
setup:
It's better to use virtualenv or similar tools to create isolated Python environment for develop.
After that, install dependencys:
./bootstrap.sh
build, test and benchmark:
inv build
inv test
inv benchmark
License
The project is open source under Anti-996 License and GNU GPL License, you can choose one of them.
Metadata
Release files for validr 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| validr-1.2.2.tar.gz | 336.4 kB | Without provenance | Details for validr-1.2.2.tar.gz |
Release files / validr-1.2.2.tar.gz
| Download URL | validr-1.2.2.tar.gz |
|---|---|
| Size | 336.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a3c3f9049fc6eae7fe68eec076ff90d36bd460bd3bdd3fecc0d603a03475a669
|
|
BLAKE2b-256 checksum How to use checksums |
63c04c4d6230d43c7276e14f4234b96a77e6487025a577c70bbfd526f77528b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for validr 1.2.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.