# aioratelimits
Client rate limiter. It enqueues function calls and run them as leaky bucket to
ensure specified rates.
## Implementation
Leaky bucket. We have one queue for requests and `count` number of workers.
Each worker can handle one request per `delay` seconds
## Install
```
pip install aioratelimits
```
## Use
The following code prints not more than 2 lines per second.
```python
import asyncio
from aioratelimits import RateLimiter
async def critical_resource(i: int):
print('request:', i)
async def main():
async with RateLimiter(count=2, delay=1) as limiter:
await asyncio.gather(*(
limiter.run(critical_resource(i))
for i in range(10)
))
asyncio.run(main())
```
Arguments to `RateLimiter`:
- `count` - how many calls can we do in the specified interval
- `delay` - the interval in seconds
Raw data
{
"_id": null,
"home_page": "https://github.com/kupec/aioratelimits",
"name": "aioratelimits",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "",
"keywords": "rates,ratelimit,ratelimiter,leaky,bucket",
"author": "Dmitry Kostromin",
"author_email": "kupec-k@ya.ru",
"download_url": "https://files.pythonhosted.org/packages/ad/57/0df52f6091689ca53e6a93e7e7394504e2077eda137a8b5296ac5028cb4b/aioratelimits-0.2.6.tar.gz",
"platform": null,
"description": "# aioratelimits\n\nClient rate limiter. It enqueues function calls and run them as leaky bucket to\nensure specified rates.\n\n## Implementation\n\nLeaky bucket. We have one queue for requests and `count` number of workers.\nEach worker can handle one request per `delay` seconds\n\n## Install\n\n```\npip install aioratelimits\n```\n\n## Use\n\nThe following code prints not more than 2 lines per second.\n\n```python\nimport asyncio\nfrom aioratelimits import RateLimiter\n\n\nasync def critical_resource(i: int):\n print('request:', i)\n\n\nasync def main():\n async with RateLimiter(count=2, delay=1) as limiter:\n await asyncio.gather(*(\n limiter.run(critical_resource(i))\n for i in range(10)\n ))\n\n\nasyncio.run(main())\n```\n\nArguments to `RateLimiter`:\n- `count` - how many calls can we do in the specified interval\n- `delay` - the interval in seconds \n",
"bugtrack_url": null,
"license": "",
"summary": "",
"version": "0.2.6",
"project_urls": {
"Homepage": "https://github.com/kupec/aioratelimits",
"Repository": "https://github.com/kupec/aioratelimits"
},
"split_keywords": [
"rates",
"ratelimit",
"ratelimiter",
"leaky",
"bucket"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8ec7a7d07045e2863907592019c2f4594210a46c42747ec11337634e4a2274f0",
"md5": "128b1e4f0ccf6ca46314603c6e151437",
"sha256": "b7d77fa7a9b12d2bb34d66c4110507606f768e01b3493845789de82ee471cd37"
},
"downloads": -1,
"filename": "aioratelimits-0.2.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "128b1e4f0ccf6ca46314603c6e151437",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 2019,
"upload_time": "2023-05-23T05:48:07",
"upload_time_iso_8601": "2023-05-23T05:48:07.163492Z",
"url": "https://files.pythonhosted.org/packages/8e/c7/a7d07045e2863907592019c2f4594210a46c42747ec11337634e4a2274f0/aioratelimits-0.2.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ad570df52f6091689ca53e6a93e7e7394504e2077eda137a8b5296ac5028cb4b",
"md5": "2503120344d634ba58dd157766169662",
"sha256": "cd762bb7ec5d424fec848aff4f412d1f8ca7df7068c29955647e8ced7bac9b2d"
},
"downloads": -1,
"filename": "aioratelimits-0.2.6.tar.gz",
"has_sig": false,
"md5_digest": "2503120344d634ba58dd157766169662",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 2065,
"upload_time": "2023-05-23T05:48:08",
"upload_time_iso_8601": "2023-05-23T05:48:08.360696Z",
"url": "https://files.pythonhosted.org/packages/ad/57/0df52f6091689ca53e6a93e7e7394504e2077eda137a8b5296ac5028cb4b/aioratelimits-0.2.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-23 05:48:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kupec",
"github_project": "aioratelimits",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "aioratelimits"
}