Uses filter groups to validate requests
Project description
Request Filter Groups
Description
A Python wrapper and utility function for validating requests.
The funtions takes a list of dictionaries containing JSON paths keys to search for the attribute to validate and filter rule values to validate the attributes with. Under the hood, the validation process uses Validator to validate the JSON path values with the Validator rules. If atleast one filter group is validated, then the funcion returns True. List of possible Validator rules can be found here:
Examples
Decorator:
Succeeded Validation
r = RequestFilter()
@r.request_filter_groups([
{
"A.B": "regex:foo",
"C": "required|min:3"
}
])
def func(data):
# <response logic>
return {"statusCode": 200}
request_data = {
"A": {"B": "foo"},
"C": [1, 2, 3]
},
response = func(data)
Returns dummy func()
return value:
{"statusCode": 200}
Failed Validation
r = RequestFilter()
@r.request_filter_groups([
{
"A.B": "regex:foo",
"C": "required|min:10"
}
])
def func(data):
# <response logic>
return {"statusCode": 200}
request_data = {
"A": {"B": "foo"},
"C": [1, 2, 3]
},
response = func(data)
Returns validate()
return value
{'statusCode': 422, 'body': ValidationError({'C': {'Min': 'Expected Maximum: 10, Got: 3'}})}
Installation
Package can be found on PyPI
pip install request-filter-groups
TODO:
- Add Flask-related tests
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 request-filter-groups-0.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b274c50a855b991522e296b95e6e93a162083514410623e95033860ae75c0b37 |
|
MD5 | 8f0624185ba67dbe51ced3923d8e2198 |
|
BLAKE2b-256 | 9ffae5068718660c6b9e820579e66368589f3f5f91a59b0feb052161c9e48350 |
Hashes for request_filter_groups-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ebfcd2c56cd25f3a5c274b20b8c2f3017087d21dce5a5e54157df92ada8636c |
|
MD5 | b4e52d52f6111505ebd3f10e3a8b2d68 |
|
BLAKE2b-256 | 2a5e38d932d788421a5b221f504eec34909f124d889bc0de500eec5ee7c884c5 |