skip to navigation
skip to content

Not Logged In

validator.py 0.6.1

A library for validating that dictionary values meet certain sets of parameters. Much like form validators, but for dicts.

Latest Version: 1.2.0

validator.py [![Build Status]https://travis-ci.org/mansam/validator.py.png?branch=master]https://travis-ci.org/mansam/validator.py [![PyPI version]https://badge.fury.io/py/validator.py.png]http://badge.fury.io/py/validator.py [![Bitdeli Badge]https://d2weczhvl823v0.cloudfront.net/mansam/validator.py/trend.png]https://bitdeli.com/free "Bitdeli Badge")
============

A library for validating that dictionary values meet certain sets of parameters. Much like form validators, but for dicts.

## [Documentation]http://validatorpy.readthedocs.org/en/latest/index.html

This README has some basic usage information, but more detailed documentation may be found at [ReadTheDocs]http://validatorpy.readthedocs.org/en/latest/index.html)

## Usage Example

First, install it from PyPI.

pip install validator.py


```python

from validator import Required, Not, Truthy, Blank, Range, Equals, In, validate

# let's say that my dictionary needs to meet the following rules...
rules = {
"foo": [Required, Equals(123)],
"bar": [Required, Truthy()],
"baz": [In(["spam", "eggs", "bacon"])],
"qux": [Not(Range(1, 100))] # by default, Range is inclusive
}

# then this following dict would pass:
passes = {
"foo": 123,
"bar": True, # or a non-empty string, or a non-zero int, etc...
"baz": "spam",
"qux": 101
}
print validate(rules, passes)
# (True, {})

# but this one would fail
fails = {
"foo": 321,
"bar": False, # or 0, or [], or an empty string, etc...
"baz": "barf",
"qux": 99
}
print validate(rules, fails)
# (False,
# {
# 'foo': ["must be equal to '123'"],
# 'bar': ['must be True-equivalent value'],
# 'baz': ["must be one of ['spam', 'eggs', 'bacon']"],
# 'qux': ['must not fall between 1 and 100']
# })
```  
File Type Py Version Uploaded on Size
validator.py-0.6.1.tar.gz (md5) Source 2014-01-31 4KB
  • Downloads (All Versions):
  • 45 downloads in the last day
  • 286 downloads in the last week
  • 574 downloads in the last month