Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

validator.py-1.2.4.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

validator.py-1.2.4-py2.py3-none-any.whl (8.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file validator.py-1.2.4.tar.gz.

File metadata

  • Download URL: validator.py-1.2.4.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for validator.py-1.2.4.tar.gz
Algorithm Hash digest
SHA256 81dcf3a73f189fdff8a606cf4b6cd6272088251b9b250a7c9cd59099a4dfac5e
MD5 2e45d2c02803813036d01845df1d9467
BLAKE2b-256 546abbacd59749287cd9cd7cf943815aae8feeafe22dcee5fea424e1db89da85

See more details on using hashes here.

File details

Details for the file validator.py-1.2.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for validator.py-1.2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2590ea23b04db9d67780636a612b8ee8af909214db9dce8c85e35c015c3d30f2
MD5 e427c6049593ed0cb92261ccb8b6f40a
BLAKE2b-256 2a1fa1848d7a374580120210bfe0a6e2ed6c0ccb9594c9f082d2ccbce7a6c2dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page