Data validation utilities
Project description
vutils-validator: Data Validation Utilities
This package provides a set of tools that helps with validation of input data.
Installation
To get the package on your system, type
$ pip install vutils-validator
How to Use
Please, read the following subsections to get more info about particular use case.
Basic Validations
Module vutils.validator.basic
provides a set of functions for validation of
simple input data forms, like email addresses:
verify_not_empty(value)
fails ifvalue
is empty.verify_matches(value, regex, message="")
fails ifvalue
does not match regular expressionregex
. Since many regular expressions describe entities that have a name (identifier, number, email address, etc.) the default error message can be overridden bymessage
argument.verify_email(value)
fails ifvalue
is not an email address (currently described by simple^\S+@\S+\.[A-Za-z]+$
regular expression).
The value
passed to all validation functions can be either str
or a
ValueHolder
(from vutils.validator.value
) object. A ValueHolder
object
can be used to store additional information about value, like its name and
origin. The synopsis of ValueHolder
's constructor is
__init__(self, value, name="The value", location=None)
, where value
,
name
, and location
are value, its name, and the location of its origin,
respectively. location
is a Location
(from vutils.validator.value
) object
that holds path, line, and column of the value/token origin. ValueHolder
serves to provide more detail about value in error messages issued by
validation functions by raising ValidationError
(from
vutils.validator.errors
) when the validation fails, example:
from vutils.validator.basic import verify_email
from vutils.validator.errors import ValidationError
from vutils.validator.value import ValueHolder
def get_input(name):
return ValueHolder(input(f"Enter {name}: "), name)
try:
verify_email(get_input("email"))
except ValidationError as exc:
print(exc)
On ill-formed input, the example prints email must be an email address!
,
since get_input
names a value as email
.
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
Built Distribution
Hashes for vutils_validator-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6f8b6ec49fc3c9f3f6e1cd30473352387c4a986c3e34b1055293bc517ab96b2 |
|
MD5 | 6c0b5cb7603f38624b0b38326944e8c8 |
|
BLAKE2b-256 | fc5175ee581bb437b462ec057e90a2b628a257001a97807336f00e61ca0d634c |