Questions tagged [voluptuous]

voluptuous is a data validation library for Python

From the github project page:

Voluptuous, despite the name, is a Python data validation library. It is primarily intended for validating data coming into Python as JSON, YAML, etc.

It has three goals:

  • Simplicity.
  • Support for complex data structures.
  • Provide useful error messages.
20 questions
17
votes
1 answer

Python - Cerberus, jsonschema, voluptous - Which one will be appropriate?

I am developing a small RESTful web application in python and using JSON as interface. The application accepts JSON data and needs to validate them against a schema. The schema may be very strict or flexible depending on the request. Also, the…
5
votes
1 answer

voluptuous unable to handle unicode string?

I'm trying to use voluptuous to validate JSON input from HTTP request. However, it doesn't seem to handle unicode string to well. from voluptuous import Schema, Required from pprint import pprint schema = Schema({ Required('name'): str, …
lang2
  • 11,433
  • 18
  • 83
  • 133
5
votes
2 answers

Are there any conditional rules for voluptuous?

Is there any way to define conditional rules using voluptuous? Here's the schema I have: from voluptuous import Schema, All, Any schema = Schema({ 'resolution': All(str, Any('1920x1080', '1280x720')), 'bitrate': 20, }) That's ok, but now I…
Dmitrii Mikhailov
  • 5,053
  • 7
  • 43
  • 69
3
votes
1 answer

no error after forgetting Schema() in voluptuous

According to examples, this is the correct way to create a validation Schema: import voluptuous as vol PORT1 = vol.Schema(vol.All(int, vol.Range(min=0, max=65535))) However, I noticed, that the Schema call is missing in some of my validators,…
VPfB
  • 14,927
  • 6
  • 41
  • 75
3
votes
1 answer

Getting a better Voluptuous Schema error message for key type validation?

I have a Schema that looks like this (an example): Schema({ Any(str, unicode): [{ Required('first_name'): [Any(str, unicode)], Required('age'): Any('int32', 'double'), Required('something'): Any(int, long, float, str,…
David Gourde
  • 3,709
  • 2
  • 31
  • 65
3
votes
1 answer

How to upload a variable amount of files using a single multipartform post header key

I have a repeatable form field:
that will (using jQuery) for example result in
flaudre
  • 2,358
  • 1
  • 27
  • 45
2
votes
2 answers

Voluptuous Exclusive Class

I am using voluptuous 0.9.2 and I have a problem with Exclusive class. I need that if there is none of the keys, it should give an error. However, this is okay for voluptuous. Is this a bug of voluptuous? If not, how I can write a script for…
2
votes
1 answer

Handling a function argument with a decorator

At the core, what I'm trying to do is take a number of functions that look like this undecorated validation function: def f(k: bool): def g(n): # check that n is valid return n return g And make them look like this…
Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
2
votes
1 answer

Can voluptuous code pass pylint?

I run pylint -E as part of the tests on my Python project to ensure that errors don't creep into untested code. Generally this works quite well. But recently I've been running into problems with voluptuous and pylint. The problem is that pylint…
danvk
  • 15,863
  • 5
  • 72
  • 116
1
vote
2 answers

Voluptuous : give error line in yaml file

I am using voluptuous a lot to validate yaml description files. Often the errors are cumbersome to decipher, especially for regular users. I am looking for a way to make the error a bit more readable. One way is to identify which line in the YAML…
nowox
  • 25,978
  • 39
  • 143
  • 293
1
vote
0 answers

Build Python Voluptuous Schema within another Schema

I am attempting to validate a schema within another schema. The error I receive with the following schema is "expected a dictionary" for the campaign parameter. The reason why I am trying to do this is so that if I change one field in the campaign,…
stwhite
  • 3,156
  • 4
  • 37
  • 70
1
vote
1 answer

voluptuous: how to validate non-string value from json data in HTTP POST

I'm implementing some REST API with flask. In one of the APIs, I need to submit a location defined by longitude and latitude. So naturally I'm doing this with httpie: http POST :5000/api/v1.0/foo lng=12.34 lat=56.78 At the flask end, I'm using…
lang2
  • 11,433
  • 18
  • 83
  • 133
0
votes
1 answer

voluptuous: list of dictionaries. full compliance

test_data = [{'field1': 'value1', 'field2': 1}, {'field1': 'value3', 'field2': 2} ] schema = Schema([ {Required('field1'): 'value1', Required('field2'): int}, {Required('field1'):…
0
votes
1 answer

Voluptuous at least one-of key in dictionary validation?

Let's say I would like a dictionary with at least one of the three key foo', 'bar', baz`. The following would allow an empty set. Schema({ 'foo': str, 'bar': int, 'baz': bool }) Unfortunately, I cannot do this: Any( Schema({'foo': str}), …
nowox
  • 25,978
  • 39
  • 143
  • 293
0
votes
1 answer

How to make all Voluptuous fields required with a single command?

I try to check my JSON fields and their types. So, I use voluptuous and its methods. An example is here. check = Schema({ Required('Id'): All(str, Length(min=1)), Required('CalculationId'): All(str, Length(min=1)), Required('Routes'): All([ …
Alex Kay
  • 23
  • 1
  • 3
1
2