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
Hashes for django-throttle-requests-0.5.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3981b355be9a45d881e2f88f35b34e24b7da41554d8ff5b119f021dcbbfd2965 |
|
MD5 | 0f0dc6b75c401e5d4b26cad0a6c82322 |
|
BLAKE2b-256 | cd0a7ab449245b89b8d48e6c8eceb9ae3e3d15509d15351fa334c677f0a6e3bb |