Function Argument Pre-Processor
This is a abstract library that need to be extended before put actual use.
The primary use case is to extend it as a Flask Extenstion but is open to use with any other environment/framework that needs to deal with http endpoints eg: AWS Lambda
Implementations
Installation
$ pip install funcargpreprocessor
or download the code and run
$ python3 setup.py install
What it does?
- Extraction and transformation of function argument and raise appropriate exceptions
Example
- Please refer testimplementation.py and fieldtest.py for examples
Explanation
The following explanantion uses the example from test folder
def get_current_time():
return datetime.now().replace(microsecond=0)
def get_current_date():
return date.today()
def get_future_date(date_factor=1):
def inner_fu():
return date.today() + timedelta(date_factor)
return inner_fu
from enum import Enum
class Gender(Enum):
MALE = "male"
FEMALE = "female"
TRANSGENDER = "transgender"
definition = {
"pageNo": { #Key name expected from the HTTP endpoint
"data_type": int # Data type expected
, "min_val": 0 # Min validation for the key
, "max_val": 20 # Max validation for the key
, 'alias': 'page_no' # Key for the function argument, to the function the argument will be 'page_no'
# Need? most of the time the http request are expected json and the keys will be in camelCase
, "default": 1 # Default value for the field if no value has been passed
}
, "start_date": {
"data_type": DateArg('%Y-%m-%d') # Expects a date argument in <str>'YYYY-MM-DD' format or datetime.date object accepts '2020-01-10', datetime.date(2020, 1, 10) converts,in case of a string argument, to datetime.date(2020, 1, 10) and passes it to the function
, "min_val": get_current_date # Function can be passed for min value, this function should not take any argument and should return a single value of the same type
, "max_val": get_future_date(10) # Function can be passed for max value, this function should not take any argument and should return a single value of the same type
, "required": True # This key is required to be there in the input
}
, "id_list": {
"data_type": list # Expects list of value
, "nested": int # The values in the list should be int same rule as `date_type`
, "value_list": [0, 1, 2, 3] # Accepted values, valid argument ex: [1,2], [1], [2,3,0]
# Need? Multiselect options
}
, "gender": {"data_type": str, "value_list": Gender} #Enum can be used for the value list and will be marshalled
, "random_flag": {"data_type": int, "value_list": [0,1]}
, 'reg_time': {"data_type": DateTimeArg('%Y-%m-%d %H:%M:%S'),
"default": get_current_time # Function can be passed for default value, this function should not take any argument and should return a single value of the same type
}
, "location": {"data_type": list
, "nested": { # Custom definition for objects in the list
"address_line_1": {"data_type": str, "required": True}
, "address_line_2": {"data_type": str
, "min_len": 5 #Mininum length expected for the argument
, "max_len": 10 # Maximum length accepted for the argument
}
, "latitude": {"data_type": DecimalArg(), "min_val": Decimal("-90"), "max_val": Decimal("90")}
, "longitude": {"data_type": DecimalArg(), "min_val": Decimal("-180"), "max_val": Decimal("180")}
, "pincode": {"data_type": int, "required": True}
, "contact_person": {
"data_type": dict
, "nested": {
"first_name": {"data_type": str, "required": True}
, "last_name": {"data_type": str}
, "phone_number": {
"data_type": str
, "required": True
, "regex": r"[0-9]{10,12}" # Regular expression validation
, "regex_error_message": "<some message>" # Message when the RegEx validation fails
}
}
}
}
}
}
Metadata
Release files for funcargpreprocessor 0.10.3
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 |
|---|---|---|---|---|
| funcargpreprocessor-0.10.3.tar.gz | 6.4 kB | Without provenance | Details for funcargpreprocessor-0.10.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| funcargpreprocessor-0.10.3-py3-none-any.whl | Python 3 | none | any | Details for funcargpreprocessor-0.10.3-py3-none-any.whl |
Total release size: 15.1 kB
Release files / funcargpreprocessor-0.10.3.tar.gz
| Download URL | funcargpreprocessor-0.10.3.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef1fab53ea5e0861821b6dac06c83ba360d8309a6f3489edb9e13f0f15e791aa
|
|
BLAKE2b-256 checksum How to use checksums |
2eb5f58f09836fcdc373e7f01be3e7e572062df2aa72cebe443fddf0a5971fd1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10
|
Release files / funcargpreprocessor-0.10.3-py3-none-any.whl
| Download URL | funcargpreprocessor-0.10.3-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f50c30c446389cd19dee32af6fb8e0934d9069d619d3e4a7aae3a1e996f1a9a0
|
|
BLAKE2b-256 checksum How to use checksums |
2b7d68acc217dc81767f2cf5417e684c38b736278c22a893d14a55edc1668b8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10
|
Security for funcargpreprocessor 0.10.3
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.