A fixed window rate limiter based on Redis
$ pip install redis-ratelimit
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.
MIT