top | item 15629253

Show HN: PySchemes – A library for validating data structures in Python

94 points| shivaprasad | 8 years ago |github.com | reply

34 comments

order
[+] fermigier|8 years ago|reply
[+] shazzy|8 years ago|reply
Also a shameless plug for my python library for declarative multi-field validation:

https://github.com/shezadkhan137/required

It makes it easier to expresses complex inter-field validation rules, and is meant to be used with other validation libraries.

[+] chucksmash|8 years ago|reply
It looks similar to voluptuous. Browsing READMEs, the other three examples expose their own library level representations for primitive types (e.g. Field.int() or {"type": "int"} instead of the primitive Python type int).
[+] logronoide|8 years ago|reply
Why is better PySchemes than others like Voluptuous? I’m happy with it, but open to new stuff.
[+] StavrosK|8 years ago|reply
My preferred library is "schema", as it's very functional.
[+] sametmax|8 years ago|reply
Everytime i see one of those i always wonder if they heard of marshmallow. I mean it's like creating a requests competitor really. It's an interesting exercice but the chances to be relevant are very low.
[+] houzi|8 years ago|reply
I wasn't impressed. Couldn't figure out how to do complex validation of a JSON object, based on the input of another JSON object.
[+] mathgenius|8 years ago|reply
The great thing about python is it's so easy to roll your own. And people start thinking they are a genius or something. Ha :-)
[+] craigds|8 years ago|reply
marshmallow: 62 watchers, 2055 stars, 244 forks. requests: 1142 watchers, 28420 stars, 5212 forks.

I don't think those are in the same league

[+] vram22|8 years ago|reply
There is also jsonschema:

https://pypi.python.org/pypi/jsonschema

A post showing a simple use of it:

Using JSON Schema with Python to validate JSON data:

https://jugad2.blogspot.in/2015/12/using-json-schema-with-py...

[+] ansgri|8 years ago|reply
Exactly my thought about json-schema, as I use it extensively in both Python and C++ (excellent library valijson [0]).

Not all Python objects are json-serializable by default, so the ideal solution (for me) would be json-schema with simple syntax for adding custom type validators.

[0] https://github.com/tristanpenman/valijson

[+] varlock|8 years ago|reply
Maybe I'm missing something, but IMO using isinstance, issubclass and explicit checks achieves the same effect, and is probably more readable. Or not?
[+] gh02t|8 years ago|reply
It's tedious if you wanna validate a complex structure. Most of these libraries are meant to validate stuff that is user input. Imagine I load a complex input from a configuration file into a nested dict and checking it, that'd be really tedious to do manually. A couple checks here or there are ok, but they get confusing and difficult to maintain very quickly. Stuff like optional values, enumerated values etc are also not much fun.

Also error messages for the user. I've mostly used Voluptuous, but it provides much easier to understand error messages.

[+] w_t_payne|8 years ago|reply
I really like 'voluptuous' (and its' ungoogleable fork; 'good')
[+] bitexploder|8 years ago|reply
Seconded. It works and let's you build rules declaratively.