Skip to content

romantomjak/redis-ratelimit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redis-ratelimit

Travis Coveralls PyPI PyPI - Python Version

A fixed window rate limiter based on Redis


Installation

$ pip install redis-ratelimit

Example Usage

The library itself is framework agnostic, but let's assume you want to use it with Flask:

from flask import Flask, jsonify
from redis_ratelimit import ratelimit

app = Flask(__name__)

@app.route('/')
@ratelimit(rate='10/m', key='ccc')
@ratelimit(rate='2/s', key='ccc')
def index():
    return jsonify({'status': 'OK'})

This will allow a total of 10 requests in any given minute, but no faster than 2 requests a second.

Notes

License

MIT