Skip to main content

A (very) simple banning & rate limiting extension for Flask.

Project description

flask-gatekeeper

A (very) simple banning & rate limiting extension for Flask.

It's not meant to be a remplacement for other, more complex banning & rate limiting modules like flask-Limiter or flask-ipban.

It's simple, does not require any dependancies, and quite fast due to the use of collections.deque.

Install

pip install flask-gatekeeper

Usage

Here is a demo app showing all the capabilities of flask-gatekeeper :

from flask import Flask
from flask_gatekeeper import GateKeeper # important

# create our flask app 
app = Flask(__name__)

# add our GateKeeper instance with global rules
gk = GateKeeper(app,ban_rule=[3,60,600],rate_limit_rule=[100,60])

@app.route("/ping") # This route is rate limited
def ping():
    return "ok",200

@app.route("/login")
def login():
    if password_is_ok():
        return token,200
    else:
        gk.report() # ban if an IP is "reported" 3 times in less than 60s
        return "bad password",401

@app.route("/specific")
@gk.specific(rate_limit_rule=[1,10]) # add a route specific, tighter rate limit
def specific():
    return "ok",200



 app.run("127.0.0.1",5001)

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

flask_gatekeeper-0.1.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

flask_gatekeeper-0.1-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

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