flask-gatekeeper


Nameflask-gatekeeper JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/k0rventen/flask-gatekeeper
SummaryA (very) simple banning & rate limiting extension for Flask.
upload_time2021-05-04 21:11:19
maintainer
docs_urlNone
authork0rventen
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # flask-gatekeeper

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

It's not meant to be a replacement 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` and minimal storage of information regarding the clients.

## Install

```
pip install flask-gatekeeper
```

## Usage

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

```py
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=app, # link to our app now or use .init_app() later.
                ban_rule=[3,60,600], # will ban for 600s if an IP is reported using `report()` 3 times in a 60s window.
                rate_limit_rule=[100,60] # will rate limit if an IP makes more than 100 request in a 60s window.
                ) 


@app.route("/ping") # this route is rate limited by the global rule
def ping():
    return "ok",200

@app.route("/login") # also rate limited by the global rule
def login():
    if password_is_ok():
        return token,200
    else:
        gk.report() # report that IP
        return "bad password",401

@app.route("/specific")
@gk.specific(rate_limit_rule=[1,10]) # add another rate limit on top of the global one
def specific():
    return "ok",200

@app.route("/specific")
@gk.specific(rate_limit_rule=[1,10],standalone=True) # rate limited only by this rule
def specific():
    return "ok",200


@app.route("/bypass")
@gk.bypass # do not apply anything on that route
def bypass():
    return "ok",200


app.run("127.0.0.1",5000)
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/k0rventen/flask-gatekeeper",
    "name": "flask-gatekeeper",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "k0rventen",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/1f/06/e03cc1cf9d7984009cce334f6900470a0cc7c8f976c197a84083c2b86039/flask_gatekeeper-0.3.0.tar.gz",
    "platform": "",
    "description": "# flask-gatekeeper\n\nA (very) simple banning & rate limiting extension for Flask.\n\nIt's not meant to be a replacement for other, more complex banning & rate limiting modules like `flask-Limiter` or `flask-ipban`.\n\nIt's simple, does not require any dependancies, and quite fast due to the use of `collections.deque` and minimal storage of information regarding the clients.\n\n## Install\n\n```\npip install flask-gatekeeper\n```\n\n## Usage\n\nHere is a demo app showing all the capabilities of flask-gatekeeper : \n\n```py\nfrom flask import Flask\nfrom flask_gatekeeper import GateKeeper # important\n\n# create our flask app \napp = Flask(__name__)\n\n# add our GateKeeper instance with global rules\ngk = GateKeeper(app=app, # link to our app now or use .init_app() later.\n                ban_rule=[3,60,600], # will ban for 600s if an IP is reported using `report()` 3 times in a 60s window.\n                rate_limit_rule=[100,60] # will rate limit if an IP makes more than 100 request in a 60s window.\n                ) \n\n\n@app.route(\"/ping\") # this route is rate limited by the global rule\ndef ping():\n    return \"ok\",200\n\n@app.route(\"/login\") # also rate limited by the global rule\ndef login():\n    if password_is_ok():\n        return token,200\n    else:\n        gk.report() # report that IP\n        return \"bad password\",401\n\n@app.route(\"/specific\")\n@gk.specific(rate_limit_rule=[1,10]) # add another rate limit on top of the global one\ndef specific():\n    return \"ok\",200\n\n@app.route(\"/specific\")\n@gk.specific(rate_limit_rule=[1,10],standalone=True) # rate limited only by this rule\ndef specific():\n    return \"ok\",200\n\n\n@app.route(\"/bypass\")\n@gk.bypass # do not apply anything on that route\ndef bypass():\n    return \"ok\",200\n\n\napp.run(\"127.0.0.1\",5000)\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A (very) simple banning & rate limiting extension for Flask.",
    "version": "0.3.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "36e1197b5c267f8bd8d5fb562233c6f0",
                "sha256": "0270a36454ea488f803ab39c0ac27aafc2e7f042771a881e4dc9c26f96310911"
            },
            "downloads": -1,
            "filename": "flask_gatekeeper-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "36e1197b5c267f8bd8d5fb562233c6f0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7040,
            "upload_time": "2021-05-04T21:11:18",
            "upload_time_iso_8601": "2021-05-04T21:11:18.013383Z",
            "url": "https://files.pythonhosted.org/packages/a3/34/c4f043bea3c1f241eaa85f11de525aa9675c23cfae766d185df844807c4f/flask_gatekeeper-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "695eab514293f5074742792dea023157",
                "sha256": "5eee78d122f0049ad932c2b977e27e5f25a5b569f55098b9e5da48eb9dfd3042"
            },
            "downloads": -1,
            "filename": "flask_gatekeeper-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "695eab514293f5074742792dea023157",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5497,
            "upload_time": "2021-05-04T21:11:19",
            "upload_time_iso_8601": "2021-05-04T21:11:19.994887Z",
            "url": "https://files.pythonhosted.org/packages/1f/06/e03cc1cf9d7984009cce334f6900470a0cc7c8f976c197a84083c2b86039/flask_gatekeeper-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-05-04 21:11:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "k0rventen",
    "error": "Could not fetch GitHub repository",
    "lcname": "flask-gatekeeper"
}
        
Elapsed time: 0.23526s