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)
Built Distribution
Close
Hashes for flask_gatekeeper-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d759acf68610c2ff742095be55723fbd9c63fe5fab0a05c1e9605f91759c42b |
|
MD5 | 0c4f4b1c555c6160c4a22bde4804b80e |
|
BLAKE2b-256 | 3db2454c52ca2f6428fa2ed846cb172db1b9d801e768867d93adf061133b425c |