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

Cannot serialize data when patching to a field that has a 'valueschema' that is of type 'dict' in Eve

So say i have the following document: test_obj = { 'my_things':{ 'id17': { 'blah': 3, 'weird': 'yay', 'thechallenge': ObjectId('5712d06fdb4d0856551300d2') }, 'id32': { …
Sir Neuman
  • 1,385
  • 1
  • 14
  • 23
1
vote
1 answer

Can I create unique-compound constraints on eve schema definition?

I would like to know if it is possible to create a unique constraint into an eve schema definition, between two or more fields of a document, instead of only one as shown on Eve's schema definition documentation, I want the same behavior as creating…
gcw
  • 1,639
  • 1
  • 18
  • 37
0
votes
0 answers

Is there a way to get the Cerberus Schema through the API?

I am trying to implement an API for other users that is based around YAML files and am using Cerberus to validate the contents of those files. I want to allow the user to specify their own Cerberus schema within those YAML files and validate them as…
jhuitema
  • 1
  • 1
0
votes
1 answer

Python Cerberus - Validating Schema with this Example

I am using Cerberus to validate dataframes schema. Using this sample data and code below, the if-else statement should "data structure is valid", however it returns that the "data structure is not valid". Any insight would be appreciated. import…
Starbucks
  • 1,448
  • 3
  • 21
  • 49
0
votes
1 answer

Only allow one property to have a given value if another property has another given value

I want to do something fairly simple. I've browsed through the questions already asked here but couldn't find an answer to my specific issue. I've played around with excludes and allowed and dependencies, to no avail. Can someone please put me on…
0
votes
0 answers

Have a trouble with create a scheme for cerberus

I have some problem with create scheme for list without name which same as my example. Have JSON response: ` [ { "id": 1 }, {same object} ] ` My scheme: ` scheme = {"type":"list","valuesrules": {"type": "dict", "schema": …
0
votes
0 answers

Cerberus - nullable rule doesn't drop custom validation rules

I'm evaluating cerberus' capability for adding new validation rules and I stumbled upon the following issue, custom rules do not work with the "nullable" rule. Here is an example of using a custom validator from the documentation with…
warownia1
  • 2,771
  • 1
  • 22
  • 30
0
votes
1 answer

Is it possible to set condition to empty parameter in cerberus?

I want to set conditional validate for empty parameter. For example: schema = { 'param1': {'type': 'string', empty: False, required:True, 'allowed': ['One', 'Two']}, 'param2': {'type': 'string', empty: False, required:True} } I need that empty…
0
votes
0 answers

how to check if a keyword exists in csv using Cerberus?

I want to read a csv and return error if a kwyword , say 'xyz' exists in a column NAME? Below is my implementation . Yaml - ID: type: integer required: True NAME: type: string required: False MAIL: type: string required: False regex:…
Sss
  • 11
  • 2
0
votes
1 answer

Passing additional arguments to _normalise_coerse methods in cerberus

I have some code see EOM; it's by no means final but is the best way (so far) I've seen/conceived for validating multiple date formats in a somewhat performant way. I'm wondering if there is a means to pass an additional argument to this kind of…
0
votes
1 answer

Python Cerberus JSON schema validation

I have no clue why my code doesn't work, hence looking for some help. That's my sample JSON array: [ { "bookingid": 1774 }, { "bookingid": 1020 } ] and my code is as follows: def…
0
votes
1 answer

How to validate a list of custom dictionaries - schemas with Cerberus in Python

I have a basic data_schema and I produce a list of many data points. Each data point follow my data_schema. How can I validate them all at once as part of the list. A reason I wish to do that is for speed. Iterating through the list and individually…
KZiovas
  • 3,491
  • 3
  • 26
  • 47
0
votes
0 answers

Getting attribute error on attribute being imported

Sorry for all the questions and thank you for the help. I have the following code that I'm working for school. I'm trying to import the Cerberus package into my code with "import cerberus" and that works with no problems. However, when I run the…
0
votes
1 answer

How to use min value with type datetime in Cerberus?

I want validate a field with one value greater or equal 01/01/1900 in type datetime in Cerberus, but not works this way: from cerberus import Validator from datetime import datetime v = Validator() schema = { "birthdate": { "type":…
natielle
  • 380
  • 3
  • 14
0
votes
1 answer

python cerberus - how to catch UNALLOWED_VALUE?

How do I catch the UNALLOWED_VALUE error? # my schema schema = { 'sort': { 'type': 'list', 'empty': False, 'required': True, 'schema': { 'type': 'dict', 'schema': { …
Bronte2k7
  • 3
  • 2
1 2 3
8 9