跳转到主要内容

通用Python数据验证器

项目描述

警告:

:警告: 自2018年起,此库已弃用,请考虑使用jsonschema (https://pypi.python.org/pypi/jsonschema) 代替。

https://travis-ci.org/jamesturk/validictory.svg?branch=master https://coveralls.io/repos/jamesturk/validictory/badge.png?branch=master https://img.shields.io/pypi/v/validictory.svg Documentation Status

通用Python数据验证器。

基于JSON Schema提案的Schema格式 (https://json-schema.fullstack.org.cn)

包含来自Ian Lewis和Yusuke Muraoka的jsonschema库的代码。

用法

JSON文档和模式必须首先加载到Python字典类型中,然后才能进行验证。

解析简单的JSON文档

>>> import validictory
>>>
>>> validictory.validate("something", {"type":"string"})

解析更复杂的JSON文档

>>> import json
>>> import validictory
>>>
>>> data = json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
>>> schema = {
...   "type":"array",
...   "items":[
...     {"type":"string"},
...     {"type":"object",
...      "properties":{
...        "bar":{
...          "items":[
...            {"type":"string"},
...            {"type":"any"},
...            {"type":"number"},
...            {"type":"integer"}
...          ]
...        }
...      }
...    }
...   ]
... }
>>> validictory.validate(data,schema)

捕获ValueErrors以处理验证问题

>>> import validictory
>>>
>>> try:
...     validictory.validate("something", {"type":"string","minLength":15})
... except ValueError, error:
...     print(error)
...
Length of value 'something' for field '_data' must be greater than or equal to 15

您可以在官方文档中了解更多信息: Read the Docs.

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

validictory-1.1.3.tar.gz (29.9 kB 查看哈希值)

上传时间

构建分布

validictory-1.1.3-py2.py3-none-any.whl (11.3 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下支持