Skip to main content
Help us improve Python packaging – donate today!

A fixed window rate limiting based on Redis

Project Description

Build Status

A fixed window rate limiting based on Redis


Requirements

  • Python >= 3.6
  • Django >= 1.11
  • Redis

Installation

To install django-redis-ratelimit, simply:

$ pip install django-redis-ratelimit

NB! django-redis-ratelimit requires a running Redis server. See Redis’s quickstart for installation instructions.

Getting started

First, add the middleware to your settings.py:

MIDDLEWARE = [
    # ...

    'redis_ratelimit.middleware.RateLimitMiddleware',
]

this will make sure that end user sees the HTTP 429 response.

Next, apply the ratelimit decorator to the view:

from django.http import HttpResponse
from redis_ratelimit import ratelimit

@ratelimit(rate='5/m')
def index(request):
    return HttpResponse("Hello World!")

Memory requirements

For this example we will assume that each key takes up roughly 250 bytes and each value is 4 bytes:

250 + 4 * 1 million unique hits = ~254 Megabytes

License

MIT

Release history Release notifications

This version
History Node

0.1.1

History Node

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django_redis_ratelimit-0.1.1-py2.py3-none-any.whl (6.1 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Nov 1, 2017
django-redis-ratelimit-0.1.1.tar.gz (3.6 kB) Copy SHA256 hash SHA256 Source None Nov 1, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page