# Validr
[![github-action](https://github.com/guyskk/validr/actions/workflows/build-test.yml/badge.svg?branch=main)](https://github.com/guyskk/validr/actions/workflows/build-test.yml) [![codecov](https://codecov.io/gh/guyskk/validr/branch/master/graph/badge.svg)](https://codecov.io/gh/guyskk/validr)
A simple, fast, extensible python library for data validation.
- Simple and readable schema
- 10X faster than [jsonschema](https://github.com/Julian/jsonschema),
40X faster than [schematics](https://github.com/schematics/schematics)
- Can validate and serialize any object
- Easy to create custom validators
- Accurate and friendly error messages
简单,快速,可拓展的数据校验库。
- 简洁,易读的 Schema
- 比 [jsonschema](https://github.com/Julian/jsonschema) 快 10 倍,比 [schematics](https://github.com/schematics/schematics) 快 40 倍
- 能够校验&序列化任意类型对象
- 易于拓展自定义校验器
- 准确友好的错误提示
## Overview
```python
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](http://cython.org/) since v0.14.0, it's 5X
faster than pure Python implemented.
**setup**:
It's better to use [virtualenv](https://virtualenv.pypa.io/en/stable/) 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](/LICENSE) and [GNU GPL License](/LICENSE-GPL), you can choose one of them.
Raw data
{
"_id": null,
"home_page": "https://github.com/guyskk/validr",
"name": "validr",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "validation validator validate schema jsonschema",
"author": "guyskk",
"author_email": "guyskk@qq.com",
"download_url": "https://files.pythonhosted.org/packages/63/c0/4c4d6230d43c7276e14f4234b96a77e6487025a577c70bbfd526f77528b8/validr-1.2.2.tar.gz",
"platform": null,
"description": "# Validr\n\n[![github-action](https://github.com/guyskk/validr/actions/workflows/build-test.yml/badge.svg?branch=main)](https://github.com/guyskk/validr/actions/workflows/build-test.yml) [![codecov](https://codecov.io/gh/guyskk/validr/branch/master/graph/badge.svg)](https://codecov.io/gh/guyskk/validr)\n\nA simple, fast, extensible python library for data validation.\n\n- Simple and readable schema\n- 10X faster than [jsonschema](https://github.com/Julian/jsonschema),\n 40X faster than [schematics](https://github.com/schematics/schematics)\n- Can validate and serialize any object\n- Easy to create custom validators\n- Accurate and friendly error messages\n\n\u7b80\u5355\uff0c\u5feb\u901f\uff0c\u53ef\u62d3\u5c55\u7684\u6570\u636e\u6821\u9a8c\u5e93\u3002\n\n- \u7b80\u6d01\uff0c\u6613\u8bfb\u7684 Schema\n- \u6bd4 [jsonschema](https://github.com/Julian/jsonschema) \u5feb 10 \u500d\uff0c\u6bd4 [schematics](https://github.com/schematics/schematics) \u5feb 40 \u500d\n- \u80fd\u591f\u6821\u9a8c&\u5e8f\u5217\u5316\u4efb\u610f\u7c7b\u578b\u5bf9\u8c61\n- \u6613\u4e8e\u62d3\u5c55\u81ea\u5b9a\u4e49\u6821\u9a8c\u5668\n- \u51c6\u786e\u53cb\u597d\u7684\u9519\u8bef\u63d0\u793a\n\n## Overview\n\n```python\nfrom validr import T, modelclass, asdict\n\n@modelclass\nclass Model:\n \"\"\"Base Model\"\"\"\n\nclass Person(Model):\n name=T.str.maxlen(16).desc('at most 16 chars')\n website=T.url.optional.desc('website is optional')\n\nguyskk = Person(name='guyskk', website='https://github.com/guyskk')\nprint(asdict(guyskk))\n```\n\n## Install\n\nNote: Only support Python 3.5+\n\n pip install validr\n\nWhen you have c compiler in your system, validr will be c speedup mode.\nOtherwise validr will fallback to pure python mode.\n\nTo force c speedup mode:\n\n VALIDR_SETUP_MODE=c pip install validr\n\nTo force pure python mode:\n\n VALIDR_SETUP_MODE=py pip install validr\n\n## Document\n\nhttps://github.com/guyskk/validr/wiki\n\n## Performance\n\nbenchmark result in Travis-CI:\n\n```\n--------------------------timeits---------------------------\n voluptuous:default 10000 loops cost 0.368s\n schema:default 1000 loops cost 0.318s\n json:loads-dumps 100000 loops cost 1.380s\n validr:default 100000 loops cost 0.719s\n validr:model 100000 loops cost 1.676s\n jsonschema:draft3 10000 loops cost 0.822s\n jsonschema:draft4 10000 loops cost 0.785s\n schematics:default 1000 loops cost 0.792s\n---------------------------scores---------------------------\n voluptuous:default 375\n schema:default 43\n json:loads-dumps 1000\n validr:default 1918\n validr:model 823\n jsonschema:draft3 168\n jsonschema:draft4 176\n schematics:default 17\n```\n\n## Develop\n\nValidr is implemented by [Cython](http://cython.org/) since v0.14.0, it's 5X\nfaster than pure Python implemented.\n\n**setup**:\n\nIt's better to use [virtualenv](https://virtualenv.pypa.io/en/stable/) or\nsimilar tools to create isolated Python environment for develop.\n\nAfter that, install dependencys:\n\n```\n./bootstrap.sh\n```\n\n**build, test and benchmark**:\n\n```\ninv build\ninv test\ninv benchmark\n```\n\n## License\n\nThe project is open source under [Anti-996 License](/LICENSE) and [GNU GPL License](/LICENSE-GPL), you can choose one of them.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple, fast, extensible python library for data validation.",
"version": "1.2.2",
"project_urls": {
"Homepage": "https://github.com/guyskk/validr"
},
"split_keywords": [
"validation",
"validator",
"validate",
"schema",
"jsonschema"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "63c04c4d6230d43c7276e14f4234b96a77e6487025a577c70bbfd526f77528b8",
"md5": "5d8b9ed1f33e364e1d73dc8d550d99c2",
"sha256": "a3c3f9049fc6eae7fe68eec076ff90d36bd460bd3bdd3fecc0d603a03475a669"
},
"downloads": -1,
"filename": "validr-1.2.2.tar.gz",
"has_sig": false,
"md5_digest": "5d8b9ed1f33e364e1d73dc8d550d99c2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 336371,
"upload_time": "2023-12-13T20:40:33",
"upload_time_iso_8601": "2023-12-13T20:40:33.477930Z",
"url": "https://files.pythonhosted.org/packages/63/c0/4c4d6230d43c7276e14f4234b96a77e6487025a577c70bbfd526f77528b8/validr-1.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-13 20:40:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "guyskk",
"github_project": "validr",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"lcname": "validr"
}