Rate limiting middleware for Django applications


Quick start

Add the rate limiter to your django projects’ and enable a global rate limit for all views in your project:

MIDDLEWARE_CLASSES += ("djlimiter.Limiter",)
RATELIMIT_GLOBAL = "10/second; 50/hour"

In one of the apps’ view:

def index(request):

def ping(request):

The above example will result in the following characteristics being applied to the django project:

  • A global rate limit of 10 per second, and 50 per hour applied to all routes.
  • The index route will have an explicit rate limit of 5/second
  • The ping route will be exempt from any global rate limits.

Every time a request exceeds the rate limit, the view function will not get called and instead a 429 http error will be raised.

Refer to Recipes for more examples.


0.2 2015-12-20

  • Django 1.8/1.9 compatibility

0.1.1 2015-01-09

  • Bug Fix: remove duplicate hits when rate limits are stacked.
  • Bug Fix: multiple rate limits returned by dynamic limits weren’t respected.
  • Documentation tweaks.

0.1.0 2015-01-09

  • first release.