跳转到主要内容

可缓存的架构描述和验证

项目描述

https://readthedocs.org/projects/conformity/badge/ https://pepy.tech/badge/conformity https://img.shields.io/pypi/l/conformity.svg https://api.travis-ci.org/eventbrite/conformity.svg https://img.shields.io/pypi/v/conformity.svg https://img.shields.io/pypi/wheel/conformity.svg https://img.shields.io/pypi/pyversions/conformity.svg

一致性 是一个声明式架构验证库,旨在用于库、服务、应用程序设置等。


声明架构

from conformity.fields import Dictionary, Float, Integer, List, UnicodeString

person = Dictionary({
    "name": UnicodeString(),
    "height": Float(gte=0),
    "event_ids": List(Integer(gt=0)),
})

检查数据是否有效

data = {"name": "Andrew", "height": 180.3, "event_ids": [1, "3"]}
errors = person.errors(data)

# Key event_ids: Index 1: Not an integer

并将函数包装以在进入和退出时进行验证

kwargs = Dictionary({
    "name": UnicodeString(),
    "score": Integer(),
}, optional_keys=["score"])

@validate_call(kwargs, UnicodeString())
def greet(name, score=0):
    if score > 10:
        return "So nice to meet you, {}!".format(name)
    else:
        return "Hello, {}.".format(name)

支持基本字符串、数字、地理、时间、网络和其他字段类型,所有这些都易于扩展(可选地通过子类化)。一致性还支持完整的应用程序设置架构定义和验证,包括可定义的默认值,并包含Sphinx autodoc 扩展,以帮助您使用一致性生成有意义的代码文档。

许可证

一致性许可协议为 Apache许可证,版本2.0

安装

符合性可在PyPi上获得,可以直接通过Pip安装或在setup.pyrequirements.txtPipfile中列出。

pip install 'conformity~=1.26'
install_requires=[
    ...
    'conformity~=1.26',
    ...
]
conformity~=1.26
conformity = {version="~=1.26"}

文档

完整的符合性文档可在Read the Docs上找到!

项目详情


下载文件

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

源分发

conformity-1.28.2.tar.gz (43.6 kB 查看哈希值)

上传时间

构建分发

conformity-1.28.2-py27.py35.py36.py37.py38-none-any.whl (53.2 kB 查看哈希值)

上传时间 Python 2.7 Python 3.5 Python 3.6 Python 3.7 Python 3.8

由以下机构支持