Generic Python validation frameworks?

All Python ORM and form frameworks love to define own field/schema model. This seems to lead to a situation where they define their own validation functions too.

Some examples:

Isn’t writing one’s own validation code a bit redundant and exactly “reinventing the wheel” what open source principles so hard try to avoid? Could validation be a low hanging fruit to share among fellow Python projects? As I see it, for the simple data validation, like email and URL, the core code could be easily shared and different Python projects. You basically want just method is_valid_phonenumber(str) and then framework specific way to raise the error to the user.

Do such frameworks already exist? At least I haven’t seen one being used in any big Python project yet 🙁

… or is validation so complex thing, so that validation functions must be tightly integrated with the parent framework and I am missing some big things (like locales, etc.) here?

 

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+

14 thoughts on “Generic Python validation frameworks?

  1. This is something validatish (yeah, bad name) tries to accomplish. Don’t know if it’s what you’re looking for or not, but take a look.

  2. validatish and colander are both validation-only libraries. formencode does a lot more and its extra validators are very US-oriented, so I would not recommend it here.

  3. Here’s how you make a library like Colander or FormEncode which has its own schema work with other systems: an integration plugin generates a Colander schema that mirrors the existing schema of your Django model or whatever. Under normal usage you don’t need to deal with the generated schema, which at its simplest would just be a list of fields that are mirrored to the target schema.

    It’s sort of necessary for any library that is tasked with “validation” to work from a schema support. Even the simplest configuration of “type your password / repeat your password” represents a composite schema. The validation use case extends into composite validations almost immediately in the real world.

    FormEncode has international support though I haven’t worked with it to know if it has serious shortcomings. I have hacked FormEncode to do things it normally can’t do however.

  4. Formencode is fantastic, and very very easy to extend in sophisticated ways. I have found the more complex the validation gets, the better it is, I only wish it’s documentation better highlighted the power of it’s inner working. It has excellent design features for handling things like nested structures intelligently, looping over subschemas with access to the outer validator, all kinds of goodies.

  5. I asked for a simple validation and not form framework.

    Why I am getting dozens of suggestion for form and schema frameworks? Is everyone missing the point here?

Leave a Reply

Your email address will not be published. Required fields are marked *