News for hackers. Stuff that matters.
Re:'New' Python modules of 2015 by StavrosK on Wednesday December 23, 2015 @11:38AM (#10784096)
Hands down, my favorite new library is schema:

https://pypi.python.org/pypi/schema

Here's a schema I use in production, see how readable it makes the parameters of the API and how quick all the validation and normalization is:

https://www.pastery.net/mhwwnv/

At the end, you get an object called data, and you can do data.title, data.language, etc, and be sure that everything is as you expect.

Re:'New' Python modules of 2015 by fidget on Wednesday December 23, 2015 @12:32PM (#10784422)
For those of us more dictionary oriented, there is https://pypi.python.org/pypi/voluptuous (which is OK for the most part, as long as you are only trying to do validation, and nothing too crazy)
Re:'New' Python modules of 2015 by odonnellryan on Wednesday December 23, 2015 @02:00PM (#10784940)
Similar, I've used this library with a lot of success: https://marshmallow.readthedocs.org/en/latest/
Re:'New' Python modules of 2015 by makmanalp on Wednesday December 23, 2015 @05:34PM (#10786075)
+1 for marshmallow - most of the serialization libraries are 80% there, but marshmallow has it 95% down - all the weird corner cases about nested models and lists of nested models and all that. Plus the dev is very helpful and courteous on github.
Re:'New' Python modules of 2015 by aidos on Wednesday December 23, 2015 @02:40PM (#10785162)
I've tried truckloads of Python serialisation libs over the last few years and marshmallow is the one that finally makes me feel like I don't need to look for another one.
Re:'New' Python modules of 2015 by odonnellryan on Wednesday December 23, 2015 @02:53PM (#10785237)
It's very easy and does everything I've needed it to!
Re:'New' Python modules of 2015 by NightMKoder on Wednesday December 23, 2015 @04:52PM (#10785901)
Looks extremely similar to https://github.com/schematics/schematics . Always good to see two projects approach the problem the same way independently - higher chance that the solution is right :)

Schematics has a very useful feature in "roles" - i.e. a good way of hiding certain fields in certain situations (e.g. admin views vs self vs other vs anonymous). Does marshmallow have something similar?

Re:'New' Python modules of 2015 by Walkman on Wednesday December 23, 2015 @04:10PM (#10785665)
Marshmallow is also my favourite lib of the year. Pyramid guys love it too! The developer is responsive, and the library moves really fast!
Re:'New' Python modules of 2015 by stuaxo on Wednesday December 23, 2015 @04:12PM (#10785680)
That looks great, I've built similar things myself and it's great to find someone elses I can use.
Re:'New' Python modules of 2015 by Dowwie on Wednesday December 23, 2015 @08:22PM (#10786571)
hear hear. Steve Loria, the author, has done tremendous work this year. Thanks Steve!
Re:'New' Python modules of 2015 by hedgehog on Wednesday December 23, 2015 @02:15PM (#10785032)
On the binary side Construct is quite nice: https://construct.readthedocs.org

I've used it for parsing various network protocols to good effect.

Re:'New' Python modules of 2015 by StavrosK on Wednesday December 23, 2015 @12:41PM (#10784469)
Huh, voluptuous looks pretty much exactly the same as schema. Or at least a subset of it, as it doesn't have And/Or/Use, as far as I can see.
Re:'New' Python modules of 2015 by mixmastamyk on Wednesday December 23, 2015 @01:05PM (#10784607)
I believe it may, perhaps analogous to its Any and All, etc.
Re:'New' Python modules of 2015 by rezacks on Thursday December 24, 2015 @02:04AM (#10787409)
voluptuous is simple and useful
Re:'New' Python modules of 2015 by shinryuu on Wednesday December 23, 2015 @02:48PM (#10785212)
There is also JSON-Schema protocol: http://json-schema.org/implementations.html curious how schema may be superior :).
Re:'New' Python modules of 2015 by lqdc13 on Wednesday December 23, 2015 @04:05PM (#10785639)
Yup, this one is way easier to use and very cross-language compatible.
Re:'New' Python modules of 2015 by pbowyer on Thursday December 24, 2015 @04:46AM (#10787679)
> Here's a schema I use in production, see how readable it makes the parameters of the API and how quick all the validation and normalization is: https://www.pastery.net/mhwwnv/

Thank you so much for providing this example. I couldn't grok what schema did, and your code made it make sense.

If people want to provide examples for the other libraries in this thread, you'll be popular :)

Re:'New' Python modules of 2015 by tenfingers on Thursday December 24, 2015 @07:08AM (#10787918)
Anyone that have been using schema after using 'rx' (https://pypi.python.org/pypi/Rx/)?

I generally like the simplicity of Rx and the fact that's language agnostic (I've used it with both json and yaml and other serialization libraries), with schemas themselves being written both systems. However, the lacking documentation has always been a problem.

Re:'New' Python modules of 2015 by lsh on Wednesday December 23, 2015 @11:47AM (#10784153)
Any relation to the Clojure Schema? https://github.com/Prismatic/schema
Re:'New' Python modules of 2015 by StavrosK on Wednesday December 23, 2015 @11:49AM (#10784167)
Possibly? It certainly looks similar.
Re:'New' Python modules of 2015 by bpicolo on Wednesday December 23, 2015 @12:30PM (#10784403)
Optional being an attribute of the key rather than the value is pretty bizarre to me, I've seen that patten a couple times. Feels like the wrong way to go about it
Re:'New' Python modules of 2015 by HeyImAlex on Wednesday December 23, 2015 @12:49PM (#10784517)
Think about it in terms of composability of validators; "having a key" is a property of the dict/object, not the value that is stored there. I feel your intuition, but experience says otherwise.
Re:'New' Python modules of 2015 by StavrosK on Wednesday December 23, 2015 @12:39PM (#10784463)
I see what you mean, but it's the key that's optional, not the value.
Re:'New' Python modules of 2015 by bpicolo on Wednesday December 23, 2015 @01:38PM (#10784823)
Ahh. That makes sense then. The value of the key being optional is indeed a different concept. Fwiw, this is one huge downside of Swagger APIs. Swagger supports the concept of optional keys but not optional values >.>

I have yet to find a validation library that supports all the sorts of things I expect it to. One place they tend to fail is the ways they can fulfill default values.

Say a field has an error and I want to just give it a default value when it's broken? That particular feature doesn't exist in any library i've found so far (for python) =/

Granted, this sort of blends into the usual "It's a validation library not a serialization library". But they all make a half-assed attempt at the other side in my experience.

Re:'New' Python modules of 2015 by noir_lord on Thursday December 24, 2015 @06:32AM (#10787854)
I like Schema and Voluptuous enough that as a polyglot who mostly works in PHP I'm working on a PHP version at the moment.
Re:'New' Python modules of 2015 by reinhardt on Thursday December 24, 2015 @02:50PM (#10789384)
In similar vein is valideer: https://pypi.python.org/pypi/valideer
Re:'New' Python modules of 2015 by jgalt212 on Thursday December 24, 2015 @03:26PM (#10789488)
What's the difference between these sort of libraries and an ORM? Don't ORM's provide built in validation and serialization?
Re:'New' Python modules of 2015 by taha_jahangir on Saturday December 26, 2015 @03:18AM (#10793655)
They are useful when you want backend-independent orm (say you want to save your objects as JSON in ceph in deployment, and in sqlite in development)
Re:'New' Python modules of 2015 by jgalt212 on Tuesday December 29, 2015 @06:59AM (#10806295)
I thought most ORMs were back-end independent. Isn't that 1/2 of their value proposition? The other half being accessing a persistence layer in native code.