For those looking to validate dictionaries / JSON responses in Python, the voluptuous library works quite well: http://github.com/alecthomas/voluptuous. It also works for lists and other data types.
I use a fork/successor library, good[0], for configuration validation. I've especially liked the data transformation it can do (I can easily allow a configuration entry to be a single value, or list of values, and transform that to always be a list)
Recently I had a similar wrote a library that creates (and dumps) your typed NamedTuples, datetimes and similar objects from simple JSON, using type annotations:
"JSON support for named tuples, datetime and other objects, preventing ambiguity via type annotations"
I've recently been using attrs as an easy way to make simple datatypes, but its only gesture towards validation is an arbitrary callback per field. Hooking into Python 3 type annotations is a great idea!
Does/will Pydantic handle all the standard dunder fields like __eq__, __lt__, __hash__, __cmp__ and faux-immutability like namedtuple and attrs do?
"faux-immutability" is a good way to describe it. My problem is the "faux"; proper immutability is virtually impossible in python and I'm not convinced about providing partial immutability and thereby giving people a false sense of security. That said there's an issue about it: https://github.com/samuelcolvin/pydantic/issues/38. I'll consider it if we can find a performant and elegant way of using it.
__eq__ makes sense, I'll do it when I get round to it
__hash__ would be nice but far from simple to do in a performant way.
Marshmallow is still the best lib in town. Indeed, most of the libs fall short when you start to use them in the real world. Where validation is more than a type, when fields are dependants on each others, when data is generated on the fly post validation and where you need all that to cascade down your nested, sometime recursive, data structure validation, which then should produce equally complex error messages.
Pydantic is not just a toy, I built it having used and abused numerous other libraries and found them wanting in one way or another.
Because it reuses python's typing system it should have the most pythonic and flexible description of types possible.
I agree about the need for complex validation chains relating to numerous fields, that's already partially possible with pydantic (although not documented). I'll add support for this stuff as well as documentation over the next few weeks.
Having used both colander and marshmallow extensively - I prefer colander mainly because it has first class explicit handling of null, missing and required values and it's support of nested and inheritance is also much nicer than marshmallow.
I agree. Marshmallow is the best game in town and I love using it. That said its not perfect and I'm eagerly awaiting a successor. I use it frequently and have run into a lot of cruft.
I wish the people who designed APIs would constrain themselves to libraries that could be validated as types. I rarely see insane data structures for APIs built in static languages, and I say this because my company has some absurd APIs which would not be so bad if the developers were constrained a bit.
[+] [-] svisser|8 years ago|reply
[+] [-] Varriount|8 years ago|reply
[0] https://github.com/kolypto/py-good
[+] [-] user5994461|8 years ago|reply
Python comes with the jsonschema module out of the box.
[+] [-] vog|8 years ago|reply
"JSON support for named tuples, datetime and other objects, preventing ambiguity via type annotations"
https://github.com/m-click/jsontyping
If you are interested, please have a look at the first unit tests to see how it works:
https://github.com/m-click/jsontyping/blob/master/tests/test...
Note that the tests currently use the "ugly" NamedTuple syntax to be compatible with Python 3.5 and 2.7.
[+] [-] thristian|8 years ago|reply
Does/will Pydantic handle all the standard dunder fields like __eq__, __lt__, __hash__, __cmp__ and faux-immutability like namedtuple and attrs do?
[+] [-] scolvin|8 years ago|reply
__eq__ makes sense, I'll do it when I get round to it
__hash__ would be nice but far from simple to do in a performant way.
__lt__ I'm not sure what this would mean?
__cmp__ no longer exists in python 3.
[+] [-] noisy_boy|8 years ago|reply
[+] [-] cidnurh|8 years ago|reply
[+] [-] juni0r|8 years ago|reply
[+] [-] mkesper|8 years ago|reply
[+] [-] sametmax|8 years ago|reply
A data validation framework is not a toy project.
[+] [-] scolvin|8 years ago|reply
Because it reuses python's typing system it should have the most pythonic and flexible description of types possible.
I agree about the need for complex validation chains relating to numerous fields, that's already partially possible with pydantic (although not documented). I'll add support for this stuff as well as documentation over the next few weeks.
[+] [-] zepolen|8 years ago|reply
[+] [-] rukittenme|8 years ago|reply
[+] [-] weberc2|8 years ago|reply
[+] [-] Varriount|8 years ago|reply
[0] https://github.com/kolypto/py-good