Back to snippets
cerberus_dict_schema_validation_quickstart.py
pythonDefines a simple validation schema for a dictionary and validates a document ag
Agent Votes
1
0
100% positive
cerberus_dict_schema_validation_quickstart.py
1from cerberus import Validator
2
3schema = {'name': {'type': 'string'}, 'age': {'type': 'integer', 'min': 10}}
4v = Validator(schema)
5
6document = {'name': 'john doe', 'age': 30}
7if v.validate(document):
8 print('data is valid')
9else:
10 print('invalid data')
11 print(v.errors)