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).
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).
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.
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.
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.
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.
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.
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.
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.
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.... Is that something people would be interested in me open sourcing?
- https://github.com/alecthomas/voluptuous
- https://github.com/schematics/schematics
- https://github.com/pyeve/cerberus
- https://github.com/fuhrysteve/marshmallow-jsonschema