# Django Ratelimit

## Project

Django Ratelimit is a ratelimiting decorator for Django views, storing rate data in the configured Django cache backend.

Code:

  https://github.com/jsocol/django-ratelimit

License:

  Apache Software License

Issues:

  https://github.com/jsocol/django-ratelimit/issues

Documentation:

  http://django-ratelimit.readthedocs.org/

## Quickstart

Warning

django_ratelimit requires a Django cache backend that supports atomic increment operations. The Memcached and Redis backends do, but the database backend does not. More information can be found in Installation

Install:

    pip install django-ratelimit

Use as a decorator in `views.py`:

    from django_ratelimit.decorators import ratelimit

    @ratelimit(key='ip')
    def myview(request):
        # ...

    @ratelimit(key='ip', rate='100/h')
    def secondview(request):
        # ...

Before activating django-ratelimit, you should ensure that your cache backend is setup to be both persistent and work across multiple deployment worker instances (for instance UWSGI workers). Read more in the Django docs on caching.

## Contents

- Installation
  - Create or use a compatible cache
  - Configuration
  - Enforcing Ratelimits
- Settings
  - `RATELIMIT_CACHE_PREFIX`
  - `RATELIMIT_HASH_ALGORITHM`
  - `RATELIMIT_ENABLE`
  - `RATELIMIT_USE_CACHE`
  - `RATELIMIT_VIEW`
  - `RATELIMIT_FAIL_OPEN`
  - `RATELIMIT_IP_META_KEY`
  - `RATELIMIT_IPV4_MASK`
  - `RATELIMIT_IPV6_MASK`
  - `RATELIMIT_EXCEPTION_CLASS`
- Using Django Ratelimit
  - Use as a decorator
  - Core Methods
  - Exceptions
  - Middleware
- Ratelimit Keys
  - Common keys
  - String values
  - Callable values
- Rates
  - Simple rates
  - Callables
- Security considerations
  - Client IP address
  - Brute force attacks
  - User-supplied Data
- Upgrade Notes
  - From 3.x to 4.0
  - From 2.0 to 3.0
  - From <=0.4 to 0.5
- Contributing
  - Set Up
  - Running the Tests
  - Code Standards
- Cookbook
  - Recipes

## Indices and tables

- Index

- Module Index

- Search Page