Validator
Validator is a Python library for dealing with request validating.
Installation
Use the package manager pip to install Validator.
pip install validator
Usage
User should pass request dictionary and rules dictionary for validating data in the request.
Please see examples below:
from validator import validate
reqs = {"name": "Jon Doe",
"age": 33,
"mail": "jon_doe@gmail.com"}
rule = {"name": "required",
"age": "integer|min:18",
"mail": "required|mail"}
result = validate(request, rules) # True
valiadte() returns either True or False.
Another option is to use Validator class
from validator import Validator
reqs = {...}
rule = {...}
val = Validator(request, rules)
result = val.validate() # True
Error Messages
Validator allows user to have a look at failed validations
from validator import validate
reqs = {"name": "",
"mail": "jon_doe"}
rule = {"name": "required",
"mail": "mail"}
result, errors = validate(reqs, rule, return_errors=True)
"""
result = True
errors = {'name': {'Required': 'Field was empty'},
mail': {'Mail': 'Expected a Mail, Got: jon_doe'}}
"""
Or you can use Validator class for error messages as well (result and errors are same).
val = Validator(request, rules)
result = val.validate()
errors = val.get_error_messages()
Rules
Validator Rules can be used in different ways. Please see some examples below:
Strings
rule = {"name": "required",
"age": "integer|min:18",
"mail": "required|mail"}
Array of Strings
rule = {"name": ["required"],
"age": ["integer", "min:18"],
"mail": ["required", "mail"]}
Array of Rules
from validator import rules as R
rules = {"name": [R.Required()],
"age": [R.Integer(), R.Min(18)],
"mail": [R.Requried(), R.Mail()]}
Other Miscellaneous
from validator import rules as R
rules = {"name": R.Required(), # no need for Array Brackets if one rule
"age": [R.Integer, R.Min(18)],
"mail": [R.Requried, R.Mail]} # no need for class initialization with brakcets ()
# if no arguments are passed to rule
All of rules are listed in RULES.md file
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please see CONTRIBUTING.md before making PR :)
License
Metadata
Release files for validator 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| validator-0.1.2.tar.gz | 22.2 kB | Without provenance | Details for validator-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| validator-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for validator-0.1.2-py3-none-any.whl |
Total release size: 36.6 kB
Release files / validator-0.1.2.tar.gz
| Download URL | validator-0.1.2.tar.gz |
|---|---|
| Size | 22.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
628f17f1b84cd84d3c5d91448c17ac3e8b35438c51fe4cdb0fc764c22a76d00f
|
|
BLAKE2b-256 checksum How to use checksums |
3a8001d0da6303950f6188053911a517f88f1cebf4370c794b7dbf613ca27d44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2
|
Release files / validator-0.1.2-py3-none-any.whl
| Download URL | validator-0.1.2-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2cbd8d91b8c34e27ee57316fc51c7becae8a1cafc32e397a5e6c412ad7ba38ee
|
|
BLAKE2b-256 checksum How to use checksums |
1d01ae6bde012a2e608a59a04d08fb210f88ee987a2ce2ea9a33105713db51da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2
|
Security for validator 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.