Database query budget enforcement for Django
Project description
Django Query Budget
Database query budget enforcement for Django.
Define budgets on cumulative query runtime, query count, and per-query duration within rolling time windows. When a budget is exceeded, pluggable actions respond — log, reject, or custom.
Features
- Budget enforcement via settings, decorators, or context managers
- Built-in
LOGandREJECTactions with custom action support - Async-safe hook system for observability
- SQL fingerprinting for query normalization
- Optional cluster-wide sync via Redis or database backends
- Works with Django 5.0+ (WSGI and ASGI)
Installation
Install from PyPI:
pip install django-query-budget
For Redis-based cluster sync:
pip install django-query-budget[redis]
Quick start
# settings.py
INSTALLED_APPS = ["django_query_budget", ...]
MIDDLEWARE = ["django_query_budget.middleware.QueryBudgetMiddleware", ...]
QUERY_BUDGET = {
"default": {
"total_runtime": "30m",
"window": "5m",
"action": "LOG",
},
}
# views.py
from django_query_budget import query_budget
@query_budget(total_runtime="10s", window="1m", action="REJECT")
def expensive_report(request):
...
Documentation
Full documentation at django-query-budget.readthedocs.io.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_query_budget-0.1.1.tar.gz.
File metadata
- Download URL: django_query_budget-0.1.1.tar.gz
- Upload date:
- Size: 23.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b774595bf8108c1a63bdb67aad475d3916ceb94eea2b0698858456f08896b4ba
|
|
| MD5 |
630b786a6042554d461139628687fd1d
|
|
| BLAKE2b-256 |
314b20ee5536a1ed4522722250383acb1f8dce8f8cb887d9048e623c11f0a0d2
|
File details
Details for the file django_query_budget-0.1.1-py3-none-any.whl.
File metadata
- Download URL: django_query_budget-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1d23abc346a10054a050172d357fda5127a681258859fe8e6384baa571a6138
|
|
| MD5 |
417fd3a7ff74b444365918dba672be4b
|
|
| BLAKE2b-256 |
f6f0689c0b5abaf3508aa66e9eb0fed30dc0c5dbc2d05ceb52a4ffcd01b3e3f9
|