Skip to main content

A fixed window rate limiting based on Redis

Project description

# django-redis-ratelimit

[![Build Status](https://travis-ci.org/r00m/django-redis-ratelimit.svg?branch=master)](https://travis-ci.org/r00m/django-redis-ratelimit)

A fixed window rate limiting based on Redis

---

## Installation

To install django-redis-ratelimit, simply:

```console
$ pip install django-redis-ratelimit
```

**NB!** django-redis-ratelimit requires a running Redis server. See [Redis's quickstart](http://redis.io/topics/quickstart)
for installation instructions.

## Getting started

First, add the middleware to your `settings.py`:

```django
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:

```django
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

- [Redis Rate Limiting Pattern #2](https://redis.io/commands/INCR#pattern-rate-limiter-2)

## 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.0.tar.gz (3.3 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.0-py2.py3-none-any.whl (5.9 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for django-redis-ratelimit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b2dec9aa0a0ae6077f34089db3c6914875349e162f195c9bb17460d151b00ee5
MD5 5fc19893683c7d707bb6db211dfb2803
BLAKE2b-256 82f1f57bd1f3e82eacee2ccaba1fe4d324e67ecbf439d0f8b390c46395289b18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_redis_ratelimit-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 aa2a4e584a36c78c5350b1eb1980ecb470b2923af21b54f56bc23739218935ae
MD5 85e489814ae20f8d3b064e00f1753a15
BLAKE2b-256 7d0e5235f380298dbe74f6a9da1054617f24d94fe7800855d557e9cac502e9a9

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