A library for validating that dictionary values meet certain sets of parameters. Much like form validators, but for dicts.
Project description
A library for validating that dictionary values meet certain sets of parameters. Much like form validators, but for dicts.
Documentation
This README has some basic usage information, but more detailed documentation may be found at ReadTheDocs.
Usage Example
First, install it from PyPI.
pip install validator.py
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']
# })
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file validator.py-1.2.3-py2.py3-none-any.whl.
File metadata
- Download URL: validator.py-1.2.3-py2.py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bab2418e8e249b7be9fa76daf27e70d9b4c33880190e2857138a8ca7c1906182
|
|
| MD5 |
e5133b74adb66aecf5a4af9e9c490d02
|
|
| BLAKE2b-256 |
eba08cc41a72aad708fcfdbea8d363fd9dfd4ea6d652a5acfb9a130e840d6c07
|