Skip to main content

Streamline and supercharge your query string parameter parsing in Flask!

Project description

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().

Flask Query String Manager PyPi

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 main will automatically create a new release on PyPi unless it is from a forked Repo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-RDN-1.0.4.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

Flask_RDN-1.0.4-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file Flask-RDN-1.0.4.tar.gz.

File metadata

  • Download URL: Flask-RDN-1.0.4.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for Flask-RDN-1.0.4.tar.gz
Algorithm Hash digest
SHA256 5eaada9663a8574c86f4a5ba8dbc8d98f0e3cd1720785f78c636040b4edb3126
MD5 6f87f923668ec5a68fd9ae697f452954
BLAKE2b-256 e3145a91c3b8842198f24bcd4ec1699441646a72b420a9c7cbb04babbeb87264

See more details on using hashes here.

File details

Details for the file Flask_RDN-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: Flask_RDN-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for Flask_RDN-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8f3d2961973440c24dffb583c8c87a90baebc1ad7d814f2427295b313b055bb5
MD5 fe8189142cab91f8a1b6f5ba9739acd0
BLAKE2b-256 9462a02034a68c135a471c1f8f76188529a4d6acfe01457c464f4d15edeaf337

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page