FlaskFloodgate


NameFlaskFloodgate JSON
Version 1.1 PyPI version JSON
download
home_pageNone
SummaryA small customizable package to rate-limit your Flask endpoints.
upload_time2024-04-05 17:35:55
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords flask rate-limit floodgate
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Introduction

Flask-IP-Floodgate is a small Python package that provides rate limiting functionalities for Flask endpoints.

# Current Features
- Rate limit IPs.
- Restrict a certain amount of requests in a specified time window.
- Add a limit to the number of times an IP can be rate-limited (blocked).
- Punish IPs for exceeding block limit by either black-listing them or blocking them for an extended duration.
- Set the block duration based on either the first or the last blocked request.
- Set a max duration to the time a request window will be stored in the DB.
- Allow IPs to accumulate requests from past request windows.
- Allow requests with certain data.
- Blacklist and whitelist IPs during runtime.

# TODO
- **Multiple DB**: Implement availability for other DBs.
- **Request Cooldown**: A cooldown after each request.
- **Improved logging**: As of now, only INFO logs are made.
- **Adaptive blocking**: Increase the window/block duration based on the severity level.

# Installation

`pip install FlaskFloodgate`

# Usage
```python

import logging

from datetime import timedelta
from flask import Flask

from FlaskFloodgate import RateLimiter
from FlaskFloodgate.handlers import Sqlite3Handler

app = Flask(__name__)

# No need to specify all the parameters.
handler = RateLimiter(
    db=MemoryHandler(),
    amount=20, # All parameters below this are optional.
    time_window=timedelta(minutes=1)
    block_limit=5,
    block_exceed_duration=timedelta(days=1),
    relative_block=True,
    block_exceed_reset=True,
    max_window_duration=timedelta(days=2),
    accumulate_requests=True,
    dl_data_wb=True,
    logger=logging.Logger("FlaskFloodgate"),
    export_dir=os.getcwd()
)

handler = RateLimiter(db=db)

@app.route('/rate-limited')
@handler.rate_limited_route()
def rate_limited():
    return 'Hello!', 200

if __name__ == "__main__":
    app.run(host="localhost")

```

