A easy dependency validator
Project description
required: A Easy Dependency Validator
=====================================
[![Build Status](https://travis-ci.org/shezadkhan137/required.svg?branch=master)](https://travis-ci.org/shezadkhan137/required)
`required` is a simple Python package which allows you to validate function argument dependencies in situations where there are a large number of optional parameters. Places where you may have this are:
* In a API where you may have a number of optional query parameters, that are only valid under some permutations
* Functions which receive **kwargs but need to validate that it is correct
Some examples to make it a bit more clear:
```python
>>> from required import Requires, R, validate
>>> @validate(Requires("x", "y"))
... def some_function(x=None, y=None):
... pass
>>> some_function(x=1)
RequirementError: x requires 'y' to be present
>>> @validate(Requires("x", R("x") <= R("y")))
... def x_must_be_less_or_equals_to_y(x, y):
... return x,y
>>> x_must_be_less_or_equals_to_y(x=3, y=2)
RequirementError: x requires x to be less than or equal to y
>>> @validate(Requires("x", R("y") >= R("x")) + Requires("z", R("y") <= R("z")))
... def z_must_be_gte_y_and_y_must_gte_x(x,y,z):
... return x,y,z
>>> z_must_be_gte_y_and_y_must_gte_x(x=1, y=2, z=1)
RequirementError: z requires y to be less than or equal to z
```
### Caveats
* The validation is done through dictionary types. Therefore all parameters to your function
must be passed as **kwargs, *args are unchecked.
* Currently this is still in the early stages and so most likely have bugs. YMMV
* Only a limited number of expressions are currently supported
* Only simple comparison operations are supported
### TODO
* Add more expression operators
* Add support for more complex expressions
* Add tests for partial dependencies
=====================================
[![Build Status](https://travis-ci.org/shezadkhan137/required.svg?branch=master)](https://travis-ci.org/shezadkhan137/required)
`required` is a simple Python package which allows you to validate function argument dependencies in situations where there are a large number of optional parameters. Places where you may have this are:
* In a API where you may have a number of optional query parameters, that are only valid under some permutations
* Functions which receive **kwargs but need to validate that it is correct
Some examples to make it a bit more clear:
```python
>>> from required import Requires, R, validate
>>> @validate(Requires("x", "y"))
... def some_function(x=None, y=None):
... pass
>>> some_function(x=1)
RequirementError: x requires 'y' to be present
>>> @validate(Requires("x", R("x") <= R("y")))
... def x_must_be_less_or_equals_to_y(x, y):
... return x,y
>>> x_must_be_less_or_equals_to_y(x=3, y=2)
RequirementError: x requires x to be less than or equal to y
>>> @validate(Requires("x", R("y") >= R("x")) + Requires("z", R("y") <= R("z")))
... def z_must_be_gte_y_and_y_must_gte_x(x,y,z):
... return x,y,z
>>> z_must_be_gte_y_and_y_must_gte_x(x=1, y=2, z=1)
RequirementError: z requires y to be less than or equal to z
```
### Caveats
* The validation is done through dictionary types. Therefore all parameters to your function
must be passed as **kwargs, *args are unchecked.
* Currently this is still in the early stages and so most likely have bugs. YMMV
* Only a limited number of expressions are currently supported
* Only simple comparison operations are supported
### TODO
* Add more expression operators
* Add support for more complex expressions
* Add tests for partial dependencies
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
required-0.1.1.tar.gz
(5.8 kB
view details)
File details
Details for the file required-0.1.1.tar.gz
.
File metadata
- Download URL: required-0.1.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6cd28c409b1c7c162535b39fc0d971d9d850930b2da263e813131893ad3b018 |
|
MD5 | d671c79f3b50b12b267c0f1144cf2428 |
|
BLAKE2b-256 | 2fc3c8fb8b3bf7b320e45e28499404926ca340486c36735e90a0f5154d14b7f9 |