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

Normalize nested dict in Cerberus

I'd like to have default values in nested dicts with Cerberus normalize function. Unfortunately it's not working. I have code such as: from yaml import load, Loader from cerberus import Validator text_schema = """ server: type: dict required:…
pszafer
  • 370
  • 2
  • 15
0
votes
1 answer

Python: Cerberus coerce field when not empty

I would like to allow a field to be empty, but when it is not empty I want it to be Integer and range checked. I will need to coerce the field, when not empty, to int because it comes in as string. Is there a way to do this? My approach is below but…
K Venner
  • 11
  • 2
0
votes
1 answer

How to prohibit certain words in a json value with cerberus

Lets say that I have this json: {"name": "John"} And I want to restrict the json from containing the substring "my name is", so if I receive: {"name": "my name is John"} Cerberus will me that the json is not correct and I can display the correct…
Casanalo
  • 15
  • 4
0
votes
1 answer

Cerberus and validating a list containing dicts

I'm trying to validatie the following doc. document = { 'days': { 'Monday': [{ 'address': 'my address', 'city': 'my town' }], 'Tuesday': [{ …
nidkil
  • 1,295
  • 1
  • 17
  • 28
0
votes
0 answers

How to solve validating a 3 layered YAML file using Cerberus?

I have a YAML config file and I want to validate it using Cerberus. The problem is my YAML file is a kind of 3 layered dictionaries and it seems the validation function does not work when we have more than 2 nestings. As an example when I run the…
Doralisa
  • 171
  • 4
0
votes
1 answer

Python Cerberus embed numeric config data in schema

I have a set of documents and schemas I am doing validation against (shocker). These documents are JSON messages from various different clients that use various different formats, thus a schema is defined for each document/message received from…
0
votes
1 answer

Validating arbitrary dict keys with strict schemas with Cerberus

I am trying to validate JSON, the schema for which specifies a list of dicts with arbitrary string keys, the corresponding values of which are dicts with a strict schema (i.e, the keys of the inner dict are strictly some string, here 'a'). From the…
0
votes
1 answer

Cerberus oneof two keys

I have a set of schemas I'm using to validate one of my input routes: # schemas is just a dict of validator schemas REGISTRATION_VALIDATOR = { 'email_address': schemas['email_address'], 'user_level': schemas['user_level'], 'first_name':…
xendi
  • 2,332
  • 5
  • 40
  • 64
0
votes
1 answer

Exclude issue in Cerberus 1.3.2

I'm new to Cerberus recently upgraded the Cerberus version to 1.3.2 from 1.1. But getting validation errors. Please find the validation schema. my_schema = { 'email': { 'type': 'string', 'maxlength': 1000, 'regex':…
reegan vijay
  • 161
  • 11
0
votes
3 answers

Is it possible to set conditional validation in cerberus, Python?

I use Python package cerberus to validate my payload Here's my issue: I need to set a field to be required only if some field from another schema has exact value. Something like: "key2": { "type": "string", "required": \\\ true if…
0
votes
1 answer

Using cerberus regex to validate string ends with pattern

The cerberus library says that it allows for regex validation, but that doesn't seem to work across a variety of cases and the documentation is scarce. In the instance of trying to validate that a string ends with ".csv" the validation always fails…
Steven M. Mortimer
  • 1,618
  • 14
  • 36
0
votes
1 answer

Python: Cerberus Value Coercion if len(value) == 1

Using the cerberus library for validation, I am wondering how a custom rule might look like that checks if the input is a list with only ONE element. If this is the case, the value should be changed to a single value (Value Coercion). Here's my try,…
Andi
  • 3,196
  • 2
  • 24
  • 44
0
votes
1 answer

Cerberus throwing exception when using added rule set

I have the following piece in a Cerberus 1.3.2 schema (that I'm storing as a YAML file): members: dependencies: res_type: gsuite_group type: dict keysrules: allowed: - gsuite - csod schema:…
Lopson
  • 1,202
  • 1
  • 8
  • 20
0
votes
2 answers

Cant validate a list of values for duplicates using Python and Cerberus

I am fairly new to Python and Cerberus. I have a requirement where I need to validate a list for any empty Strings or duplicates. Below is what I did: import cerberus myschema = {'uid': {'type': 'list', 'schema': {'type': 'string', 'required' :…
NixRam
  • 509
  • 1
  • 10
  • 21
0
votes
1 answer

Overloading validate in cerberus

I'd like to overload validate in my custom validator class so that if the client only gives me text, I can convert it to yaml for validation. I've tried the following: import cerberus from cerberus import Validator from ruamel.yaml import…
aronchick
  • 6,786
  • 9
  • 48
  • 75
1 2 3
8 9