
Show HN: PySchemes – A library for validating data structures in Python - shivaprasad
https://github.com/shivylp/pyschemes
======
fermigier
How does it compare to established, actively maintained, projects like the
following ones ?

\-
[https://github.com/alecthomas/voluptuous](https://github.com/alecthomas/voluptuous)

\-
[https://github.com/schematics/schematics](https://github.com/schematics/schematics)

\- [https://github.com/pyeve/cerberus](https://github.com/pyeve/cerberus)

\- [https://github.com/fuhrysteve/marshmallow-
jsonschema](https://github.com/fuhrysteve/marshmallow-jsonschema)

~~~
shazzy
Also a shameless plug for my python library for declarative multi-field
validation:

[https://github.com/shezadkhan137/required](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.

~~~
willvarfar
May I join you in shameless plugging? My own obiwan:

[https://pypi.python.org/pypi/obiwan](https://pypi.python.org/pypi/obiwan)

It predates the MyPy syntax and, in my opinion, is a gazillion times prettier
and my "pythonic". I'm not bitter ;)

It's "actively maintained" but I haven't needed to do anything in ages - it
just works :)

PySchemes seems to have very similar syntax, but obiwan is also able to
validate signatures in function annotations and is particularly good at
validating JSON and msgpack APIs (the python code to validate an API is self-
describing and makes excellent API documentation for other parties).

------
sametmax
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
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.

~~~
sametmax
I read your comment like somebody saying he is not impressed by this bus that
helps the whole town going to the office because he couldn't figure how to do
nascar with it.

------
vram22
There is also jsonschema:

[https://pypi.python.org/pypi/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...](https://jugad2.blogspot.in/2015/12/using-json-schema-with-python-
to.html)

~~~
ansgri
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](https://github.com/tristanpenman/valijson)

~~~
vram22
Thanks for the info.

------
Dowwie
Check out typeguard:
[https://github.com/agronholm/typeguard](https://github.com/agronholm/typeguard)

it offers run-time type checking in a variety of ways, is intuitive, and
actively maintained

~~~
StavrosK
Is static checking with mypy just as good, faster and more timely?

~~~
rcthompson
They're not mutually exclusive. Static type checking is fine if you can cover
all your code with it, but it doesn't enforce anything at runtime. If you're
writing a library that will be called by other people's code (which likely
won't be statically type-checked), it might still be useful to validate your
functions' inputs at runtime.

~~~
StavrosK
True, and I guess it helps for when your non-validated code calls validated
code. Odd how we've come around to realizing the importance of types and
contracts after years of dynamic typing.

It's a bit like document databases, people are starting to realize again how
convenient relational databases and how helpful schemas are.

~~~
rcthompson
To be a little more clear, in a language where static typing was mandatory,
there would obviously be no need for dynamic type checking of those same
types. But since Python's static typing is optional, dynamic type checking at
runtime is not redundant.

------
varlock
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
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.

------
jdipierro
I'm surprised to not see Formencode's validation on any of these lists:
[http://www.formencode.org/en/latest/Validator.html](http://www.formencode.org/en/latest/Validator.html)

------
crdoconnor
If you want to validate YAML and want line numbers and code snippets in your
errors, I wrote this:

[http://github.com/crdoconnor/strictyaml](http://github.com/crdoconnor/strictyaml)

------
w_t_payne
I really like 'voluptuous' (and its' ungoogleable fork; 'good')

~~~
bitexploder
Seconded. It works and let's you build rules declaratively.

------
nolite
does anyone know of something like this for ruby?

~~~
ezekg
I wrote something similar for Ruby/Rails parameter validation. All of the
solutions that were around at the time weren’t what I was looking for. It ends
up looking like:
[https://gist.github.com/ezekg/f525a9d006c97cbcba231aa43e5ac9...](https://gist.github.com/ezekg/f525a9d006c97cbcba231aa43e5ac9b7).
Is that something people would be interested in me open sourcing?

------
souenzzo
Looks like clojure spec.

