Flask-Validation-Extended

Easily validate all parameters coming into your flask!
Provides validation function for all parameters that can be input such as Header, Route, Query, Form, Json, and File.
Install
Pip: pip install flask-validation-extended
Direct:
git clone https://github.com/iml1111/flask-validation-extendedpython setup.py install
Get Started
from flask import Flask
from flask_validation_extended import Validator
from flask_validation_extended.params import Route, Json, Query
from flask_validation_extended.types import List
from flask_validation_extended.rules import MinLen, Min, Max, IsoDatetime
app = Flask(__name__)
"""
id: Collected in the URI parameter, and must be int.
username: Collected from Body-Json, must be str, and minimum length greater than 5.
age: Collected from Body-Json, it must be an int, and must be between 16 and 98.
nicknames: Collected by Body-Json, it should be a list consisting of str.
birthday: Collected from Body-Json, must be str, and must be in ISO Datetime format.
expire: Collected from Body-Json, and it must be int, but it does not have to be input. (Optional)
is_admin: Collected from Query and must be bool. If it is not input, it is treated as false.
"""
@app.route("/update/<int:id>", methods=["POST"])
@Validator()
def hello(
id=Route(int),
username=Json(str, rules=MinLen(5)),
age=Json(int, rules=[Min(18), Max(99)]),
nicknames=Json(List(str)),
birthday=Json(str, rules=IsoDatetime()),
expire=Json(int, optional=True),
is_admin=Query(bool, default=False)
):
return "Update Complete! %s" % locals()
if __name__ == "__main__":
app.run(debug=True)
Simple Usage
- Register the Validator() decorator for the flask route function you want to apply.
- For each argument, declare and register the Param object in which area to search and verify the value.
parameter_name = Param(parameter_type, default, rules, optional)
# parameter_name : the name of the parameter
# Param: In which area to search for parameters (Header, Route(URI), Query, Form, Json, File)
# parameter_type: the type of the parameter (single or multiple list)
# default: Set default value when no value is provided
# rules: Additional validation logic for that parameter (single or multiple list)
# optional: Set whether the corresponding parameter is required (True or False)
'''
The usage may be slightly different depending on which Param is used.
Please refer to the Documentation below for details.
'''
- For each parameter, proceed as follows.
- Check if a parameter with that name exists in the specified area.
- If the parameter does not exist, check the default value and optional.
- Verifies that the corresponding parameter matches the specified parameter type.
- Check whether all relevant parameters for the entered rule are satisfied.
- The corresponding parameter is returned as an argument at the start of the route function.
Documentation
-
When collecting input parameters, click here to see which areas support collection.
-
Click here to check which types are supported when validating parameter types.
-
When verifying parameters, click here to check which rules are supported by default and how to register custom rules.
-
If validation fails, click here to define a custom error function.
Click here for more advanced features.
References
Metadata
Release files for flask-validation-extended 0.2.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-validation-extended-0.2.1.tar.gz | 11.5 kB | Without provenance | Details for flask-validation-extended-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_validation_extended-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for flask_validation_extended-0.2.1-py3-none-any.whl |
Total release size: 22.4 kB
Release files / flask-validation-extended-0.2.1.tar.gz
| Download URL | flask-validation-extended-0.2.1.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c37731c25e44f55928e96cb0f4e83cdc603bbe1345de7681c175372f46df626
|
|
BLAKE2b-256 checksum How to use checksums |
7afe88c90df7da6d6cb5696ef9bbe65e9907607272e7545ab77bfb2bff174a10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.12
|
Release files / flask_validation_extended-0.2.1-py3-none-any.whl
| Download URL | flask_validation_extended-0.2.1-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
35bd16f4a2b7f4d63cac061e970f9a8864ba6de695c145acdedbaa3329da67d6
|
|
BLAKE2b-256 checksum How to use checksums |
8e9626ed7870c70dc9d7c8c6ed0cd7c50f071845a2cf1165a492dfa37c31fc98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.12
|
Security for flask-validation-extended 0.2.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.