Bear Django Request Utils
This is a core utility library for Django, designed to clean and normalize incoming request data (GET, POST, JSON, etc.) before it reaches your business logic. It solves the common problem of client applications (frontend, mobile apps) sending data in a non-unified format.
This package provides the base logic and is intended to be used within your own components, such as middleware.
✨ Key Features
- None Normalization: Converts strings like
"null", empty strings"", and the integer0foridor_idfields into aNonevalue. - Boolean Normalization: Converts string values like
"true"and"false"(case-insensitive) intoTrueandFalse. - String Cleaning: Automatically trims leading/trailing whitespace and decodes URL-encoded characters (like
%20). - Special Email Handling: Removes spaces and lowercases email fields.
- Universal: Works with
GETparameters,application/json,multipart/form-data, andapplication/x-www-form-urlencoded. - Configurable: Allows you to specify which URL prefixes (e.g.,
/api/) the normalization should apply to.
⚙️ Installation
pip install bear-django-request-utils
🧩 Concept and Usage
This package provides a RequestUtils class with a set of static methods. The main method is convert_request_params(request), which accepts a Django request object and modifies it in-place.
The best way to use this is by calling the method from within your own custom middleware.
Example of creating middleware that uses this package
your_project/middleware.py
from bear_request_utils import RequestUtils
class RequestNormalizerMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
# Call the core logic from the package
RequestUtils.convert_request_params(request)
return self.get_response(request)
Add your middleware to settings.py:
MIDDLEWARE = [
# ...
'your_project.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-utils 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 |
|---|---|---|---|---|
| bear_django_request_utils-0.2.1.tar.gz | 4.3 kB | Without provenance | Details for bear_django_request_utils-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bear_django_request_utils-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for bear_django_request_utils-0.2.1-py3-none-any.whl |
Total release size: 8.9 kB
Release files / bear_django_request_utils-0.2.1.tar.gz
| Download URL | bear_django_request_utils-0.2.1.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
63eb3e2e76d89f0890dbf617a49ded4989f5ecbdcbcbfc6c1594669e0c305b34
|
|
BLAKE2b-256 checksum How to use checksums |
3f905c634fa30cfb86dc40e00ba2f3ac226b122c4056b7a77a24da6cb11b86f7
|
| 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_utils-0.2.1-py3-none-any.whl
| Download URL | bear_django_request_utils-0.2.1-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f9811050b17d97fd1fd8e12949ef937a1d938acc52d36e75fdfb432c3de105ed
|
|
BLAKE2b-256 checksum How to use checksums |
a923401677b13f6c46f2b01c237d6ba6560d04016cb518114efe56e69c8fe95d
|
| 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-utils 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.