VF: Validation Functions (for Python dicts.)
Project description
VF
VF = Validation Functions (for Python dicts.)
Installation
For now, please download the vf.py
module into your project directory. We should soon introduce a simpler installation method.
Quickstart
Create a validator function by supplying a schema:
import vf;
personValidator = vf.dictOf({
"_id": vf.typeIs(str),
"name": vf.dictOf({
"first": vf.typeIs(str),
"last": lambda x: type(x) is str,
}),
"birth_timestamp": vf.typeIs(int),
"gender": lambda x: x in ["MALE", "FEMALE", "OTHER"],
"parentIdList": vf.listOf(vf.typeIs(str)),
"spouceId": lambda x: x is None or type(x) is str,
"childrenIdList": vf.listOf(vf.typeIs(str)),
});
Use validator function to test if dicts are valid:
personValidator({
"_id": "00a3",
"name": {"first": "John", "last": "Doe"},
"birth_timestamp": 318191400000,
"gender": "MALE",
"parentIdList": ["00a1", "00a2"],
"spouceId": "87b1",
"childrenIdList": ["00a6", "00a8"],
}); # Returns `True` => Valid
If validation fails, vf.ValidationError
will be raised:
personValidator({
"_id": "1c3f",
"name": {"first": "Jane", "last": "Doe"},
"birth_timestamp": "1990-01-01",
"gender": "FEMALE",
"parentIdList": ["1c3a", "1c3b"],
"spouceId": None,
"childrenIdList": [],
}); # Raises `vf.ValidationError` => Invalid
Schema
The schema supplied to vf.dictOf(.)
should be a dict
, where each value is a boolean functions. In the above example, vf.typeIs(str)
is a shorthand for lambda x: type(x) is str
.
Licensing
Copyright (c) 2020 Polydojo, Inc.
Software Licensing:
The software is released "AS IS" under the MIT license, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Kindly see LICENSE.txt for more details.
No Trademark Rights:
The above software licensing terms do not grant any right in the trademarks, service marks, brand names or logos of Polydojo, Inc.
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 Distribution
Built Distribution
Hashes for vf-0.0.1rc0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2cb1b65b75d744e7e1b9da6ccd6085c486da3c187255c2c660c405bcd48c3b7 |
|
MD5 | 653efe6187ef3d94c2841e17d0877225 |
|
BLAKE2b-256 | 855b68323370840a0f69cba629b3a2b960a79e780e47a395c1f884ac4bb3fd53 |