6 ms·
Show HN: PySchemes – A library for validating data structures in Python
- sametmax 9y agoEverytime 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.
- mathgenius 9y agoThe great thing about python is it's so easy to roll your own. And people start thinking they are a genius or something. Ha :-)
- shivylp 9y agoNo one's thinking that. Oh wait. Look at the username !
- houzi 9y agoI 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 9y agoI 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.
- craigds 9y agomarshmallow: 62 watchers, 2055 stars, 244 forks. requests: 1142 watchers, 28420 stars, 5212 forks. I don't think those are in the same league
- aldanor 9y agoMarshmallow doesn't suppport some trivial constructs like nested dicts, and isn't likely to: https://github.com/marshmallow-code/marshmallow/issues/483 https://github.com/marshmallow-code/marshmallow/issues/483 To me, that's a complete showstopper.
- fermigier 9y agoHow 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
- fermigier 9y agoEven more interesting projects here: - https://awesome-python.com/#data-validation https://awesome-python.com/#data-validation
- shazzy 9y agoAlso 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 9y agoMay 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).
- logronoide 9y agoWhy is better PySchemes than others like Voluptuous? I’m happy with it, but open to new stuff.
- StavrosK 9y ago
- w_t_payne 9y agoI really like 'voluptuous' (and its' ungoogleable fork; 'good')
- bitexploder 9y agoSeconded. It works and let's you build rules declaratively.
- varlock 9y agoMaybe I'm missing something, but IMO using isinstance, issubclass and explicit checks achieves the same effect, and is probably more readable. Or not?
- gh02t 9y agoIt'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 9y agoI'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
- vram22 9y agoThere 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-python-to.html https://jugad2.blogspot.in/2015/12/using-json-schema-with-py...
- ansgri 9y agoExactly 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 9y agoThanks for the info.
- nolite 9y agodoes anyone know of something like this for ruby?
- ezekg 9y agoI 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/f525a9d006c97cbcba231aa43e5ac9b7 https://gist.github.com/ezekg/f525a9d006c97cbcba231aa43e5ac9.... Is that something people would be interested in me open sourcing?
- Dowwie 9y agoCheck 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 9y agoIs static checking with mypy just as good, faster and more timely?
- rcthompson 9y agoThey'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 9y agoTrue, 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 9y agoTo 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.
- crdoconnor 9y agoIf 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
- souenzzo 9y agoLooks like clojure spec.