django-throttle-requests
a framework for implementing rate-limiting middleware for Django projects
Overview
This package allows Django developers to define application-level rate-limiting rules. Often, these rules would be expressed as “max # requests within a defined time period”. E.g.:
an IP address may make at most 1500 requests/day
users with an OAuth access token may make 500 reads/hour and 200 writes/hour
You can also define leaky bucket-style rules:
Allow 10 requests per minute, then every 6 seconds thereafter.
Features
Attach rules to specific views using a decorator
Supports multiple throttle configurations
Use Django’s cache layer as the storage backend, or use Redis scripting for production-ready atomic operations
Define request attributes to rate limit (e.g. remote IP address, username, HTTP header value, device fingerprint, etc.)
Application-level rate limiting rules using fixed-bucket or generic cell rate algorithm (leaky bucket)
Installation
Install the library with pip:
sudo pip install django-throttle-requests
Add the directory throttle to your project’s PYTHONPATH.
Usage
Insert the following configuration into your project’s settings:
THROTTLE_ZONES = { 'default': { 'VARY':'throttle.zones.RemoteIP', 'ALGORITHM': 'fixed-bucket', # Default if not defined. 'BUCKET_INTERVAL':15 * 60, # Number of seconds to enforce limit. 'BUCKET_CAPACITY':50, # Maximum number of requests allowed within BUCKET_INTERVAL }, } # Where to store request counts. THROTTLE_BACKEND = 'throttle.backends.cache.CacheBackend' # Optional if Redis backend is chosen ('throttle.backends.redispy.RedisBackend') THROTTLE_REDIS_HOST = 'localhost' THROTTLE_REDIS_PORT = 6379 THROTTLE_REDIS_DB = 0 THROTTLE_REDIS_AUTH = 'pass' # Normally, throttling is disabled when DEBUG=True. Use this to force it to enabled. THROTTLE_ENABLED = TrueUse the @throttle decorator to enforce throttling rules on a view:
from throttle.decorators import throttle @throttle(zone='default') def myview(request): ...
Also works with class-based views:
from django.views.generic import View from django.utils.decorators import method_decorator from throttle.decorators import throttle class TestView(View): @method_decorator(throttle(zone='default')) def dispatch(self, *args, **kwargs): return super(TestView, self).dispatch(*args, **kwargs) def head(self, request): ... def get(self, request): ...
Development
Run unit tests:
uv run runtests.py
Run linter:
uvx ruff@latest check
Metadata
Release files for django-throttle-requests 0.8.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 | |
|---|---|---|---|---|
| django_throttle_requests-0.8.1.tar.gz | 8.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_throttle_requests-0.8.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.0 kB
Release files / django_throttle_requests-0.8.1.tar.gz
| Download URL | django_throttle_requests-0.8.1.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf741cc008a6eb6c872c984ab33eac680320fa31fb89f6995afe65c383e1ae9b
|
|
BLAKE2b-256 checksum How to use checksums |
d04b58c7c4c3b37f713cb7f1e357d2d82be2b4d6de08b01ec319d3faff22dd73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / django_throttle_requests-0.8.1-py3-none-any.whl
| Download URL | django_throttle_requests-0.8.1-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
65c9b150f0fbd001ec67b219bd913f7fe0bb78663b301989efd5b292e08176ae
|
|
BLAKE2b-256 checksum How to use checksums |
4b363fd95a0f864245fd88eaea98170c030528b9b15cee6b3ba9351a1af7a989
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for django-throttle-requests 0.8.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.