Questions tagged [cerberus]

Cerberus is a lightweight and extensible data validation library for Python

Filter by
Sorted by
Tagged with
0 votes
0 answers
19 views

coerce datetime using Cerberus with schema defined in config file

Referring to this answer, I have defined the schema in a separate config file and using the read_config function to read the schema. This works fine for standard validation rules but when I define ...
user0000's user avatar
  • 367
-1 votes
1 answer
92 views

lambda function Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'cerberus'

I am trying to use Cerberus in AWS lambda but running into the below error when trying to execute the code. I created a custom layer and pointed it to zip file in S3 downloaded from here. Runtime env ...
user0000's user avatar
  • 367
0 votes
0 answers
22 views

cerberus validator to accept either smaller case or Title case

Looking for Cerberus validator to accept either 'x-api-key' or 'X-Api-Key' (title cased). >>>>python3 Python 3.9.13 (v3.9.13:6de2ca5339, May 17 2022, 11:37:23) [Clang 13.0.0 (clang-1300.0....
Arun G's user avatar
  • 1,678
0 votes
0 answers
18 views

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 ...
jhuitema's user avatar
0 votes
1 answer
129 views

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 ...
Starbucks's user avatar
  • 1,468
0 votes
1 answer
32 views

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 ...
Yohann Pitrey's user avatar
1 vote
1 answer
44 views

Is it possible for cerberus to check nested recursive structure?

So there is a response, which has recursive list children : resp = [{'name': "child-1", 'cap': 3, 'children': [ { 'name': "child-11", ...
Lezakk's user avatar
  • 21
1 vote
1 answer
248 views

Specify list length range in Python Cerberus

I need to set the minimum and maximum length of a list between 2 - 5. Is there a way to specify this in Python Cerberus. Here's what I have currently but this allows lists of all sizes: { "...
Asad Amir Khwaja's user avatar
1 vote
0 answers
61 views

Nested JSON Validation and Parsing

I cannot return the nested JSON file after I validate it using Cerberus in my api. Validation works fine but I don't know how to input the JSON file to the "add_argument" function of ...
Turan Toprak Bilge's user avatar
0 votes
1 answer
72 views

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:...
user388794's user avatar
0 votes
1 answer
135 views

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 ...
Josh McCarter's user avatar
1 vote
0 answers
149 views

Cerberus - how not to skip empty values from getting checked

I am using Cerberus with default and custom validation rules. My raw data can include empty values and this is causing them to be skipped from any validation, whereas I would like to be able to check ...
Lev's user avatar
  • 663
0 votes
1 answer
321 views

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 } ] ...
adrnrtkvski's user avatar
0 votes
1 answer
252 views

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 ...
KZiovas's user avatar
  • 3,825
2 votes
1 answer
467 views

Validating JSON Schema with Cerberus throws error when using correct data type

I am trying to validate a JSON schema. When specifying the correct data type date for released Cerberus throws an error. def test_validate_books_schema(): schema = { "url" : {...
Armz's user avatar
  • 95
0 votes
1 answer
212 views

Cerberus: Can the schema copy a value to multiple fields?

I want to take an input document like the below and copy the 'foo' key to multiple fields with different coercions and validations to get something like this: >>> input_doc = {'foo': 10} >&...
Douglas Storz's user avatar
0 votes
0 answers
80 views

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" ...
Jason Powers's user avatar
2 votes
0 answers
180 views

Use Cerberus Schemas to Automate Documentation

We are using cerberus extensively to validate json configuration files. We therefore have a wide range of schemas, which define how these json documents should be formatted. We would like to be able ...
OliverBurke's user avatar
1 vote
0 answers
373 views

Python Cerberus: validating NAN and numbers using 'anyof_schema' rule

I'm trying to create a Cerberus validation schema to validate a set of data in a Pandas dataframe. One of the columns should only validate on the following data: numbers NaN (this is Numpy's floating-...
sam_ur_ai's user avatar
  • 107
0 votes
1 answer
288 views

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 = ...
natielle's user avatar
  • 400
1 vote
1 answer
175 views

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', ...
Bronte2k7's user avatar
1 vote
1 answer
728 views

In Cerberus (Python) is there a way to create a schema that allows any key name in a dictionary?

Given a dictionary where the top level keys can be any value, but there is a strict schema within the values of those keys: {"rand_value": ["key1": "val1", "key2&...
Prime's user avatar
  • 207
0 votes
1 answer
156 views

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 ...
pszafer's user avatar
  • 370
0 votes
1 answer
197 views

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 ...
K Venner's user avatar
1 vote
0 answers
159 views

How to convert json schema in one form to other surported by cerberus?

How can we convert this schema to the below one: { "entityName": "Firm", "attributes": [ { "name": "FirmKey", &...
Harshit Pathak's user avatar
1 vote
1 answer
2k views

Validate list of dicts using cerberus

Started to use cerberus for contract testing purposes. It works perfectly in cases, when we got dict-based JSON structure, e.g: {'results': [{"key": "value"}, {"key": &...
Shoo's user avatar
  • 43
2 votes
1 answer
174 views

Python Cerberus - One is required if another one does not exist

What I want to achieve: >>> from cerberus import Validator >>> schema = {"x": {"type": "integer", "required": False}, "y": {"...
AnnieFromTaiwan's user avatar
1 vote
0 answers
99 views

How do I setup cerberus to validate against a model based on a SQL database schema?

How do I setup cerberus to validate against a model based on a SQL database schema? Specifically is there a way to generate the schema definition of what we are loading data into (e.g. SQL Server ...
Bim Dave's user avatar
0 votes
1 answer
63 views

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 ...
Casanalo's user avatar
1 vote
0 answers
121 views

Unresolved reference for some library classes of Cerberus in PyCharm

I started running into an import issue where PyCharm is unable to resolve references to classes for some libraries I have installed. I haven't run into this issue for any standard libraries. from ...
Kenton Parton's user avatar
1 vote
1 answer
1k views

Cerberus schema with single dict or list of dicts

I'm trying to build a schema where the statement can be a single dict or a list of dicts. Ex: {'Document': {'key': 'value'}} Or multiple keys: {'Document': [ {'key1': 'value1'}, {'key2': 'value2'}, {'...
Rafael Koike's user avatar
0 votes
1 answer
373 views

Cerberus and validating a list containing dicts

I'm trying to validatie the following doc. document = { 'days': { 'Monday': [{ 'address': 'my address', 'city': 'my town' ...
nidkil's user avatar
  • 1,295
0 votes
0 answers
447 views

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 ...
Doralisa's user avatar
  • 181
2 votes
3 answers
2k views

N elements list of string validation in cerberus

How can I validate that certain type is a list and it contains only e.g string elements, of unknown number? My current solution is 'categories_id' : {'required' : False, 'type' : ['string','list']}, ...
konradk's user avatar
  • 193
0 votes
1 answer
267 views

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 ...
parallel_pilgrim's user avatar
1 vote
1 answer
454 views

Dependencies validation based on conditions using Cerberus

There are two fields "field1" and "field2". The condition is either "field1" or "field2" can take 'ANY' value, but both fields cannot have 'ANY' value. How to ...
Misha's user avatar
  • 49
2 votes
1 answer
1k views

cerberus - how to validate arbitrary dict keys?

I have read issues here and here using keysrules and valuesrules but I've only seen them validate nested not root. I'd like to valid the top level root dict keys. schema = { 'any_arbitrary_str': { ...
nobody's user avatar
  • 270
0 votes
1 answer
468 views

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 ...
carrotstrip's user avatar
0 votes
1 answer
364 views

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'], '...
xendi's user avatar
  • 2,392
1 vote
0 answers
203 views

Use cerberus coercers to encrypt / decrypt data

I am planning to use python eve & cerberus to save some documents into a mongodb database. Some of this documents will have some sensible data (pseudo-passwords) which I do want to store encrypted....
Mayday's user avatar
  • 4,798
0 votes
1 answer
230 views

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',...
reegan vijay's user avatar
1 vote
1 answer
162 views

How can I produce a warning with ceberus if a key is missing?

Cerberus allows for required fields but I'd like to have a "preferred" class of fields such that a warning message is logged if they're missing. Some ideas I have that don't seem great are the ...
Jessica's user avatar
  • 330
0 votes
3 answers
2k views

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": { ...
Ab B Bg Kostroš's user avatar
0 votes
1 answer
1k views

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 ...
Steven M. Mortimer's user avatar
1 vote
2 answers
2k views

Python: cerberus check_with function

I would like to validate a dict, where the values adhere to the following rules: value must be either a single float or List(float) if it is a single float, the value must be 1 if it's a List(float), ...
Andi's user avatar
  • 3,433
1 vote
0 answers
241 views

Permit one of the given schemas

I am using Cerberus to validate some YAML files that might look like this: fleet.yml fleet_city: "New York" vehicles: vehicle_1: car: # License plate required for car license_plate:...
Donentolon's user avatar
  • 1,433
0 votes
1 answer
386 views

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 ...
Andi's user avatar
  • 3,433
2 votes
1 answer
435 views

Python: validation using cerberus

I would like to validate a dict, where a field may contain either an int or a List[int]. Also, all int must be positive. I need some help with setting up the schema. The schema below are not working ...
Andi's user avatar
  • 3,433
0 votes
1 answer
144 views

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: - ...
Lopson's user avatar
  • 1,222
0 votes
2 answers
1k views

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': '...
NixRam's user avatar
  • 519