# Documentation
For detailed functions, check out the documentation: [FlaskFloodgate Documentation](https://flaskfloodgate.readthedocs.io/en/latest/introduction.html)

# Contact
You can contact me on my email: ivoscev@gmail.com

# Updates
- # 1.1
- Updated with a runtime terminal.
- Moved rate limiting parameters to the `RateLimiter` handler instead of the `DBHandler`.
- Introduced whitelisting of IPs.
- Introduced `RedisHandler`.

- # 1.0.1
- The first version (with updated PyPI README).

- # 1.0
- The first version.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "FlaskFloodgate",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "flask, rate-limit, floodgate",
    "author": null,
    "author_email": "Evscion <ivoscev@example.com>",
    "download_url": "https://files.pythonhosted.org/packages/94/3e/803881c17c8c98f54176a3d3ebd524156b1aec4bd724813994c2ed20e77b/FlaskFloodgate-1.1.tar.gz",
    "platform": null,
    "description": "# Introduction\n\nFlask-IP-Floodgate is a small Python package that provides rate limiting functionalities for Flask endpoints.\n\n# Current Features\n- Rate limit IPs.\n- Restrict a certain amount of requests in a specified time window.\n- Add a limit to the number of times an IP can be rate-limited (blocked).\n- Punish IPs for exceeding block limit by either black-listing them or blocking them for an extended duration.\n- Set the block duration based on either the first or the last blocked request.\n- Set a max duration to the time a request window will be stored in the DB.\n- Allow IPs to accumulate requests from past request windows.\n- Allow requests with certain data.\n- Blacklist and whitelist IPs during runtime.\n\n# TODO\n- **Multiple DB**: Implement availability for other DBs.\n- **Request Cooldown**: A cooldown after each request.\n- **Improved logging**: As of now, only INFO logs are made.\n- **Adaptive blocking**: Increase the window/block duration based on the severity level.\n\n# Installation\n\n`pip install FlaskFloodgate`\n\n# Usage\n```python\n\nimport logging\n\nfrom datetime import timedelta\nfrom flask import Flask\n\nfrom FlaskFloodgate import RateLimiter\nfrom FlaskFloodgate.handlers import Sqlite3Handler\n\napp = Flask(__name__)\n\n# No need to specify all the parameters.\nhandler = RateLimiter(\n    db=MemoryHandler(),\n    amount=20, # All parameters below this are optional.\n    time_window=timedelta(minutes=1)\n    block_limit=5,\n    block_exceed_duration=timedelta(days=1),\n    relative_block=True,\n    block_exceed_reset=True,\n    max_window_duration=timedelta(days=2),\n    accumulate_requests=True,\n    dl_data_wb=True,\n    logger=logging.Logger(\"FlaskFloodgate\"),\n    export_dir=os.getcwd()\n)\n\nhandler = RateLimiter(db=db)\n\n@app.route('/rate-limited')\n@handler.rate_limited_route()\ndef rate_limited():\n    return 'Hello!', 200\n\nif __name__ == \"__main__\":\n    app.run(host=\"localhost\")\n\n```\n\n# Documentation\nFor detailed functions, check out the documentation: [FlaskFloodgate Documentation](https://flaskfloodgate.readthedocs.io/en/latest/introduction.html)\n\n# Contact\nYou can contact me on my email: ivoscev@gmail.com\n\n# Updates\n- # 1.1\n- Updated with a runtime terminal.\n- Moved rate limiting parameters to the `RateLimiter` handler instead of the `DBHandler`.\n- Introduced whitelisting of IPs.\n- Introduced `RedisHandler`.\n\n- # 1.0.1\n- The first version (with updated PyPI README).\n\n- # 1.0\n- The first version.\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A small customizable package to rate-limit your Flask endpoints.",
    "version": "1.1",
    "project_urls": {
        "Homepage": "https://github.com/Evscion/FlaskFloodgate",
        "Issues": "https://github.com/Evscion/FlaskFloodgate/issues"
    },
    "split_keywords": [
        "flask",
        " rate-limit",
        " floodgate"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3121de159eed1af6c4eaffd3a1525d9eacc8fa0e484e54a11926ed345807793a",
                "md5": "ea5b127f47f09b4b183ed6cd85bd783e",
                "sha256": "50724332b1de1df5bba2968342fb2eab5ba571f8208e0aba4554af0cb22eb30c"
            },
            "downloads": -1,
            "filename": "FlaskFloodgate-1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ea5b127f47f09b4b183ed6cd85bd783e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 10197,
            "upload_time": "2024-04-05T17:35:54",
            "upload_time_iso_8601": "2024-04-05T17:35:54.135343Z",
            "url": "https://files.pythonhosted.org/packages/31/21/de159eed1af6c4eaffd3a1525d9eacc8fa0e484e54a11926ed345807793a/FlaskFloodgate-1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "943e803881c17c8c98f54176a3d3ebd524156b1aec4bd724813994c2ed20e77b",
                "md5": "bdbd931124c609549685d0d5928ed28f",
                "sha256": "97cc06058a640bafa8335dec363989378b361de8ab4e7917fd15b2cea10ef071"
            },
            "downloads": -1,
            "filename": "FlaskFloodgate-1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "bdbd931124c609549685d0d5928ed28f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10701,
            "upload_time": "2024-04-05T17:35:55",
            "upload_time_iso_8601": "2024-04-05T17:35:55.903919Z",
            "url": "https://files.pythonhosted.org/packages/94/3e/803881c17c8c98f54176a3d3ebd524156b1aec4bd724813994c2ed20e77b/FlaskFloodgate-1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-05 17:35:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Evscion",
    "github_project": "FlaskFloodgate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "flaskfloodgate"
}
        
Elapsed time: 0.22618s