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
1
vote
1 answer

Python Cerberus: problem with validation different schemas using 'anyof_schema' rule

I am trying to use Cerberus to validate a list that contains strings or dictionaries using anyof_schema rule as proposed in this post: from cerberus import Validator A = {'type': 'dict', 'schema': {'name': {'type': 'string', 'required':…
desergik
  • 55
  • 9
1
vote
1 answer

TypeError when attempting recursive schema validation in cerberus

I'm attempting to construct a recursive schema using cerberus but appear to be missing the point of how it should work. Could someone help me out? In the documentation and old issues in the repo it is explained that the way to handle recursion is to…
Sirrah
  • 1,681
  • 3
  • 21
  • 34
1
vote
0 answers

SSH.NET does not capture exception message

We are using Cerberus FTP server. And for the client I am using SSH.NET library to connect to server and upload a file. I was able to connect and upload files to FTP server without issue most of the time. However when destination path does not…
LP13
  • 30,567
  • 53
  • 217
  • 400
1
vote
1 answer

ceberus: How to ignore a field based on yaml comment?

Overview I have a lot of .yaml files, and a schema to validate them. Sometimes, a "incorrect" value, is in fact correct. I need some way to ignore some fields. No validations should be performed on these fields. Example ## file -- a.yaml …
Pablo
  • 37
  • 5
1
vote
1 answer

cerberus: Validate an optional field occurs at least once

I'm using cerberus to validate data. One of my fields is optional - it doesn't need to be present for every item. However, the key must be populated at least once across the entire data array. As an example, say I want to validate the key 'c' occurs…
zlipp
  • 790
  • 7
  • 16
1
vote
0 answers

Disable readonly during Cerberus validation

I have a schema where some items are set to 'readonly'. Is there a way I can bypass/override this restriction when an admin supplies configuration? Is there a better way than to recurse through the schema and set all 'readonly's to False before…
Throw Away
  • 11
  • 1
1
vote
1 answer

Cerberus Custom Normalization Rule

Is there a way to create a custom normalization rule in Cerberus? I am using Cerberus to normalize Protobuf messages before storing them in MongoDB. One of my use cases is to flatten a sub-message to a reference: { "team": {"id": {"value":…
1
vote
1 answer

Python Cerberus how to check dynamic root keys

I have a dict with IDs as its root keys that I want to validate. In other words, the root keys of the dict I want to validate are dynamic. Is there a way to run keyschema against the root keys? e.g. https://repl.it/@crunk1/cerberusrootkeys import…
crunk1
  • 2,560
  • 1
  • 26
  • 32
1
vote
1 answer

Strict schema validation for Cerberus

I'm using Cerberus version 1.1. The Cerberus required validation rule appears to default to False, with the result being that an empty document is perfectly valid. >>> schema = { 'spam': {'type': 'string'} } >>> v = Validator() >>>…
Matt Skone
  • 315
  • 1
  • 4
  • 10
1
vote
1 answer

How can I validate that a mapping field has at least one item with Cerberus?

I'm validating documents with Cerberus that roughly look like this: {"a_dict": {"field1": "test1", "field2": "test2", "field3": "test3"}} Not all of the fields in the subdocument need to be present, but one should. So far my…
funky-future
  • 3,716
  • 1
  • 30
  • 43
1
vote
1 answer

How can I validate a field against a schema depending on the value of another field with Cerberus?

I'm using Cerberus to validate payloads that have a type and a data field. Depending on the value of type (test or build), I want to validate data against different constraints. So far, I hav this setup: test_task = {"folder": {"required":…
funky-future
  • 3,716
  • 1
  • 30
  • 43
1
vote
1 answer

Validating that two params have same amount elements using Cerberus

Is there a way to have Cerberus validate that two fields have the same amount of elements? For instance, this document would validate: {'a': [1, 2, 3], b: [4, 5, 6]} And this won't: {'a': [1, 2, 3], 'b': [7, 8]} So far I have come up with this…
Wang Nick
  • 385
  • 1
  • 6
  • 17
1
vote
1 answer

SQLAlchemy whole model validation with Cerberus

I want to create some universal validation mechanism for all models using cerberus. The goal is to have cerberus schema in model's __schema__ property and perform validation of whole model using this schema each time model's state changed (not…
Eugene Tsakh
  • 2,777
  • 2
  • 14
  • 27
1
vote
1 answer

Force Eve to validate document inside custom route

In my python/eve REST API I have a custom route that does some non trivial processing. I'm receiving a POST request and after some processing I'll send this doc to database. But it would be nice if I could validate this doc using the same validation…
Gustavo Vargas
  • 2,497
  • 2
  • 24
  • 32
1
vote
1 answer

Cerberus schema validation dependency depending of self value

I know that according to the Cerberus documentation, it is possible to define validation dependencies, according to other keys values, such as: schema = {'field1': {'required': False}, 'field2': {'required': True, …
gcw
  • 1,639
  • 1
  • 18
  • 37
1 2 3
8 9