Flask-value-checker 🔎
Imaging web form checking, but now imagine that it was easy and comfy
Example usage
from flask_value_checker import Invigilator
from flask import Flask, request
invigilator = Invigilator()
@app.route('/abc', methods=['POST'])
@invigilator.check(
'POST',
'''
username : str/lenlim(5, 15)
password : str/lenlim(8, inf)
stayLoggedIn : str/accept(['on'])/optional
'''
)
def abc():
stay_logged_in = request.form.get('stayLoggedIn', 'off')
return f'hi {request.form['username']}, stay logged in: {stay_logged_in}'
app.run()
example default error
Note: this error can be customized
{
"error": {
"code": "MALFORMED_OR_MISSING_PARAMETERS",
"message": "one or more fields we're either missing or malformed",
"fields": {
"email" : "missing parameter, parameter is required",
"firstName" : "string length must be between 5 and inf",
"age" : "parameter has to be of type 'int'"
...
}
}
}
function docs 📔 📓 📕 📘
Invigilator(err_function=None)
- Type :
functionorNone - Description : the function that displays the final error to the webpage, must be written the the way a standard flask function is written, (although you may wanna check out Flask.Response, and return that instead of a tuple like
(error, 400)) - Example
def custom_error_shower(errors):
return Response(
json.dumps({"errors": errors,}), status=400, mimetype="application/json"
)
Invigilator.check(http_methods, checker_str)
http_methods:
- Type :
strorlist of strs - Description : HTTP methods to check for,
NOTE: if the http method to check for is not present in methods, the decorated function will be called normally and no checks will be performed
- Example :
'GET','POST',['GET', 'POST']
field name attribute docs
all top attributes (str, int, float) should not have any parameters,
Note: top attributes should be placed first, then its sub attributes should be placed
str
lenlim(min, max)
the minimum and maximum length the fields string can be
- min :
intor the valueinf, the minimum accepted string length - max :
intor the valueinf(see example-usage), the maximum accepted string length
optional
is the attribute optional ?
accept(accepted_vals)
values that can be accepted when using the field name
- accepted_vals:
list of strings, the acceptable values for the parameter
int and float
int specifies that the number must be an integer,
float specifies that it can be decimal,
both attributes have the same sub-attributes
lim(min, max)
the limits that the numeric values can range between
- min :
floator the valueinf, the minimum accepted numeric value - max :
floator the valueinf(see bigger-full-example), the maximum accepted numeric value
optional
is the attribute optional ?
checker_str
- Type :
str - Description : the form attributes and their restrictions written in the prescribed format, See Here
Guide 🤘
Writing parameters:
- different parameters are separated by a newline
- the parameter and its rules are separated by an
: - rule conditions are separated by an
/ - the first condition should be the type of the required value,
str,intorfloat - condition arguments are put in brackets
()
example:
score : float/lim(0, 11.5)/optional
bigger full example
@app.route('/abc')
@invigilator.check(
'POST',
'''
firstName : str/lenlim(1, 15)
middleName : str/optional
lastName : str/optional
stayLoggedIn : str/accept(['on'])/optional
email : str
password : str/lenlim(8, inf)
phone : str/lenlim(8, 15)
# number will have to be an Int,
# but it'll have to be greater than
# 18, not including 18
age : int/lim(18.9, inf)
score : float/lim(0, 10) # can be a decimal value
'''
)
def abc():
some_content
Dev-docs
- codestyle : black
- documentation style : numpydoc
- HTTP-Returns extra to Numpydoc, that is similar to Return, but is represented as follows
'''
HTTP-Returns
------------
400
on failure, the response will be similar to,
{
"error": {
"code": "MALFORMED_OR_MISSING_PARAMETERS",
"message": "one or more fields we're either missing or malformed",
"fields": {
"email" : "missing parameter, parameter is required",
"firstName" : "name has to be under 15 characters",
"age" : "parameter has to be of type 'int'"
...
}
}
}
*
or whatever the original function returns
*
'''
i.e.
<return code>
<details>
<return message>
Metadata
Release files for flask-value-checker 1.1
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 |
|---|---|---|---|---|
| flask-value-checker-1.1.tar.gz | 13.5 kB | Without provenance | Details for flask-value-checker-1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_value_checker-1.1-py3-none-any.whl | Python 3 | none | any | Details for flask_value_checker-1.1-py3-none-any.whl |
Total release size: 27.0 kB
Release files / flask-value-checker-1.1.tar.gz
| Download URL | flask-value-checker-1.1.tar.gz |
|---|---|
| Size | 13.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2330453dc5e18e1d03f371572babf5ccd0ca14f533c32ce58dd5e984d338fab0
|
|
BLAKE2b-256 checksum How to use checksums |
4fae6fb00e884883110c4fb829257af050f186e5d4d4779855ce810535cfff44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.22.0
|
Release files / flask_value_checker-1.1-py3-none-any.whl
| Download URL | flask_value_checker-1.1-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4c4a785606843842363d8ac126691573213068721d3f63b65eea625356fb5ea1
|
|
BLAKE2b-256 checksum How to use checksums |
69ae74845a883a717efe7ffc8158c86b721acd0f4d005269343fe8a7a0559eda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.22.0
|
Security for flask-value-checker 1.1
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.