Conformity - Declarative Schema for Python¶
Release: 1.28.2
Conformity is a declarative schema validation library designed for use in libraries, services, application settings, and more.
In just a few lines of code, you can define and validate a schema:
>>> person_schema = fields.Dictionary(
{
'name': fields.UnicodeString(),
'height': fields.Float(gt=0),
'age': fields.Nullable(fields.Integer(gte=0)),
'eye_color': fields.Constant('blue', 'brown', 'black', 'green', 'yellow', 'hazel'),
},
optional_keys=('eye_color', ),
)
>>> person_schema.errors({})
[Error(message='Missing key: name', code='MISSING', pointer='name'),
Error(message='Missing key: height', code='MISSING', pointer='height'),
Error(message='Missing key: age', code='MISSING', pointer='age')]
>>> person_schema.errors({'name': 'Scott', 'height': -2.0, 'age': 25})
[Error(message='Value not > 0', code='INVALID', pointer='height')]
>>> person_schema.errors({'name': 'Scott', 'height': 1.9, 'age': 25, 'eye_color': 'purple'})
[Error(message='Value is not one of: "black", "blue", "brown", "green", "hazel", "yellow"', code='UNKNOWN', pointer='eye_color')]
>>> person_schema.errors({'name': 'Scott', 'height': 1.9, 'age': 25, 'eye_color': 'brown'})
[]
>>> @validator.validate_call(fields.Dictionary({'person': person_schema}), returns=fields.Boolean())
def insert_person(person):
return True
>>> insert_person(person={})
ValidationError: Invalid keyword arguments:
- person.name: Missing key: name
- person.height: Missing key: height
- person.age: Missing key: age
>>> insert_person(person={'name': 'Scott', 'height': 1.9, 'age': 25, 'eye_color': 'purple'})
ValidationError: Invalid keyword arguments:
- person.eye_color: Value is not one of: "black", "blue", "brown", "green", "hazel", "yellow"
>>> insert_person(person={'name': 'Scott', 'height': 1.9, 'age': 25, 'eye_color': 'brown'})
True
Table of Contents¶
- Using Conformity Fields
- Using Conformity Settings
- Validating Values and Invocations
- API Reference Documentation
- Conformity Sphinx Extensions
- Contributing
- Changelog
- 1.28.1 (2022-09-01)
- 1.28.0 (2020-09-09)
- 1.27.3 (2020-06-29)
- 1.27.2 (2020-03-06)
- 1.27.1 (2020-03-05)
- 1.27.0 (2020-02-03)
- 1.26.8 (2019-12-02)
- 1.26.7 (2019-12-02)
- 1.26.6 (2019-11-04)
- 1.26.5 (2019-11-01)
- 1.26.4 (2019-11-01)
- 1.26.3 (2019-10-01)
- 1.26.2 (2019-09-16)
- 1.26.1 (2019-09-15)
- 1.26.0 (2019-09-13)
- 1.25.0 (2019-06-13)
- 1.24.3 (2019-06-12)
- 1.24.2 (2019-06-12)
- 1.24.1 (2019-06-11)
- 1.24.0 (2019-06-07)
- 1.23.0 (2019-06-05)
- 1.22.0 (2019-06-04)
- 1.21.0 (2019-04-17)
- 1.20.0 (2019-04-10)
- 1.19.2 (2019-01-30)
- 1.19.1 (2019-01-29)
- 1.19.0 (2019-01-29)
- 1.18.0 (2019-01-04)
- 1.17.2 (2018-11-15)
- 1.17.1 (2018-10-24)
- 1.17.0 (2018-09-06)
- 1.16.0 (2018-08-29)
- 1.15.1 (2018-06-13)
- 1.15.0 (2018-06-07)
- 1.14.0 (2018-05-25)
- 1.13.0 (2018-05-12)
- 1.12.0 (2018-05-01)
- 1.11.0 (2018-04-19)
- 1.10.0 (2018-04-10)
- 1.9.1 (2018-02-16)
- 1.9.0 (2018-02-13)
- 1.8.0 (2018-02-06)
- 1.7.5 (2018-02-05)
- 1.7.4 (2018-02-05)
- 1.7.3 (2018-02-05)
- 1.7.2 (2018-01-19)
- 1.7.1 (2018-01-18)
- 1.7.0 (2018-01-18)
- 1.6.1 (2017-10-14)
- 1.6.0 (2017-08-11)
- 1.5.0 (2017-05-02)
- 1.4.0 (2017-05-01)
- 1.3.1 (2017-04-25)
- 1.3.0 (2017-04-13)
- 1.2.0 (2017-02-06)
- 1.1.1 (2016-11-03)
- 1.1.0 (2016-10-25)
- 1.0.0 (2016-10-04)
Indices, Tables, and Searching¶
Copyright © 2023 Eventbrite, freely licensed under Apache License, Version 2.0.
Documentation generated 2023 January 10 22:12 UTC.