Skip to main content

Django Request Normalizer

A configurable Django middleware that automatically cleans and normalizes incoming request data before it reaches your views.

Features

  • Trims Whitespace: Strips leading/trailing whitespace from all string values.
  • Normalizes Booleans: Converts string values like "true" and "false" to actual booleans.
  • Normalizes Nulls: Converts string "null", empty strings "" for ID fields, and integer 0 for ID fields to None.
  • Cleans Email: Removes spaces and lowercases email fields.
  • Handles All Data: Works seamlessly with GET parameters, application/json, multipart/form-data, and x-www-form-urlencoded data.
  • Configurable: You can enable/disable the middleware or specify which URL prefixes it should act on.

Installation

pip install django-request-normalizer

Usage

Add the middleware to your MIDDLEWARE list in settings.py. It should be placed before any middleware that accesses request data, such as DRF's authentication classes or your own views.

# settings.py
MIDDLEWARE = [
    # ...
    'request_normalizer.middleware.RequestNormalizerMiddleware',
    # ...
]

⚙️ Configuration

To enable normalization, you must specify a list of URL prefixes for which it will be applied. This is done in your settings.py.

# settings.py

# A list of URL prefixes for which normalization will be active.
API_PREFIXES = ['/api/v1/', '/api/v2/']

🧮 Normalization Rules

Input Value Key Output Value Explanation
"null" any None The string "null" becomes None
"true" any True The string "true" becomes True
"false" any False The string "false" becomes False
0 (integer) user_id None 0 for _id or id fields becomes None
"0" (string) id None The string "0" for _id or id fields becomes None
"" (empty string) category_id None An empty string for _id or id fields becomes None
" test%20string " name "test string" Whitespace is trimmed and characters are decoded
" User@Example.com " email "user@example.com" Whitespace is removed and the string is lowercased

📜 License

This project is licensed under the MIT License.

Metadata

Release files for bear-django-request-normalizer 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bear-django-request-normalizer 0.3.1
File Size Uploaded Provenance Actions
bear_django_request_normalizer-0.3.1.tar.gz 2.7 kB Without provenance Details for bear_django_request_normalizer-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bear-django-request-normalizer 0.3.1
File Interpreter ABI Platform Actions
bear_django_request_normalizer-0.3.1-py3-none-any.whl Python 3 none any Details for bear_django_request_normalizer-0.3.1-py3-none-any.whl

Total release size: 5.8 kB

Release files / bear_django_request_normalizer-0.3.1.tar.gz

Download URL bear_django_request_normalizer-0.3.1.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
82be4ac8c3182c09b58e850a4655971954a16193e6fd879291ceb7426c7fb1dc
BLAKE2b-256 checksum
How to use checksums
0d8b0dc33c850655064077ddef816623b634c3bf1e121618d15dc25b7f2943c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / bear_django_request_normalizer-0.3.1-py3-none-any.whl

Download URL bear_django_request_normalizer-0.3.1-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef300b82cadb1f14d3674fd6d41d5637431f69d1c5a05c5db94bab54b122ae07
BLAKE2b-256 checksum
How to use checksums
0d33d35fe47ad72babec75726add59b487631b732fac5a3c13a6fba5044f02d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Security for bear-django-request-normalizer 0.3.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page