Skip to main content

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

Notes

License

MIT

Project details


Download files

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

Source Distribution

django-redis-ratelimit-0.1.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_redis_ratelimit-0.1.1-py2.py3-none-any.whl (6.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-redis-ratelimit-0.1.1.tar.gz.

File metadata

File hashes

Hashes for django-redis-ratelimit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3a7084a4898b9d3c411521173652d09a8299723c05aebd3e6c464bc94798e041
MD5 27ce17a69da08434861e70faa9ce17cf
BLAKE2b-256 b5ef2c5d7e565874b8d631e24b598d9a7575b9520aa2e604862e544872fcba92

See more details on using hashes here.

File details

Details for the file django_redis_ratelimit-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_redis_ratelimit-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 56a4be337c698250c78fdc216117a67b1c062ca6f79e3b8e386e989e193113a7
MD5 8dd7c3c3033a7c5d950c4583b1ab63dc
BLAKE2b-256 0bc638acdb546ea477ef4fd13192547c403dd176db69671a82b25455f0957819

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page