Docs Python Cerberus Org en Stable
Docs Python Cerberus Org en Stable
Release 1.3.2
Nicola Iarocci
1 At a Glance 3
2 Funding Cerberus 5
3 Table of Contents 7
3.1 Cerberus Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Cerberus Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Validation Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.4 Validation Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.5 Normalization Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.6 Errors & Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.7 Extending Cerberus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.8 How to Contribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.9 Funding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.10 API Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.11 Frequently Asked Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.12 External resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.13 Cerberus Changelog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.14 Upgrading to Cerberus 1.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.15 Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.16 Contact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.17 License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4 Copyright Notice 65
Index 69
i
ii
Cerberus Documentation, Release 1.3.2
CERBERUS, n. The watch-dog of Hades, whose duty it was to guard the entrance; everybody, sooner
or later, had to go there, and nobody wanted to carry off the entrance. - Ambrose Bierce, The Devil’s
Dictionary
Cerberus provides powerful yet simple and lightweight data validation functionality out of the box and is designed to
be easily extensible, allowing for custom validation. It has no dependencies and is thoroughly tested from Python 2.7
up to 3.8, PyPy and PyPy3.
Contents 1
Cerberus Documentation, Release 1.3.2
2 Contents
CHAPTER 1
At a Glance
You define a validation schema and pass it to an instance of the Validator class:
Then you simply invoke the validate() to validate a dictionary against the schema. If validation succeeds, True
is returned:
3
Cerberus Documentation, Release 1.3.2
4 Chapter 1. At a Glance
CHAPTER 2
Funding Cerberus
Cerberus is a collaboratively funded project. If you run a business and are using Cerberus in a revenue-generating
product, it would make business sense to sponsor its development: it ensures the project that your product relies on
stays healthy and actively maintained.
Individual users are also welcome to make either a recurring pledge or a one time donation if Cerberus has helped you
in your work or personal projects. Every single sign-up makes a significant impact towards making Cerberus possible.
To join the backer ranks, check out Cerberus campaign on Patreon.
5
Cerberus Documentation, Release 1.3.2
Table of Contents
This part of the documentation covers the installation of Cerberus. The first step to using any software package is
getting it properly installed.
Cerberus is actively developed in a GitHub Repository where the code. If you want to work with the development
version, there are two ways: You can either let pip pull in the development version, or you can tell it to operate on a
git checkout. Either way, virtualenv is recommended.
Get the git checkout in a new virtualenv and run in development mode.
7
Cerberus Documentation, Release 1.3.2
This will pull in the dependencies and activate the git head as the current version inside the virtualenv. Then all you
have to do is run git pull origin to update to the latest version.
To just get the development version without git, do this instead:
$ mkdir cerberus
$ cd cerberus
$ virtualenv venv --distribute
$ . venv/bin/activate
New python executable in venv/bin/python
Installing distribute............done.
$ pip install git+git://github.com/pyeve/cerberus.git
...
Cleaning up...
You define a validation schema and pass it to an instance of the Validator class:
Then you simply invoke the validate() to validate a dictionary against the schema. If validation succeeds, True
is returned:
Alternatively, you can pass both the dictionary and the schema to the validate() method:
>>> v = Validator()
>>> v.validate(document, schema)
True
Which can be handy if your schema is changing through the life of the instance.
Details about validation schemas are covered in Validation Schemas. See Validation Rules and Normalization Rules
for an extensive documentation of all supported rules.
Unlike other validation tools, Cerberus will not halt and raise an exception on the first validation issue. The whole
document will always be processed, and False will be returned if validation failed. You can then access the errors
property to obtain a list of issues. See Errors & Error Handling for different output options.
>>> schema = {'name': {'type': 'string'}, 'age': {'type': 'integer', 'min': 10}}
>>> document = {'name': 'Little Joe', 'age': 5}
>>> v.validate(document, schema)
False
>>> v.errors
{'age': ['min value is 10']}
The Validator class and its instances are callable, allowing for the following shorthand syntax:
However, you can allow unknown document keys pairs by either setting allow_unknown to True:
>>> v.schema = {}
>>> v.allow_unknown = True
>>> v.validate({'name': 'john', 'sex': 'M'})
True
Or you can set allow_unknown to a validation schema, in which case unknown fields will be validated against it:
>>> v.schema = {}
>>> v.allow_unknown = {'type': 'string'}
>>> v.validate({'an_unknown_field': 'john'})
True
>>> v.validate({'an_unknown_field': 1})
False
>>> v.errors
{'an_unknown_field': ['must be of string type']}
allow_unknown can also be set as rule to configure a validator for a nested mapping that is checked against the
schema rule:
>>> v = Validator()
>>> v.allow_unknown
False
>>> schema = {
... 'name': {'type': 'string'},
... 'a_dict': {
... 'type': 'dict',
(continues on next page)
>>> # this fails as allow_unknown is still False for the parent document.
>>> v.validate({'name': 'john',
... 'an_unknown_field': 'is not allowed',
... 'a_dict':{'an_unknown_field': 'is allowed'}},
... schema)
False
>>> v.errors
{'an_unknown_field': ['unknown field']}
Changed in version 0.9: allow_unknown can also be set for nested dict fields.
Changed in version 0.8: allow_unknown can also be set to a validation schema.
By default any keys defined in the schema are not required. However, you can require all document keys pairs by
setting require_all to True at validator initialization (v = Validator(..., require_all=True))
or change it latter via attribute access (v.require_all = True). require_all can also be set as rule to
configure a validator for a subdocument that is checked against the schema rule:
>>> v = Validator()
>>> v.require_all
False
>>> schema = {
... 'name': {'type': 'string'},
... 'a_dict': {
... 'type': 'dict',
... 'require_all': True,
... 'schema': {
... 'address': {'type': 'string'}
... }
... }
... }
The normalization and coercion are performed on the copy of the original document and the result document is avail-
able via document-property.
Beside the document-property a Validator-instance has shorthand methods to process a document and fetch its
processed result.
validated Method
There’s a wrapper-method validated() that returns the validated document. If the document didn’t validate None
is returned, unless you call the method with the keyword argument always_return_document set to True. It
can be useful for flows like this:
v = Validator(schema)
valid_documents = [x for x in [v.validated(y) for y in documents]
if x is not None]
If a coercion callable or method raises an exception then the exception will be caught and the validation with fail.
New in version 0.9.
normalized Method
Similarly, the normalized() method returns a normalized copy of a document without validating it:
3.2.5 Warnings
Warnings, such as about deprecations or likely causes of trouble, are issued through the Python standard library’s
warnings module. The logging module can be configured to catch these logging.captureWarnings().
A validation schema is a mapping, usually a dict. Schema keys are the keys allowed in the target dictionary. Schema
values express the rules that must be matched by the corresponding target values.
In the example above we define a target dictionary with only one key, name, which is expected to be a string not longer
than 10 characters. Something like {'name': 'john doe'} would validate, while something like {'name':
'a very long string'} or {'name': 99} would not.
By default all keys in a document are optional unless the required-rule is set True for individual fields or the valida-
tor’s :attr:~cerberus.Validator.require_all is set to True in order to expect all schema-defined fields to be present in
the document.
3.3.1 Registries
There are two default registries in the cerberus module namespace where you can store definitions for schemas and
rules sets which then can be referenced in a validation schema. You can furthermore instantiate more Registry
objects and bind them to the rules_set_registry or schema_registry of a validator. You may also set
these as keyword-arguments upon intitialization.
Using registries is particularly interesting if
• schemas shall include references to themselves, vulgo: schema recursion
• schemas contain a lot of reused parts and are supposed to be serialized
>>> from cerberus import schema_registry
>>> schema_registry.add('non-system user',
... {'uid': {'min': 1000, 'max': 0xffff}})
>>> schema = {'sender': {'schema': 'non-system user',
... 'allow_unknown': True},
... 'receiver': {'schema': 'non-system user',
... 'allow_unknown': True}}
3.3.2 Validation
Validation schemas themselves are validated when passed to the validator or a new set of rules is set for a document’s
field. A SchemaError is raised when an invalid validation schema is encountered. See Schema Validation Schema
for a reference.
However, be aware that no validation can be triggered for all changes below that level or when a used definition in a
registry changes. You could therefore trigger a validation and catch the exception:
>>> v = Validator({'foo': {'allowed': []}})
>>> v.schema['foo'] = {'allowed': 1}
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "cerberus/schema.py", line 99, in __setitem__
self.validate({key: value})
File "cerberus/schema.py", line 126, in validate
self._validate(schema)
File "cerberus/schema.py", line 141, in _validate
raise SchemaError(self.schema_validator.errors)
(continues on next page)
3.3.3 Serialization
Cerberus schemas are built with vanilla Python types: dict, list, string, etc. Even user-defined validation rules
are invoked in the schema by name as a string. A useful side effect of this design is that schemas can be defined in a
number of ways, for example with PyYAML.
You don’t have to use YAML of course, you can use your favorite serializer. json for example. As long as there is a
decoder that can produce a nested dict, you can use it to define a schema.
For populating and dumping one of the registries, use extend() and all().
3.4.1 allow_unknown
This can be used in conjunction with the schema rule when validating a mapping in order to set the allow_unknown
property of the validator for the subdocument. This rule has precedence over purge_unknown (see Purging Un-
known Fields). For a full elaboration refer to this paragraph.
3.4.2 allowed
This rule takes a collectionsabc.Container of allowed values. Validates the target value if the value is in the
allowed values. If the target value is an iterable, all its members must be in the allowed values.
3.4.3 allof
Validates if all of the provided constraints validates the field. See *of-rules for details.
New in version 0.9.
3.4.4 anyof
Validates if any of the provided constraints validates the field. See *of-rules for details.
New in version 0.9.
3.4.5 check_with
The error argument points to the calling validator’s _error method. See Extending Cerberus on how to submit
errors.
Here’s an example that tests whether an integer is odd or not:
If the rule’s constraint is a string, the Validator instance must have a method with that name prefixed by
_check_with_. See Methods that can be referenced by the check_with rule for an equivalent to the function-based
example above.
The constraint can also be a sequence of these that will be called consecutively.
Changed in version 1.3: The rule was renamed from validator to check_with
3.4.6 contains
This rule validates that the a container object contains all of the defined items.
3.4.7 dependencies
This rule allows one to define either a single field name, a sequence of field names or a mapping of field names and a
sequence of allowed values as required in the document if the field defined upon is present in the document.
>>> v.errors
{'field2': ["field 'field1' is required"]}
When multiple field names are defined as dependencies, all of these must be present in order for the target field to be
validated.
>>> v.errors
{'field3': ["field 'field1' is required"]}
When a mapping is provided, not only all dependencies must be present, but also any of their allowed values must be
matched.
>>> v.errors
{'field2': ["depends on these values: {'field1': 'one'}"]}
>>> schema = {
... 'test_field': {'dependencies': ['a_dict.foo', 'a_dict.bar']},
... 'a_dict': {
... 'type': 'dict',
... 'schema': {
... 'foo': {'type': 'string'},
... 'bar': {'type': 'string'}
... }
... }
... }
>>> v.errors
{'test_field': ["field 'a_dict.bar' is required"]}
When a subdocument is processed the lookup for a field in question starts at the level of that document. In order to
address the processed document as root level, the declaration has to start with a ^. An occurrence of two initial carets
(^^) is interpreted as a literal, single ^ with no special meaning.
>>> schema = {
... 'test_field': {},
... 'a_dict': {
... 'type': 'dict',
... 'schema': {
... 'foo': {'type': 'string'},
... 'bar': {'type': 'string', 'dependencies': '^test_field'}
... }
... }
... }
>>> v.errors
{'a_dict': [{'bar': ["field '^test_field' is required"]}]}
Note: If you want to extend semantics of the dot-notation, you can override the _lookup_field() method.
Note: The evaluation of this rule does not consider any constraints defined with the required rule.
3.4.8 empty
If constrained with False validation of an iterable value will fail if it is empty. Per default the emptiness of a field
isn’t checked and is therefore allowed when the rule isn’t defined. But defining it with the constraint True will skip
the possibly defined rules allowed, forbidden, items, minlength, maxlength, regex and validator
for that field when the value is considered empty.
>>> v.errors
{'name': ['empty values not allowed']}
3.4.9 excludes
>>> v = Validator()
>>> schema = {'this_field': {'type': 'dict',
... 'excludes': 'that_field'},
... 'that_field': {'type': 'dict',
... 'excludes': 'this_field'}}
>>> v.validate({'this_field': {}, 'that_field': {}}, schema)
False
>>> v.validate({'this_field': {}}, schema)
True
>>> v.validate({'that_field': {}}, schema)
True
>>> v.validate({}, schema)
True
>>> v = Validator()
>>> schema = {'this_field': {'type': 'dict',
... 'excludes': 'that_field',
... 'required': True},
... 'that_field': {'type': 'dict',
... 'excludes': 'this_field',
... 'required': True}}
(continues on next page)
3.4.10 forbidden
Opposite to allowed this validates if a value is any but one of the defined values:
3.4.11 items
Validates the items of any iterable against a sequence of rules that must validate each index-correspondent item. The
items will only be evaluated if the given iterable’s size matches the definition’s. This also applies during normalization
and items of a value are not normalized when the lengths mismatch.
See schema (list) rule for dealing with arbitrary length list types.
3.4.12 keysrules
This rules takes a set of rules as constraint that all keys of a mapping are validated with.
3.4.13 meta
This is actually not a validation rule but a field in a rules set that can conventionally be used for application specific
data that is descriptive for the document field:
Minimum and maximum value allowed for any object whose class implements comparison operations (__gt__ &
__lt__).
>>> v.errors
{'weight': ['max value is 10.9']}
Minimum and maximum length allowed for sized types that implement __len__.
>>> v.errors
{'numbers': ['max length is 3']}
3.4.16 noneof
Validates if none of the provided constraints validates the field. See *of-rules for details.
New in version 0.9.
3.4.17 nullable
If True the field value is allowed to be None. The rule will be checked on every field, regardless it’s defined or not.
The rule’s constraint defaults False.
3.4.18 *of-rules
These rules allow you to define different sets of rules to validate against. The field will be considered valid if it
validates against the set in the list according to the prefixes logics all, any, one or none.
Note: Normalization cannot be used in the rule sets within the constraints of these rules.
Note: Before you employ these rules, you should have investigated other possible solutions for the problem at hand
with and without Cerberus. Sometimes people tend to overcomplicate schemas with these rules.
For example, to verify that a field’s value is a number between 0 and 10 or 100 and 110, you could do the following:
The anyof rule tests each rules set in the list. Hence, the above schema is equivalent to creating two separate schemas:
*of-rules typesaver
You can concatenate any of-rule with an underscore and another rule with a list of rule-values to save typing:
Thus you can use this to validate a document against several schemas without implementing your own logic:
>>> invalid_employees_phones = []
>>> for employee in employees:
... if not employee_vldtr.validate(employee):
... invalid_employees_phones.append(employee)
3.4.19 oneof
Validates if exactly one of the provided constraints applies. See *of-rules for details.
New in version 0.9.
3.4.20 readonly
If True the value is readonly. Validation will fail if this field is present in the target dictionary. This is useful, for
example, when receiving a payload which is to be validated before it is sent to the datastore. The field might be
provided by the datastore, but should not writable.
A validator can be configured with the initialization argument purge_readonly and the property with the same
name to let it delete all fields that have this rule defined positively.
Changed in version 1.0.2: Can be used in conjunction with default and default_setter, see Default Values.
3.4.21 regex
The validation will fail if the field’s value does not match the provided regular expression. It is only tested on string
values.
>>> schema = {
... 'email': {
... 'type': 'string',
... 'regex': '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
... }
... }
>>> document = {'email': 'john@example.com'}
>>> v.validate(document, schema)
True
For details on regular expression syntax, see the documentation on the standard library’s re-module.
Hint: Mind that one can set behavioural flags as part of the expression which is equivalent to passing flags to
the re.compile() function for example. So, the constraint '(?i)holy grail' includes the equivalent of the
re.I flag and matches any string that includes ‘holy grail’ or any variant of it with upper-case glyphs. Look for
(?aiLmsux) in the mentioned library documentation for a description there.
3.4.22 require_all
This can be used in conjunction with the schema rule when validating a mapping in order to set the require_all
property of the validator for the subdocument. For a full elaboration refer to this paragraph.
3.4.23 required
If True the field is mandatory. Validation will fail when it is missing, unless validate() is called with
update=True:
>>> v.schema = {'name': {'required': True, 'type': 'string'}, 'age': {'type': 'integer
˓→'}}
Note: To define all fields of a document as required see this section about the available options.
Note: String fields with empty values will still be validated, even when required is set to True. If you don’t want
to accept empty values, see the empty rule.
Note: The evaluation of this rule does not consider any constraints defined with the dependencies rule.
If a field for which a schema-rule is defined has a mapping as value, that mapping will be validated against the
schema that is provided as constraint.
Note: To validate arbitrary keys of a mapping, see keysrules-rule, resp. valuesrules-rule for validating arbitrary
values of a mapping.
If schema-validation encounters an arbritrary sized sequence as value, all items of the sequence will be validated
against the rules provided in schema’s constraint.
The schema rule on list types is also the preferred method for defining and validating a list of dictionaries.
Note: Using this rule should be accompanied with a type-rule explicitly restricting the field to the list-type like
in the example. Otherwise false results can be expected when a mapping is validated against this rule with constraints
for a sequence.
Changed in version 0.0.3: Schema rule for list types of arbitrary length
3.4.26 type
Data type allowed for the key value. Can be one of the following names:
Note: While the type rule is not required to be set at all, it is not encouraged to leave it unset especially when
using more complex rules such as schema. If you decide you still don’t want to set an explicit type, rules such as
schema are only applied to values where the rules can actually be used (such as dict and list). Also, in the case
of schema, cerberus will try to decide if a list or a dict type rule is more appropriate and infer it depending on
what the schema rule looks like.
Note: Please note that type validation is performed before most others which exist for the same field (only nullable
and readonly are considered beforehand). In the occurrence of a type failure subsequent validation rules on the field
will be skipped and validation will continue on other fields. This allows one to safely assume that field type is correct
when other (standard or custom) rules are invoked.
checking for list/Sequence because it in the validation situation it is almost certain the string was not the intended
data type for a sequence.
Changed in version 0.7: Added the set data type.
Changed in version 0.6: Added the number data type.
Changed in version 0.4.0: Type validation is always executed first, and blocks other field validation rules on failure.
Changed in version 0.3.0: Added the float data type.
3.4.27 valuesrules
This rules takes a set of rules as constraint that all values of a mapping are validated with.
>>> v.errors
{'numbers': [{'an integer': ['min value is 10']}]}
Normalization rules are applied to fields, also in schema for mappings, as well when defined as a bulk operation by
schema (for sequences), allow_unknown, keysrules and valuesrules. Normalization rules in definitions
for testing variants like with anyof are not processed.
The normalizations are applied as given in this document for each level in the mapping, traversing depth-first.
To let a callable rename a field or arbitrary fields, you can define a handler for renaming. If the constraint is a string,
it points to a custom method. If the constraint is an iterable, the value is processed through that chain.
After renaming, unknown fields will be purged if the purge_unknown property of a Validator instance is True;
it defaults to False. You can set the property per keyword-argument upon initialization or as rule for subdocu-
ments like allow_unknown (see Allowing the Unknown). The default is False. If a subdocument includes an
allow_unknown rule then unknown fields will not be purged on that subdocument.
You can set default values for missing fields in the document by using the default rule.
You can also define a default setter callable to set the default value dynamically. The callable gets called with the
current (sub)document as the only argument. Callables can even depend on one another, but normalizing will fail if
there is a unresolvable/circular dependency. If the constraint is a string, it points to a custom method.
>>> v.normalized({})
>>> v.errors
{'a': ["default value for 'a' cannot be set: Circular dependencies of default setters.
˓→"]}
You can even use both default and readonly on the same field. This will create a field that cannot be assigned a
value manually but it will be automatically supplied with a default value by Cerberus. Of course the same applies for
default_setter.
Changed in version 1.0.2: Can be used in conjunction with readonly.
New in version 1.0.
Coercion allows you to apply a callable (given as object or the name of a custom coercion method) to a value before
the document is validated. The return value of the callable replaces the new value in the document. This can be used
to convert values or sanitize data before it is validated. If the constraint is an iterable of callables and names, the value
is processed through that chain of coercers.
Errors can be evaluated via Python interfaces or be processed to different output formats with error handlers.
Error handlers will return different output via the errors property of a validator after the processing of a document.
They base on BaseErrorHandler which defines the mandatory interface. The error handler to be used can be
passed as keyword-argument error_handler to the initialization of a validator or by setting it’s property with the
same name at any time. On initialization either an instance or a class can be provided. To pass keyword-arguments
to the initialization of a class, provide a two-value tuple with the error handler class and the dictionary containing the
arguments.
The following handlers are available:
• BasicErrorHandler: This is the default that returns a dictionary. The keys refer to the document’s ones
and the values are lists containing error messages. Errors of nested fields are kept in a dictionary as last item of
these lists.
Examples
Though you can use functions in conjunction with the coerce and the validator rules, you can easily extend the
Validator class with custom rules, types, validators, coercers and default_setters. While the function-based style
is more suitable for special and one-off uses, a custom class leverages these possibilities:
• custom rules can be defined with constrains in a schema
• extending the available type s
• use additional contextual data
• schemas are serializable
The references in schemas to these custom methods can use space characters instead of underscores, e.g. {'foo':
{'validator': 'is odd'}} is an alias for {'foo': {'validator': 'is_odd'}}.
Suppose that in our use case some values can only be expressed as odd integers, therefore we decide to add support
for a new isodd rule to our validation schema:
class MyValidator(Validator):
def _validate_isodd(self, isodd, field, value):
""" Test the oddity of a value.
By subclassing Cerberus Validator class and adding the custom _validate_<rulename> method, we just
enhanced Cerberus to suit our needs. The custom rule isodd is now available in our schema and, what really matters,
we can use it to validate all odd values:
>>> v = MyValidator(schema)
>>> v.validate({'amount': 10})
False
>>> v.errors
{'amount': ['Must be an odd number']}
>>> v.validate({'amount': 9})
True
As schemas themselves are validated, you can provide constraints as literal Python expression in the docstring of the
rule’s implementing method to validate the arguments given in a schema for that rule. Either the docstring contains
solely the literal or the literal is placed at the bottom of the docstring preceded by The rule's arguments are
validated against this schema: See the source of the contributed rules for more examples.
Cerberus supports and validates several standard data types (see type). When building a custom validator you can add
and validate your own data types.
Additional types can be added on the fly by assigning a TypeDefinition to the designated type name in
types_mapping:
Validator.types_mapping['decimal'] = decimal_type
Caution: As the types_mapping property is a mutable type, any change to its items on an instance will affect
its class.
class MyValidator(Validator):
types_mapping = Validator.types_mapping.copy()
types_mapping['decimal'] = decimal_type
If a validation test doesn’t depend on a specified constraint from a schema or needs to be more complex than a rule
should be, it’s possible to rather define it as value checker than as a rule. There are two ways to use the check_with
rule.
One is by extending Validator with a method prefixed with _check_with_. This allows to access the whole
context of the validator instance including arbitrary configuration values and state. To reference such method using
the check_with rule, simply pass the unprefixed method name as a string constraint.
For example, one can define an oddity validator method as follows:
class MyValidator(Validator):
def _check_with_oddity(self, field, value):
if not value & 1:
self._error(field, "Must be an odd number")
The second option to use the rule is to define a standalone function and pass it as the constraint. This brings with it the
benefit of not having to extend Validator. To read more about this implementation and see examples check out the
rule’s documentation.
You can also define custom methods that return a coerce d value or point to a method as rename_handler. The
method name must be prefixed with _normalize_coerce_.
class MyNormalizer(Validator):
def __init__(self, multiplier, *args, **kwargs):
super(MyNormalizer, self).__init__(*args, **kwargs)
self.multiplier = multiplier
Similar to custom rename handlers, it is also possible to create custom default setters.
class MyNormalizer(Validator):
def _normalize_default_setter_utcnow(self, document):
return datetime.utcnow()
3.7.6 Limitations
It’s possible to pass arbitrary configuration values when instantiating a Validator or a subclass as keyword argu-
ments (whose names are not used by Cerberus). These can be used in all of the handlers described in this document
that have access to the instance. Cerberus ensures that this data is available in all child instances that may get spawned
during processing. When you implement an __init__ method on a customized validator, you must ensure that all
positional and keyword arguments are also passed to the parent class’ initialization method. Here’s an example pattern:
class MyValidator(Validator):
def __init__(self, *args, **kwargs):
# assign a configuration value to an instance property
# for convenience
self.additional_context = kwargs.get('additional_context')
# pass all data to the base classes
super(MyValidator, self).__init__(*args, **kwargs)
Warning: It is neither recommended to access the _config property in other situations than outlined in the
sketch above nor to to change its contents during the processing of a document. Both cases are not tested and are
unlikely to get officially supported.
There are some attributes of a Validator that you should be aware of when writing custom Validators.
Validator.document
A validator accesses the document property when fetching fields for validation. It also allows validation of a field to
happen in context of the rest of the document.
New in version 0.7.1.
Validator.schema
Note: This attribute is not the same object that was passed as schema to the validator at some point. Also, its content
may differ, though it still represents the initial constraints. It offers the same interface like a dict.
Validator._error
There are three signatures that are accepted to submit errors to the Validator’s error stash. If necessary the given
information will be parsed into a new instance of ValidationError.
Full disclosure
In order to be able to gain complete insight into the context of an error at a later point, you need to call _error()
with two mandatory arguments:
• the field where the error occurred
• an instance of a ErrorDefinition
For custom rules you need to define an error as ErrorDefinition with a unique id and the causing rule that is
violated. See errors for a list of the contributed error definitions. Keep in mind that bit 7 marks a group error, bit 5
marks an error raised by a validation against different sets of rules.
Optionally you can submit further arguments as information. Error handlers that are targeted for humans will use
these as positional arguments when formatting a message with str.format(). Serializing handlers will keep these
values in a list.
New in version 1.0.
A simpler form is to call _error() with the field and a string as message. However the resulting error will contain
no information about the violated constraint. This is supposed to maintain backward compatibility, but can also be
used when an in-depth error handling isn’t needed.
Multiple errors
When using child-validators, it is a convenience to submit all their errors ; which is a list of ValidationError
instances.
New in version 1.0.
Validator._get_child_validator
If you need another instance of your Validator-subclass, the _get_child_validator()-method returns an-
other instance that is initiated with the same arguments as self was. You can specify overriding keyword-arguments.
As the properties document_path and schema_path (see below) are inherited by the child validator, you can
extend these by passing a single value or values-tuple with the keywords document_crumb and schema_crumb.
Study the source code for example usages.
New in version 0.9.
Changed in version 1.0: Added document_crumb and schema_crumb as optional keyword- arguments.
A child-validator - as used when validating a schema - can access the first generation validator’s document
and schema that are being processed as well as the constraints for unknown fields via its root_document,
root_schema, root_allow_unknown and root_require_all properties.
New in version 1.0.
Changed in version 1.3: Added root_require_all
These properties maintain the path of keys within the document respectively the schema that was traversed by possible
parent-validators. Both will be used as base path when an error is submitted.
New in version 1.0.
Validator.recent_error
The last single error that was submitted is accessible through the recent_error-attribute.
New in version 1.0.
You can use these class properties and instance instance property if you want to adjust the validation logic for each
field validation. mandatory_validations is a tuple that contains rules that will be validated for each field,
regardless if the rule is defined for a field in a schema or not. priority_validations is a tuple of ordered rules
that will be validated before any other. _remaining_rules is a list that is populated under consideration of these
and keeps track of the rules that are next in line to be evaluated. Thus it can be manipulated by rule handlers to change
the remaining validation for the current field. Preferably you would call _drop_remaining_rules() to remove
particular rules or all at once.
New in version 1.0.
Changed in version 1.2: Added _remaining_rules for extended leverage.
Contributions are welcome! Not familiar with the codebase yet? No problem! There are many ways to contribute to
open source projects: reporting bugs, helping with the documentation, spreading the word and of course, adding new
features and patches.
Note: There’s currently a feature freeze until the basic code modernization for the 2.0 release is finished. Have a look
at the ROADMAP.md for a status on its progress.
There are usually several TODO comments scattered around the codebase, maybe check them out and see if you have
ideas, or can help with them. Also, check the open issues in case there’s something that sparks your interest. What
about documentation? I suck at english so if you’re fluent with it (or notice any error), why not help with that? In any
case, other than GitHub help pages, you might want to check this excellent Effective Guide to Pull Requests
Cerberus runs under Python 2.7, 3.4, 3.5, 3.6, PyPy and PyPy3. Therefore tests will be run in those four platforms in
our continuous integration server.
The easiest way to get started is to run the tests in your local environment with:
Before you submit a pull request, make sure your tests and changes run in all supported python versions. Instead of
creating all those environments by hand, Cerberus uses tox.
Make sure you have all required python versions installed and run:
This might take some time the first run as the different virtual environments are created and dependencies are installed.
If everything is ok, you will see the following:
If something goes wrong and one test fails, you might need to run that test in the specific python version. You can use
the created environments to run some specific tests. For example, if a test suite fails in Python 3.4:
Have a look at /tox.ini for the available test environments and their workings.
Using Pytest
You also choose to run the whole test suite using pytest:
Using Docker
If you have a running Docker-daemon running you can run tests from a container that has the necessary interpreters
and packages installed and pass arguments to tox:
You can run the script without any arguments to test the project exactly as Continuous Integration does without having
to setup anything. The tox environments are preserved in a volume named cerberus-tox, just remove it with
docker volume rm to clean them.
To preview the rendered HTML-documentation you must initially install the documentation framework and a theme:
$ # in 'docs'-folder
$ make html
Continuous Integration
Each time code is pushed to the master branch the whole test-suite is executed on Travis-CI. This is also the case
for pull-requests. A box at the bottom of its conversation-view will inform about the tests’ status. The contributor can
then fix the code, add commits, squash the commits and push again. The CI will also run flake8 so make sure that your
code complies to PEP8 and test links and sample-code in the documentation.
3.9 Funding
We believe that collaboratively funded software can offer outstanding returns on investment, by encouraging users to
collectively share the cost of development.
Cerberus continues to be open-source and permissively licensed, but we firmly believe it is in the commercial best-
interest for users of the project to invest in its ongoing development.
Signing up as a Backer:
• Directly contribute to faster releases, more features, and higher quality software.
• Allow more time to be invested in documentation, issue triage, and community support.
• Safeguard the future development of Cerberus.
If you run a business and is using Cerberus in a revenue-generating product, it would make business sense to sponsor
its development: it ensures the project that your product relies on stays healthy and actively maintained. It can also
help your exposure in the Cerberus community and makes it easier to attract Cerberus developers.
Of course, individual users are also welcome to make a recurring pledge if Cerberus has helped you in your work or
personal projects. Alternatively, consider donating as a sign of appreciation - like buying me coffee once in a while :)
3.9. Funding 39
Cerberus Documentation, Release 1.3.2
Parameters
• document_crumb (tuple or hashable) – Extends the document_path of the child-
validator.
• schema_crumb (tuple or hashable) – Extends the schema_path of the child-
validator.
• kwargs (dict) – Overriding keyword-arguments for initialization.
Returns an instance of self.__class__
_lookup_field(path)
Searches for a field as defined by path. This method is used by the dependency evaluation logic.
Parameters path (str) – Path elements are separated by a .. A leading ^ indicates that the
path relates to the document root, otherwise it relates to the currently evaluated document,
which is possibly a subdocument. The sequence ^^ at the start will be interpreted as a literal
^.
Returns Either the found field name and its value or None for both.
Return type A two-value tuple.
allow_unknown
If True unknown fields that are not defined in the schema will be ignored. If a mapping with a validation
schema is given, any undefined field will be validated against its rules. Also see Allowing the Unknown.
Type: bool or any mapping
classmethod clear_caches()
Purge the cache of known valid schemas.
errors
The errors of the last processing formatted by the handler that is bound to error_handler.
ignore_none_values
Whether to not process None-values in a document or not. Type: bool
is_child
True for child-validators obtained with _get_child_validator(). Type: bool
normalized(document, schema=None, always_return_document=False)
Returns the document normalized according to the specified rules of a schema.
Parameters
• document (any mapping) – The document to normalize.
• schema (any mapping) – The validation schema. Defaults to None. If not provided here,
the schema must have been provided at class instantiation.
• always_return_document (bool) – Return the document, even if an error oc-
curred. Defaults to: False.
Returns A normalized copy of the provided mapping or None if an error occurred during nor-
malization.
purge_unknown
If True, unknown fields will be deleted from the document unless a validation is called with disabled
normalization. Also see Purging Unknown Fields. Type: bool
require_all
If True known fields that are defined in the schema will be required. Type: bool
root_allow_unknown
The allow_unknown attribute of the first level ancestor of a child validator.
root_document
The document attribute of the first level ancestor of a child validator.
root_require_all
The require_all attribute of the first level ancestor of a child validator.
root_schema
The schema attribute of the first level ancestor of a child validator.
rules_set_registry
The registry that holds referenced rules sets. Type: Registry
schema
The validation schema of a validator. When a schema is passed to a method, it replaces this attribute. Type:
any mapping or None
schema_registry
The registry that holds referenced schemas. Type: Registry
validate(document, schema=None, update=False, normalize=True)
Normalizes and validates a mapping against a validation-schema of defined rules.
Parameters
• document (any mapping) – The document to normalize.
• schema (any mapping) – The validation schema. Defaults to None. If not provided here,
the schema must have been provided at class instantiation.
• update (bool) – If True, required fields won’t be checked.
• normalize (bool) – If True, normalize the document before validation.
Returns True if validation succeeds, otherwise False. Check the errors() property for a
list of processing errors.
Return type bool
validated(*args, **kwargs)
Wrapper around validate() that returns the normalized and validated document or None if validation
failed.
class cerberus.schema.Registry(definitions={})
A registry to store and retrieve schemas and parts of it by a name that can be used in validation schemas.
Parameters definitions (any mapping) – Optional, initial definitions.
add(name, definition)
Register a definition to the registry. Existing definitions are replaced silently.
Parameters
• name (str) – The name which can be used as reference in a validation schema.
• definition (any mapping) – The definition.
all()
Returns a dict with all registered definitions mapped to their name.
clear()
Purge all definitions in the registry.
extend(definitions)
Add several definitions at once. Existing definitions are replaced silently.
Parameters definitions (a mapping or an iterable with two-value tuple s) – The names
and definitions.
get(name, default=None)
Retrieve a definition from the registry.
Parameters
• name (str) – The reference that points to the definition.
• default – Return value if the reference isn’t registered.
remove(*names)
Unregister definitions from the registry.
Parameters names – The names of the definitions that are to be unregistered.
Optionally emits an error in the handler’s format to a stream. Or light a LED, or even shut down a
power plant.
end(validator)
Gets called when a validation ends.
Parameters validator (Validator) – The calling validator.
extend(errors)
Adds all errors to the handler’s container object.
Parameters errors (iterable of ValidationError instances) – The errors to add.
start(validator)
Gets called when a validation starts.
Parameters validator (Validator) – The calling validator.
class cerberus.errors.BasicErrorHandler(tree=None)
Models cerberus’ legacy. Returns a dict. When mangled through str a pretty-formatted representation of
that tree is returned.
is_logic_error
True for validation errors against different schemas with *of-rules.
is_normalization_error
True for normalization errors.
rule = None
The rule that failed. Type: string
schema_path = None
The path to the rule within the schema that caused the error. Type: tuple
value = None
The value that failed.
Error Codes
Its code attribute uniquely identifies an ErrorDefinition that is used a concrete error’s code. Some codes are
actually reserved to mark a shared property of different errors. These are useful as bitmasks while processing errors.
This is the list of the reserved codes:
None of these bits in the upper nibble must be used to enumerate error definitions, but only to mark one with the
associated property.
Important: Users are advised to set bit 8 for self-defined errors. So the code 0001 0000 0001 / 0x101 would
the first in a domain-specific set of error definitions.
This is a list of all error defintions that are shipped with the errors module:
Error Containers
class cerberus.errors.ErrorList
A list for ValidationError instances that can be queried with the in keyword for a particular
ErrorDefinition.
class cerberus.errors.ErrorTree(errors=())
Base class for DocumentErrorTree and SchemaErrorTree.
add(error)
Add an error to the tree.
Parameters error – ValidationError
fetch_errors_from(path)
Returns all errors for a particular path.
Parameters path – tuple of hashable s.
Return type ErrorList
fetch_node_from(path)
Returns a node for a path.
Parameters path – Tuple of hashable s.
Return type ErrorTreeNode or None
class cerberus.errors.DocumentErrorTree(errors=())
Implements a dict-like class to query errors by indexes following the structure of a validated document.
class cerberus.errors.SchemaErrorTree(errors=())
Implements a dict-like class to query errors by indexes following the structure of the used schema.
3.10.6 Exceptions
exception cerberus.SchemaError
Raised when the validation schema is missing, has the wrong format or contains errors.
exception cerberus.DocumentError
Raised when the target document is missing or has the wrong format
3.10.7 Utilities
Parameters
• name (str) – The name of the new class.
• bases (tuple of or a single class) – Class(es) with additional and overriding attributes.
• namespace (dict) – Attributes for the new class.
Returns The created class.
Against this schema validation schemas given to a vanilla Validator will be validated:
Here are some recommended resources that deal with Cerberus. If you find something interesting on the web, please
amend it to this document and open a pull request (see How to Contribute).
Clickbait that mentions Cerberus. It’s a starting point to compare libraries with a similar scope though.
3.12.2 Nicola Iarocci: Cerberus, or Data Validation for Humans (November 2017)
Get fastened for the full tour on Cerberus that Nicola gave in a talk at PiterPy 2017. No bit is missed, so don’t miss it!
The talk also includes a sample of the actual pronunciation of Iarocci as extra takeaway.
3.12.3 Henry Ölsner: Validate JSON data using cerberus (March 2016)
In this blog post the author describes how to validate network configurations with a schema noted in YAML. The
article that doesn’t spare on code snippets develops the resulting schema by gradually increasing its complexity. A
custom type check is also implemented, but be aware that version 0.9.2 is used. With 1.0 and later the implementation
should look like this:
New
Fixed
• Fixed the message of the BasicErrorHandler for an invalid amount of items (#505)
• Added setuptools as dependency to the package metadata (#499)
• The CHANGES.rst document is properly included in the package (#493)
Improved
• Docs: Examples were added for the min- and maxlength rules. (#509)
Fixed
• Fixed the expansion of the deprecated rule names keyschema and valueschema (#482)
• *of_-typesavers properly expand rule names containing _ (#484)
Improved
New
Fixed
Improved
Docs
• Fix semantical versioning naming. There are only two hard things in Computer Science: cache invalidation and
naming things – Phil Karlton (#429)
• Improve documentation of the regex rule (#389)
• Expand upon validator rules (#320)
• Include all errors definitions in API docs (#404)
• Improve changelog format (#406)
• Update homepage URL in package metadata (#382)
• Add feature freeze note to CONTRIBUTING and note on Python support in README
• Add the intent of a dataclasses module to ROADMAP.md
• Update README link; make it point to the new PyPI website
• Update README with elaborations on versioning and testing
• Fix misspellings and missing pronouns
• Remove redundant hint from *of-rules.
• Add usage recommendation regarding the *of-rules
• Fix: Creating custom Validator instance with _validator_* method raises SchemaError. Closes #265
(Frank Sachsenheim).
• Fix: Consistently use new style classes (Dominik Kellner).
• Fix: NotImplemented does not derive from BaseException. (Bryan W. Weber).
• Completely switch to py.test. Closes #213 (Frank Sachsenheim).
• Convert self.assert method calls to plain assert calls supported by pytest. Addresses #213 (Bruno
Oliveira).
• Docs: Clarifications concerning dependencies and unique rules. (Frank Sachsenheim)
• Docs: Fix custom coerces documentation. Closes #285. (gilbsgilbs)
• Docs: Add note concerning regex flags. Closes #173. (Frank Sachsenheim)
• Docs: Explain that normalization and coercion are performed on a copy of the original document (Sergey
Leshchenko)
Warning: This is a major release which breaks backward compatibility in several ways. Don’t worry, these
changes are for the better. However, if you are upgrading, then you should really take the time to read the list of
Breaking Changes and consider their impact on your codebase. For your convenience, some upgrade notes have
been included.
• New: Allows various error output with error handlers (Frank Sachsenheim).
• New: Available rules etc. of a Validator-instance are accessible as ‘validation_rules’, ‘normalization_rules’,
‘types’, ‘validators’ and ‘coercer’ -property. (Frank Sachsenheim)
• New: Custom rule’s method docstrings can contain an expression to validate constraints for that rule when a
schema is validated. (Frank Sachsenheim).
• New: ‘Validator.root_schema’ complements ‘Validator.root_document’. (Frank Sachsenheim)
• New: ‘Validator.document_path’ and ‘Validator.schema_path’ properties can be used to determine the relation
of the currently validating document to the ‘root_document’ / ‘root_schema’. (Frank Sachsenheim)
• New: Known, validated definition schemas are cached, thus validation run-time of schemas is reduced. (Frank
Sachsenheim)
• New: Add testing with Docker. (Frank Sachsenheim)
• New: Support CPython 3.5. (Frank Sachsenheim)
• Fix: ‘allow_unknown’ inside *of rule is ignored. Closes #251. (Davis Kirkendall)
• Fix: unexpected TypeError when using allow_unknown in a schema defining a list of dicts. Closes #250. (Davis
Kirkendall)
• Fix: validate with ‘update=True’ does not work when required fields are in a list of subdicts. (Jonathan Huot)
• Fix: ‘number’ type fails if value is boolean. Closes #144. (Frank Sachsenheim)
• Fix: allow None in ‘default’ normalization rule. (Damián Nohales)
• Fix: in 0.9.2, coerce does not maintain proper nesting on dict fields. Closes #185.
• Fix: normalization not working for valueschema and propertyschema. Closes #155. (Frank Sachsenheim)
• Fix: ‘coerce’ on List elements produces unexpected results. Closes #161. (Frank Sachsenheim)
• Fix: ‘coerce’-constraints are validated. (Frank Sachsenheim)
• Fix: Unknown fields are normalized. (Frank Sachsenheim)
• Fix: Dependency on boolean field now works as expected. Addresses #138. (Roman Redkovich)
• Fix: Add missing deprecation-warnings. (Frank Sachsenheim)
• Docs: clarify read-only rule. Closes #127.
• Docs: split Usage page into Usage; Validation Rules: Normalization Rules. (Frank Sachsenheim)
Breaking Changes
Several relevant breaking changes have been introduced with this release. For the inside scoop, please see the upgrade
notes.
• Change: ‘errors’ values are lists containing error messages. Previously, they were simple strings if single errors,
lists otherwise. Closes #210. (Frank Sachsenheim)
• Change: Custom validator methods: remove the second argument. (Frank Sachsenheim)
• Change: Custom validator methods: invert the logic of the conditional clauses where is tested what a value is
not / has not. (Frank Sachsenheim)
• Change: Custom validator methods: replace calls to ‘self._error’ with ‘return True’, or False, or None. (Frank
Sachsenheim)
• Change: Remove ‘transparent_schema_rule’ in favor of docstring schema validation. (Frank Sachsenheim)
• Fix: when ‘items’ is applied to a list, field name is used as key for ‘validator.errors’, and offending field indexes
are used as keys for field errors ({‘a_list_of_strings’: {1: ‘not a string’}}) ‘type’ can be a list of valid types.
• Fix: Ensure that additional **kwargs of a subclass persist through validation (Frank Sachsenheim).
• Fix: improve failure message when testing against multiple types (Frank Sachsenheim).
• Fix: ignore ‘keyschema’ when not a mapping (Frank Sachsenheim).
• Fix: ignore ‘schema’ when not a sequence (Frank Sachsenheim).
• Fix: allow_unknown can also be set for nested dicts. Closes #75. (Tobias Betz)
• Fix: raise SchemaError when an unallowed ‘type’ is used in conjunction with ‘schema’ rule (Tobias Betz).
• Docs: added section that points out that YAML, JSON, etc. can be used to define schemas (C.D. Clark III).
• Docs: Improve ‘allow_unknown’ documentation (Frank Sachsenheim).
Error Handling
The inspection on and representation of errors is thoroughly overhauled and allows a more detailed and flexible han-
dling. Make sure you have look on Errors & Error Handling.
Also, errors (as provided by the default BasicErrorHandler) values are lists containing error messages, and
possibly a dict as last item containing nested errors. Previously, they were strings if single errors per field occurred;
lists otherwise.
3.14.2 Deprecations
Validator class
transparent_schema_rules
In the past you could override the schema validation by setting transparent_schema_rules to True. Now all
rules whose implementing method’s docstring contain a schema to validate the arguments for that rule in the validation
schema, are validated. To omit the schema validation for a particular rule, just omit that definition, but consider it a bad
practice. The Validator-attribute and -initialization-argument transparent_schema_rules are removed
without replacement.
validate_update
The method validate_update has been removed from Validator. Instead use validate() with the
keyword-argument update set to True.
Rules
The usage of the items-rule is restricted to sequences. If you still had schemas that used that rule to validate
mappings, just rename these instances to schema (docs).
To reflect the common terms in the Pythoniverse1 , the rule for validating all values of a mapping was renamed
from keyschema to valueschema. Furthermore a rule was implemented to validate all keys, introduced as
propertyschema, now renamed to keyschema. This means code using prior versions of cerberus would not
break, but bring up wrong results!
To update your code you may adapt cerberus’ iteration:
1. Rename keyschema to valueschema in your schemas. (0.9)
2. Rename propertyschema to keyschema in your schemas. (1.0)
Note that propertyschema will not be handled as an alias like keyschema was in the 0.9-branch.
Custom validators
Data types
Since the type-rule allowed multiple arguments cerberus’ type validation code was somewhat cumbersome as it had
to deal with the circumstance that each type checking method would file an error though another one may not - and
thus positively validate the constraint as a whole. The refactoring of the error handling allows cerberus’ type validation
to be much more lightweight and to formulate the corresponding methods in a simpler way.
Previously such a method would test what a value is not and submit an error. Now a method tests what a value is to be
expected and returns True in that case.
This is the most critical part of updating your code, but still easy when your head is clear. Of course your code is well
tested. It’s essentially these three steps. Search, Replace and Regex may come at your service.
1. Remove the second method’s argument (probably named field).
2. Invert the logic of the conditional clauses where is tested what a value is not / has not.
3. Replace calls to self._error below such clauses with return True.
A method doesn’t need to return False or any value when expected criteria are not met.
Here’s the change from the documentation example.
pre-1.0:
1 compare dictionary
1.0:
3.15 Authors
Cerberus is developed and maintained by the Cerberus community. It was created by Nicola Iarocci.
3.15.2 Contributors
• Antoine Lubineau
• Arsh Singh
• Audric Schiltknecht
• Brandon Aubie
• Brett
• Bruno Oliveira
• Bryan W. Weber
• C.D. Clark III
• Christian Hogan
• Connor Zapfel
• Damián Nohales
• Danielle Pizzolli
• Davis Kirkendall
• Denis Carriere
• Dominik Kellner
• Eelke Hermens
• Evgeny Odegov
• Florian Rathgeber
• Gabriel Wainer
3.15. Authors 61
Cerberus Documentation, Release 1.3.2
3.16 Contact
If you’ve scoured the prose and API documentation and still can’t find an answer to your question, below are various
support resources that should help. We do request that you do at least skim the documentation before posting tickets
or mailing list questions, however!
If you’d like to stay up to date on the community and development of Cerberus, there are several options:
3.16.1 Blog
3.16.2 Twitter
I often tweet about new features and releases of Cerberus. Follow @nicolaiarocci.
The mailing list is intended to be a low traffic resource for users, developers and contributors of both the Cerberus and
Eve projects.
To file new bugs or search existing ones, you may visit Issues page. This does require a (free and easy to set up)
GitHub account.
Of course the best way to track the development of Cerberus is through the GitHub repo.
3.17 License
3.16. Contact 63
Cerberus Documentation, Release 1.3.2
Copyright Notice
Cerberus is an open source project by Nicola Iarocci. See the original LICENSE for more information.
65
Cerberus Documentation, Release 1.3.2
c
cerberus.utils, 47
67
Cerberus Documentation, Release 1.3.2
Symbols D
__call__() (cerberus.errors.BaseErrorHandler definitions_errors (cer-
method), 43 berus.errors.ValidationError attribute), 44
__init__() (cerberus.errors.BaseErrorHandler document_path (cerberus.errors.ValidationError at-
method), 43 tribute), 44
__iter__() (cerberus.errors.BaseErrorHandler DocumentError, 47
method), 43 DocumentErrorTree (class in cerberus.errors), 46
__weakref__ (cerberus.errors.BaseErrorHandler at-
tribute), 43 E
_drop_remaining_rules() (cerberus.Validator emit() (cerberus.errors.BaseErrorHandler method),
method), 40 43
_error() (cerberus.Validator method), 40 end() (cerberus.errors.BaseErrorHandler method), 44
_get_child_validator() (cerberus.Validator ErrorDefinition (class in cerberus.errors), 44
method), 40 ErrorList (class in cerberus.errors), 46
_lookup_field() (cerberus.Validator method), 41 errors (cerberus.Validator attribute), 41
ErrorTree (class in cerberus.errors), 46
A excluded_types (cerberus.utils.TypeDefinition at-
add() (cerberus.errors.BaseErrorHandler method), 43 tribute), 47
add() (cerberus.errors.ErrorTree method), 46 extend() (cerberus.errors.BaseErrorHandler
add() (cerberus.schema.Registry method), 42 method), 44
all() (cerberus.schema.Registry method), 42 extend() (cerberus.schema.Registry method), 43
allow_unknown (cerberus.Validator attribute), 41
F
B fetch_errors_from() (cerberus.errors.ErrorTree
BaseErrorHandler (class in cerberus.errors), 43 method), 46
BasicErrorHandler (class in cerberus.errors), 44 fetch_node_from() (cerberus.errors.ErrorTree
method), 46
C field (cerberus.errors.ValidationError attribute), 44
cerberus.utils (module), 47
child_errors (cerberus.errors.ValidationError at- G
tribute), 44 get() (cerberus.schema.Registry method), 43
clear() (cerberus.schema.Registry method), 43
clear_caches() (cerberus.Validator class method), I
41 ignore_none_values (cerberus.Validator at-
code (cerberus.errors.ValidationError attribute), 44 tribute), 41
constraint (cerberus.errors.ValidationError at- included_types (cerberus.utils.TypeDefinition at-
tribute), 44 tribute), 47
info (cerberus.errors.ValidationError attribute), 44
is_child (cerberus.Validator attribute), 41
69
Cerberus Documentation, Release 1.3.2
M
mapping_to_frozenset() (in module cer-
berus.utils), 47
N
name (cerberus.utils.TypeDefinition attribute), 47
normalized() (cerberus.Validator method), 41
P
purge_unknown (cerberus.Validator attribute), 41
R
readonly_classproperty (class in cerberus.utils),
47
Registry (class in cerberus.schema), 42
remove() (cerberus.schema.Registry method), 43
require_all (cerberus.Validator attribute), 41
root_allow_unknown (cerberus.Validator at-
tribute), 42
root_document (cerberus.Validator attribute), 42
root_require_all (cerberus.Validator attribute),
42
root_schema (cerberus.Validator attribute), 42
rule (cerberus.errors.ValidationError attribute), 45
rules_set_registry (cerberus.Validator at-
tribute), 42
S
schema (cerberus.Validator attribute), 42
schema_path (cerberus.errors.ValidationError at-
tribute), 45
schema_registry (cerberus.Validator attribute), 42
SchemaError, 47
SchemaErrorTree (class in cerberus.errors), 46
start() (cerberus.errors.BaseErrorHandler method),
44
T
TypeDefinition (class in cerberus), 43
TypeDefinition (class in cerberus.utils), 47
V
validate() (cerberus.Validator method), 42
validated() (cerberus.Validator method), 42
ValidationError (class in cerberus.errors), 44
Validator (class in cerberus), 39
70 Index