A Django framework for application-layer rate limiting
Project description
a framework for implementing application-specific rate-limiting middleware for Django projects
What this module is intended for:
Implementing application-level (or just below) 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
What it is not intended for:
A token bucket or leaky bucket filter: intended primarily for traffic shaping, those algorithms are implemented by firewalls and servers such as nginx.
Installation
Install the library with pip:
sudo pip install django-throttle-requests
Add the directory throttle to your project’s PYTHONPATH.
Insert the following configuration into your project’s settings:
THROTTLE_ZONES = { 'default': { 'VARY':'throttle.zones.RemoteIP', 'NUM_BUCKETS':2, # Number of buckets worth of history to keep. Must be at least 2 'BUCKET_INTERVAL':15 * 60 # Period of time to enforce limits. 'BUCKET_CAPACITY':50, # Maximum number of requests allowed within BUCKET_INTERVAL }, } # Where to store request counts. THROTTLE_BACKEND = 'throttle.backends.cache.CacheBackend' # Force throttling when DEBUG=True THROTTLE_ENABLED = True
Use the @throttle decorator to enforce throttling rules on a view:
from throttle.decorators import throttle @throttle(zone='default') def myview(request): ...
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
File details
Details for the file django-throttle-requests-0.5.2.tar.gz
.
File metadata
- Download URL: django-throttle-requests-0.5.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dea1bc6b8663e10171b9d45f3ef5f9c8f2f96d6cabfb9806fdba775a1b33fc4e |
|
MD5 | 3ea96bc649235fb0930ef2b32248a056 |
|
BLAKE2b-256 | 82169e9c68c1ceaceef05f7656557f42f81f2d295ed5e62a75735abeb77a267d |
File details
Details for the file django_throttle_requests-0.5.2-py2.py3-none-any.whl
.
File metadata
- Download URL: django_throttle_requests-0.5.2-py2.py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82be9149c56f21c14185c112c7fe3e4f431090b684410eca93a5a4ff30b2abaf |
|
MD5 | eea664b2f55abcc0cb5f64691d054785 |
|
BLAKE2b-256 | 28ab8296f80c55fe1edf396f9b6fd6e890b054d334f91e62a325214735a16d23 |