Py-redis-ratelimit


NamePy-redis-ratelimit JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/AYMENJD/py-redis-ratelimit
SummaryA simple asyncio-based rate limiter for Python3 using Redis.
upload_time2022-12-06 16:06:51
maintainer
docs_urlNone
authorAYMEN Mohammed
requires_python>=3.7
licenseMIT
keywords ratelimit redis flood spam asyncio
VCS
bugtrack_url
requirements redis
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # py-redis-ratelimit [![version](https://img.shields.io/pypi/v/py-redis-ratelimit?style=flat&logo=pypi)](https://pypi.org/project/py-redis-ratelimit) [![downloads](https://img.shields.io/pypi/dm/py-redis-ratelimit?style=flat)](https://pypistats.org/packages/py-redis-ratelimit)

 A simple asynchronous rate limiter based on redis.

### Requirements

- python >= 3.7
- [redis-py](https://github.com/redis/redis-py) >= 4.2.0

### Installation

```bash
pip install py-redis-ratelimit
```

### Examples
Basic example:
```python

from redis.asyncio import Redis
import ratelimit, asyncio

redis = Redis(decode_responses=True)
limiter = ratelimit.RateLimit(
    redis, prefix="api_rate_limit", rate=10, period=60, retry_after=20
)
print(ratelimit.RateLimit.__doc__)  # print RateLimit class docstring


async def do_something():
    await limiter.acquire(
        identifier="do_something_function"
    )  # a unique identifier for the function. This let's RateLimit know what service/resource you are trying to access.
    ...


async def main():
    for x in range(40):
        try:
            print("Calling do_something() for the {}th time".format(x + 1))
            await do_something()
        except ratelimit.FloodWait as e:
            print("Exception:", e.to_dict())
            break


if __name__ == "__main__":
    asyncio.run(main())

```

# Contributing
Pull requests are always welcome!!
# License

MIT [License](https://github.com/AYMENJD/py-redis-ratelimit/blob/main/LICENSE)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AYMENJD/py-redis-ratelimit",
    "name": "Py-redis-ratelimit",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "ratelimit,redis,flood,spam,asyncio",
    "author": "AYMEN Mohammed",
    "author_email": "let.me.code.safe@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a3/23/1351cb5bf0f1c0298fb49ffc524de8f9aec19d079b26fa42e62a9778521a/Py-redis-ratelimit-0.1.4.tar.gz",
    "platform": null,
    "description": "# py-redis-ratelimit [![version](https://img.shields.io/pypi/v/py-redis-ratelimit?style=flat&logo=pypi)](https://pypi.org/project/py-redis-ratelimit) [![downloads](https://img.shields.io/pypi/dm/py-redis-ratelimit?style=flat)](https://pypistats.org/packages/py-redis-ratelimit)\n\n A simple asynchronous rate limiter based on redis.\n\n### Requirements\n\n- python >= 3.7\n- [redis-py](https://github.com/redis/redis-py) >= 4.2.0\n\n### Installation\n\n```bash\npip install py-redis-ratelimit\n```\n\n### Examples\nBasic example:\n```python\n\nfrom redis.asyncio import Redis\nimport ratelimit, asyncio\n\nredis = Redis(decode_responses=True)\nlimiter = ratelimit.RateLimit(\n    redis, prefix=\"api_rate_limit\", rate=10, period=60, retry_after=20\n)\nprint(ratelimit.RateLimit.__doc__)  # print RateLimit class docstring\n\n\nasync def do_something():\n    await limiter.acquire(\n        identifier=\"do_something_function\"\n    )  # a unique identifier for the function. This let's RateLimit know what service/resource you are trying to access.\n    ...\n\n\nasync def main():\n    for x in range(40):\n        try:\n            print(\"Calling do_something() for the {}th time\".format(x + 1))\n            await do_something()\n        except ratelimit.FloodWait as e:\n            print(\"Exception:\", e.to_dict())\n            break\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n\n```\n\n# Contributing\nPull requests are always welcome!!\n# License\n\nMIT [License](https://github.com/AYMENJD/py-redis-ratelimit/blob/main/LICENSE)\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple asyncio-based rate limiter for Python3 using Redis.",
    "version": "0.1.4",
    "split_keywords": [
        "ratelimit",
        "redis",
        "flood",
        "spam",
        "asyncio"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "92100d24147d22729b583d06bffad1c8",
                "sha256": "b2be224f0842aeec12f2884f28ea643a3492868734ddbee9f3f457848d412be7"
            },
            "downloads": -1,
            "filename": "Py-redis-ratelimit-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "92100d24147d22729b583d06bffad1c8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4263,
            "upload_time": "2022-12-06T16:06:51",
            "upload_time_iso_8601": "2022-12-06T16:06:51.520301Z",
            "url": "https://files.pythonhosted.org/packages/a3/23/1351cb5bf0f1c0298fb49ffc524de8f9aec19d079b26fa42e62a9778521a/Py-redis-ratelimit-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-06 16:06:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "AYMENJD",
    "github_project": "py-redis-ratelimit",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "redis",
            "specs": [
                [
                    ">=",
                    "4.2.0"
                ]
            ]
        }
    ],
    "lcname": "py-redis-ratelimit"
}
        
Elapsed time: 0.10954s