# asynciolimiter
A simple yet efficient Python AsyncIO rate limiter.
[![GitHub branch checks state](https://img.shields.io/github/checks-status/bharel/asynciolimiter/master)](https://github.com/bharel/asynciolimiter/actions)
[![PyPI](https://img.shields.io/pypi/v/asynciolimiter)](https://pypi.org/project/asynciolimiter/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/asynciolimiter)](https://pypi.org/project/asynciolimiter/)
[![codecov](https://codecov.io/gh/bharel/asynciolimiter/branch/master/graph/badge.svg?token=BJBL909NH3)](https://codecov.io/gh/bharel/asynciolimiter)
## Installation
`pip install asynciolimiter`
## Sample Usage
```python
# Limit to 10 requests per 5 second (equiv to 2 requests per second)
>>> limiter = asynciolimiter.Limiter(10/5)
>>> async def main():
... await limiter.wait() # Wait for a slot to be available.
... pass # do stuff
>>> limiter = Limiter(1/3)
>>> async def request():
... await limiter.wait()
... print("Request") # Do stuff
...
>>> async def main():
... # Schedule 1 request every 3 seconds.
... await asyncio.gather(*(request() for _ in range(10)))
```
## Available Limiter flavors
- `Limiter`: Limits by requests per second and takes into account CPU heavy
tasks or other delays that can occur while the process is sleeping.
- `LeakyBucketLimiter`: Limits by requests per second according to the
[leaky bucket algorithm](https://en.wikipedia.org/wiki/Leaky_bucket). Has a maximum capacity and an initial burst of
requests.
- `StrictLimiter`: Limits by requests per second, without taking CPU or other
process sleeps into account. There are no bursts and the resulting rate will
always be a less than the set limit.
## Documentation
Full documentation available on [Read the Docs](https://asynciolimiter.readthedocs.io/en/latest/).
## License
Licensed under the MIT License.
## Contribution
See [contributing.md](CONTRIBUTING.md).
Raw data
{
"_id": null,
"home_page": null,
"name": "asynciolimiter",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "asyncio, rate limiter, throttling",
"author": null,
"author_email": "Bar Harel <bzvi7919@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/4f/65/e7ba4fa38a389fcfecff7b05d19a5dfd82324488ab7dbb821f1f6792a5b2/asynciolimiter-1.1.0.post3.tar.gz",
"platform": null,
"description": "# asynciolimiter\nA simple yet efficient Python AsyncIO rate limiter.\n\n[![GitHub branch checks state](https://img.shields.io/github/checks-status/bharel/asynciolimiter/master)](https://github.com/bharel/asynciolimiter/actions)\n[![PyPI](https://img.shields.io/pypi/v/asynciolimiter)](https://pypi.org/project/asynciolimiter/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/asynciolimiter)](https://pypi.org/project/asynciolimiter/)\n[![codecov](https://codecov.io/gh/bharel/asynciolimiter/branch/master/graph/badge.svg?token=BJBL909NH3)](https://codecov.io/gh/bharel/asynciolimiter)\n\n## Installation\n`pip install asynciolimiter`\n\n## Sample Usage\n\n```python\n# Limit to 10 requests per 5 second (equiv to 2 requests per second)\n>>> limiter = asynciolimiter.Limiter(10/5)\n>>> async def main():\n... await limiter.wait() # Wait for a slot to be available.\n... pass # do stuff\n\n>>> limiter = Limiter(1/3)\n>>> async def request():\n... await limiter.wait()\n... print(\"Request\") # Do stuff\n...\n>>> async def main():\n... # Schedule 1 request every 3 seconds.\n... await asyncio.gather(*(request() for _ in range(10)))\n```\n\n## Available Limiter flavors\n\n- `Limiter`: Limits by requests per second and takes into account CPU heavy\n tasks or other delays that can occur while the process is sleeping.\n- `LeakyBucketLimiter`: Limits by requests per second according to the\n [leaky bucket algorithm](https://en.wikipedia.org/wiki/Leaky_bucket). Has a maximum capacity and an initial burst of\n requests.\n- `StrictLimiter`: Limits by requests per second, without taking CPU or other\n process sleeps into account. There are no bursts and the resulting rate will\n always be a less than the set limit.\n\n## Documentation\n\nFull documentation available on [Read the Docs](https://asynciolimiter.readthedocs.io/en/latest/).\n\n## License\n\nLicensed under the MIT License.\n\n## Contribution\nSee [contributing.md](CONTRIBUTING.md).\n",
"bugtrack_url": null,
"license": null,
"summary": "Rate limiter for Async IO",
"version": "1.1.0.post3",
"project_urls": {
"Changelog": "https://github.com/bharel/asynciolimiter/blob/master/changelog.md",
"Documentation": "https://asynciolimiter.readthedocs.io/en/latest/",
"Homepage": "https://github.com/bharel/asynciolimiter",
"Source": "https://github.com/bharel/asynciolimiter"
},
"split_keywords": [
"asyncio",
" rate limiter",
" throttling"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "05f7c2174deba155e53056f4be8222ee757572abcf80910f713d3048ceb3cf79",
"md5": "6b7c377273d3b70d80cf5d6a485f367a",
"sha256": "101b3b8c95f7fa6312f33df96cc773bc7ce46f53f5044b97b832cc1ec9f24688"
},
"downloads": -1,
"filename": "asynciolimiter-1.1.0.post3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6b7c377273d3b70d80cf5d6a485f367a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 8152,
"upload_time": "2024-09-07T20:07:56",
"upload_time_iso_8601": "2024-09-07T20:07:56.393025Z",
"url": "https://files.pythonhosted.org/packages/05/f7/c2174deba155e53056f4be8222ee757572abcf80910f713d3048ceb3cf79/asynciolimiter-1.1.0.post3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4f65e7ba4fa38a389fcfecff7b05d19a5dfd82324488ab7dbb821f1f6792a5b2",
"md5": "96d8dea683307987e8470a69d502e94d",
"sha256": "0ce279695126350b38fdb661f6d5976722bf367557156526b93f27614434977d"
},
"downloads": -1,
"filename": "asynciolimiter-1.1.0.post3.tar.gz",
"has_sig": false,
"md5_digest": "96d8dea683307987e8470a69d502e94d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 8068,
"upload_time": "2024-09-07T20:07:57",
"upload_time_iso_8601": "2024-09-07T20:07:57.676339Z",
"url": "https://files.pythonhosted.org/packages/4f/65/e7ba4fa38a389fcfecff7b05d19a5dfd82324488ab7dbb821f1f6792a5b2/asynciolimiter-1.1.0.post3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-07 20:07:57",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bharel",
"github_project": "asynciolimiter",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "asynciolimiter"
}