FlaskFloodgate


NameFlaskFloodgate JSON
Version 1.1.2 PyPI version JSON
download
home_pageNone
SummaryA small customizable package to rate-limit your Flask endpoints.
upload_time2024-08-03 06:42:26
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords flask rate-limit floodgate ip-limit
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Introduction

FlaskFloodgate 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.
- **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,
    time_window=timedelta(minutes=1),
    block_duration=timedelta(minutes=5),
    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.2
- Improved rate-limiting logic.
- Improved `MemoryHandler`.
- Fixed bugs with `RedisHandler`. 

- # 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, ip-limit",
    "author": null,
    "author_email": "Evscion <ivoscev@example.com>",
    "download_url": "https://files.pythonhosted.org/packages/c2/92/566620287d9557561742b06c705ba8c66e78562c202526040cb0aa426f88/flaskfloodgate-1.1.2.tar.gz",
    "platform": null,
    "description": "# Introduction\r\n\r\nFlaskFloodgate is a small Python package that provides rate limiting functionalities for Flask endpoints.\r\n\r\n# Current Features\r\n- Rate limit IPs.\r\n- Restrict a certain amount of requests in a specified time window.\r\n- Add a limit to the number of times an IP can be rate-limited (blocked).\r\n- Punish IPs for exceeding block limit by either black-listing them or blocking them for an extended duration.\r\n- Set the block duration based on either the first or the last blocked request.\r\n- Set a max duration to the time a request window will be stored in the DB.\r\n- Allow IPs to accumulate requests from past request windows.\r\n- Allow requests with certain data.\r\n- Blacklist and whitelist IPs during runtime.\r\n\r\n# TODO\r\n- **Multiple DB**: Implement availability for other DBs.\r\n- **Request Cooldown**: A cooldown after each request.\r\n- **Adaptive blocking**: Increase the window/block duration based on the severity level.\r\n\r\n# Installation\r\n\r\n`pip install FlaskFloodgate`\r\n\r\n# Usage\r\n```python\r\n\r\nimport logging\r\n\r\nfrom datetime import timedelta\r\nfrom flask import Flask\r\n\r\nfrom FlaskFloodgate import RateLimiter\r\nfrom FlaskFloodgate.handlers import Sqlite3Handler\r\n\r\napp = Flask(__name__)\r\n\r\n# No need to specify all the parameters.\r\nhandler = RateLimiter(\r\n    db=MemoryHandler(),\r\n    amount=20,\r\n    time_window=timedelta(minutes=1),\r\n    block_duration=timedelta(minutes=5),\r\n    block_limit=5,\r\n    block_exceed_duration=timedelta(days=1),\r\n    relative_block=True,\r\n    block_exceed_reset=True,\r\n    max_window_duration=timedelta(days=2),\r\n    accumulate_requests=True,\r\n    dl_data_wb=True,\r\n    logger=logging.Logger(\"FlaskFloodgate\"),\r\n    export_dir=os.getcwd()\r\n)\r\n\r\nhandler = RateLimiter(db=db)\r\n\r\n@app.route('/rate-limited')\r\n@handler.rate_limited_route()\r\ndef rate_limited():\r\n    return 'Hello!', 200\r\n\r\nif __name__ == \"__main__\":\r\n    app.run(host=\"localhost\")\r\n\r\n```\r\n\r\n# Documentation\r\nFor detailed functions, check out the documentation: [FlaskFloodgate Documentation](https://flaskfloodgate.readthedocs.io/en/latest/introduction.html)\r\n\r\n# Contact\r\nYou can contact me on my email: ivoscev@gmail.com\r\n\r\n# Updates\r\n- # 1.2\r\n- Improved rate-limiting logic.\r\n- Improved `MemoryHandler`.\r\n- Fixed bugs with `RedisHandler`. \r\n\r\n- # 1.1\r\n- Updated with a runtime terminal.\r\n- Moved rate limiting parameters to the `RateLimiter` handler instead of the `DBHandler`.\r\n- Introduced whitelisting of IPs.\r\n- Introduced `RedisHandler`.\r\n\r\n- # 1.0.1\r\n- The first version (with updated PyPI README).\r\n\r\n- # 1.0\r\n- The first version.\r\n\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A small customizable package to rate-limit your Flask endpoints.",
    "version": "1.1.2",
    "project_urls": {
        "Homepage": "https://github.com/Evscion/FlaskFloodgate",
        "Issues": "https://github.com/Evscion/FlaskFloodgate/issues"
    },
    "split_keywords": [
        "flask",
        " rate-limit",
        " floodgate",
        " ip-limit"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a9f8e0b4e884ca380f5296ae01bc0e17c108376f02ab098aadb142503aa99b87",
                "md5": "77987f69bcea6b0dfcadfe1c479902fc",
                "sha256": "394228bb0392a876e7860b37c8360229fd5d3ac60f875fb8667fd032f1790920"
            },
            "downloads": -1,
            "filename": "FlaskFloodgate-1.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "77987f69bcea6b0dfcadfe1c479902fc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 10748,
            "upload_time": "2024-08-03T06:41:59",
            "upload_time_iso_8601": "2024-08-03T06:41:59.063685Z",
            "url": "https://files.pythonhosted.org/packages/a9/f8/e0b4e884ca380f5296ae01bc0e17c108376f02ab098aadb142503aa99b87/FlaskFloodgate-1.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c292566620287d9557561742b06c705ba8c66e78562c202526040cb0aa426f88",
                "md5": "ca63830b4b0c453b349a004c305bb014",
                "sha256": "7dd0667b21da0b84154297053af5ed8465e5c4545be17a9bdf82b462a36b743a"
            },
            "downloads": -1,
            "filename": "flaskfloodgate-1.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "ca63830b4b0c453b349a004c305bb014",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 11218,
            "upload_time": "2024-08-03T06:42:26",
            "upload_time_iso_8601": "2024-08-03T06:42:26.036952Z",
            "url": "https://files.pythonhosted.org/packages/c2/92/566620287d9557561742b06c705ba8c66e78562c202526040cb0aa426f88/flaskfloodgate-1.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-03 06:42:26",
    "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.49308s