Questions tagged [cerberus]
Cerberus is a lightweight and extensible data validation library for Python
124
questions
0
votes
0
answers
16
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
}
]
...
0
votes
1
answer
22
views
How to get the error line number of yaml validation using cerberus?
I am using cerberus for validating my yaml file against predefined schema as shown below
import yaml
schema_text = '''
name:
type: string
age:
type: integer
min: 10
'''
input_text = '''
name: Little ...
0
votes
1
answer
17
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 ...
-1
votes
0
answers
24
views
how to validate start_time should be less than end_time with cerberus in python
from cerberus import Validator
input={"start_time":502.2, "end_time":501.1}
schema={}
schema["start_time"]={"type": "float", "required": ...
0
votes
0
answers
13
views
Cerberus: unexpected normalization behavior with anyof_schema
The following code validates the dictionary {'a_dict': {}} with the schema A and the schema any of A or B. The problem is that in the second case the dictionary is not being normalized as expected.
...
0
votes
1
answer
77
views
Given a Cerberus JSON Schema file, how can I generate a dictionary object
Problem
I have a Cerberus Json schema file and I need to generate Json files based on the schemas with default values given the data_types. The key _type in the dictionary objects is the data_type to ...
2
votes
1
answer
62
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" : {...
0
votes
0
answers
29
views
Match all elements of sequence to schema
I'm trying to define a schema such that all elements of a sequence are matched to a nested schema.
E.g.
data = {"items": ["hello", "bob", 123]}
schema = {"items"...
1
vote
1
answer
42
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}
>&...
0
votes
0
answers
26
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" ...
1
vote
0
answers
63
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 ...
0
votes
0
answers
118
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-...
0
votes
0
answers
26
views
Dependencies rules using Cerberus
My first scenario: I want only one of these 3 columns to be filled. If values are entered in 2 or more columns, it will give an error.
My second scenario: At least one column must be filled. There ...
0
votes
1
answer
76
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 = ...
0
votes
0
answers
30
views
Cerberus - Validate field only if flag is set
Assume the Cerberus Schema with some container aggregating boolean flags to control verification of another fields like below.
flags = {
"flags":
{
"enable_foo":
...
0
votes
0
answers
33
views
How to validate nested dictionary schema with Cerberus
This is my json schema-
schema = {
"workflowId": {"type": "string"},
"workspaceId": {"type": "string"},
...
0
votes
1
answer
45
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',
...
0
votes
1
answer
239
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&...
0
votes
1
answer
51
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
...
0
votes
0
answers
79
views
Python Cerberus validation for union types
I am using Cerberus to build validation logic of some sort of DSL, which specifies a list of differing objects. For example (using YAML):
items:
- name: shape1
type: Circle
...
0
votes
1
answer
68
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 ...
1
vote
0
answers
72
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",
&...
0
votes
1
answer
271
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": &...
2
votes
1
answer
96
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": {"...
1
vote
0
answers
51
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 ...
0
votes
1
answer
44
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 ...
1
vote
0
answers
40
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 ...
1
vote
1
answer
490
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'}, {'...
0
votes
1
answer
116
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'
...
0
votes
0
answers
297
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 ...
2
votes
2
answers
888
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']},
...
0
votes
1
answer
177
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 ...
1
vote
1
answer
214
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 ...
2
votes
1
answer
492
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': {
...
0
votes
1
answer
320
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 ...
0
votes
1
answer
110
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'],
'...
1
vote
0
answers
120
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....
0
votes
1
answer
144
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',...
1
vote
1
answer
71
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 ...
0
votes
3
answers
1k
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": {
...
0
votes
1
answer
897
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 ...
1
vote
2
answers
990
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), ...
1
vote
0
answers
165
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:...
0
votes
1
answer
256
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 ...
1
vote
1
answer
212
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 ...
0
votes
1
answer
74
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:
- ...
0
votes
2
answers
708
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': '...
0
votes
1
answer
47
views
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 ...
0
votes
1
answer
291
views
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: ...
2
votes
1
answer
415
views
cerberus.schema.SchemaError: {'uuid': [{'query_objectid_as_string': ['unknown rule']}]}
Eve API. I need to filter records by where={"uuid": "my_uuid"}. So my 'settings.py' for the Eve application contains:
'schema': {
'uuid': {
'type': 'string',
'...