Questions tagged [cerberus]

Cerberus is a lightweight and extensible data validation library for Python

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.6 up to 3.5, PyPy and PyPy3.

At a Glance

You define a validation schema and pass it to an instance of the Validator class:

schema = {'name': {'type': 'string'}}
v = Validator(schema)

Then you simply invoke the validate() to validate a dictionary against the schema. If validation succeeds, True is returned:

document = {'name': 'john doe'}
v.validate(document)
True

Documentation

See the Cerberus website.

127 questions
0
votes
1 answer

Using custom validation for built in types

I'm looking to validate the datetime type with custom validator, rather than the built in one. The code looks like this: schema_text = """ run_date: type: datetime required: true """ …
aronchick
  • 6,786
  • 9
  • 48
  • 75
0
votes
0 answers

How can one pass the same rule to a rules_set

Using Cerberus, I've defined custom rules that validate data (CSV data) based on some parameters passed to the rule. See example rule below copied from an answer in another question I'd asked. class MyValidator(Validator): def…
lukik
  • 3,919
  • 6
  • 46
  • 89
0
votes
1 answer

Can a Cerberus schema have an arbitrary name for the base dict?

I need to validate Python dicts that will have arbitrary names. When I attempt to validate them using Cerberus, I get unknown field. Is there a way of allowing for arbitrary dict names? I was thinking that keysrules might work, but it appears to…
user584982
  • 25
  • 5
0
votes
1 answer

Is it possible to validate key names and dictionary names of a yaml file with Cerberus?

I have a need to validate a YAML file, using Python3.7. I am trying Cerberus to perform a content validation. As for the value validation, that is working just fine, but for key names I cannot find a way to successfully verify their validity in the…
hashinate
  • 1
  • 6
0
votes
1 answer

Python Cerberus dependencies on nested list level

Does Cerberus 1.2 support dependency validation on a list? For instance the schema looks as follows: schema = { 'list_1': { 'type': 'list', 'schema': { 'type': 'dict', 'schema': { 'simple_field': {'type':…
tadalendas
  • 1,461
  • 3
  • 16
  • 37
0
votes
1 answer

have two different validation on a rule if a field exist

I need to parse a lot of yml files. I have something like the example where in some cases a value exists and because of that I need to change the regex of another rule. I can't find a way to validate it correctly yaml1: email:…
0
votes
1 answer

Cerberus coercion within nested list

I get unexpected behaviour for the following code: import cerberus v = cerberus.Validator() schema = {'list_of_values': {'type': 'list', 'schema': {'items': [{'type': 'string', 'coerce': str}, …
0
votes
1 answer

Conditional requirement dependent on value of other fields

Conditional requirement dependent on value of other fields in Cerberus has been discussed many times. Usage of dependencies doesn't meet the needs because fields can be unknown when conditions are satisfied. Usage of oneof was recommended but it may…
0
votes
0 answers

Validating child table in cerberus

Consider this simplified scenario. Master-detail tables: CREATE TABLE queue ( id bigint PRIMARY KEY, num text NOT NULL UNIQUE ); CREATE TABLE queue_device ( id bigint PRIMARY KEY, queue_id bigint NOT NULL REFERENCES queue ON DELETE…
Nikša Baldun
  • 1,854
  • 4
  • 28
  • 39
0
votes
1 answer

How to validate cerberus schema

My web application uses Cerberus schema validation for each request (current version is 1.2). For this purposes I'm writing schema in YAML, load it on application start and do validation and use a lot of back references to optimize my work as shown…
Eir Nym
  • 1,515
  • 19
  • 30
0
votes
1 answer

How to define coerce functions in YAML for python cerberus validator library

I am trying to define my validator schema for python cerberus library in YAML since it is more human readable. I ran into an issue where if i try to define coerce function in YAML, I get the a SchemaError. Starting with example from Normalizing…
0
votes
2 answers

cerberus schema validator for tuples

I have a variable declaration as follows my_var = typing.List[typing.Tuple[int, int]] and I want to write a validator as follows schema_validator = "my_var": { "type": "list", "empty": False, "items": [ {"type": "tuple"}, …
not 0x12
  • 19,360
  • 22
  • 67
  • 133
0
votes
1 answer

How Can I Check a Number is a Certain Length in Cerberus?

I'm writing a book schema with Cerberus but I've stumbled upon a block. I want the ISBN field to accept a number/integer/digit that is either 10 digits long, or 13. How can I go about that? I tried using maxlength and minlength but they don't seem…
Nerldy
  • 1
0
votes
1 answer

Checking Root Keys in Cerberus

I have a data structure that looks like this with name being an arbitrary string that cannot be certain values (src) { 'name' : 'stringvalue', 'src' : 'who cares this is wrong' } I'd like cerberus to check that the keys are anything but src…
Ray Salemi
  • 5,247
  • 4
  • 30
  • 63
0
votes
2 answers

How is possible to combine 'excludes' with 'default' in schema?

field_1 must be 0 by default, but not allowed with field_2. My try: from cerberus import Validator schema = { 'value_1': { 'type': 'integer', 'default': 0 }, 'value_2': { 'type': 'integer', 'excludes':…
El Ruso
  • 14,745
  • 4
  • 31
  • 54
1 2 3
8
9