Flask Extension: Request Data Normalizer (RDN)
Streamline and supercharge your query string parameter parsing in Flask! This Flask extension provides support for parsing complex Python objects from base64 encoded query parameters, and makes passed query parameterss of any encoding available via Flask's Request.get_json().
Installation
pip install Flask-RDN
Quick Start
from flask_request_data_normalizer import RequestDataNormalizer
from flask import Flask
app = Flask(__name__)
RequestDataNormalizer(app)
Overview
In Flask, parameters passed in a URL query string (such as test/val in localhost/?test=val) are accessed in Dictionary form via the Request.args or Request.values properties but not the Request.get_json() method.
This extension adds these parsed query parameters to the results of Request.get_json() making the method a one-stop-shop to retrieve any data passed to an endpoint.
Additionally, this extension provides support for parsing base64 encoded query parameters. This allows complex objects to be encoded in query parameters and automatically parsed by Flask!
Base64 Parsing Examples
Normally nested data like lists or maps (e.g. [1,2,3] or {"a": "b"}) can't be sent as a query parameter to a Flask application. But it can if Flask can read base64 encoded data.
For example, a Javascript application could create the following complex query string and base64 encode it:
var obj = {nested: {a: 'a', b: 'b'}, list: [1, {"in": "list"}, true]};
"?data=" + btoa(JSON.stringify(obj));
'?data=eyJuZXN0ZWQiOnsiYSI6ImEiLCJiIjoiYiJ9LCJsaXN0IjpbMSx7ImluIjoibGlzdCJ9LHRydWVdfQ=='
With this extension, Flask will be able to parse this data into a Python object automatically.
Take this sample Flask application with a single endpoint:
from flask_request_data_normalizer import RequestDataNormalizer
from flask import Flask, request
app = Flask(__name__)
RequestDataNormalizer(app)
@app.route('/')
def endpoint():
return str(request.get_json())
app.run(host="0.0.0.0", debug=True)
If we called the above endpoint with our base64 encoded query string we would get the following Python object
{'data': {'nested': {'a': 'a', 'b': 'b'}, 'list': [1, {'in': 'list'}, True]}}
The parsing of base64 query strings is done by the Query String Manager library under the hood. Check it out for more examples of how base64 query strings are parsed!
Contributing
Contributions are welcome! Please not the following when contributing:
-
Unittests must be added under the
tests/directory for the PR to be approved. You can run unittests from the root project directory with the following command:python setup.py test
-
PRs cannot be merged without all unittests passing (they will execute automatically)
-
Merges to
mainwill automatically create a new release on PyPi unless it is from a forked Repo
Metadata
Release files for Flask-RDN 1.0.4
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-RDN-1.0.4.tar.gz | 10.4 kB | Without provenance | Details for Flask-RDN-1.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Flask_RDN-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for Flask_RDN-1.0.4-py3-none-any.whl |
Total release size: 16.7 kB
Release files / Flask-RDN-1.0.4.tar.gz
| Download URL | Flask-RDN-1.0.4.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5eaada9663a8574c86f4a5ba8dbc8d98f0e3cd1720785f78c636040b4edb3126
|
|
BLAKE2b-256 checksum How to use checksums |
e3145a91c3b8842198f24bcd4ec1699441646a72b420a9c7cbb04babbeb87264
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / Flask_RDN-1.0.4-py3-none-any.whl
| Download URL | Flask_RDN-1.0.4-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8f3d2961973440c24dffb583c8c87a90baebc1ad7d814f2427295b313b055bb5
|
|
BLAKE2b-256 checksum How to use checksums |
9462a02034a68c135a471c1f8f76188529a4d6acfe01457c464f4d15edeaf337
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for Flask-RDN 1.0.4
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.