# Loop rate limiters
[](https://github.com/stephane-caron/loop-rate-limiters/actions)
[](https://stephane-caron.github.io/loop-rate-limiters/)
[](https://coveralls.io/github/stephane-caron/loop-rate-limiters?branch=main)
[](https://anaconda.org/conda-forge/loop-rate-limiters)
[](https://pypi.org/project/loop-rate-limiters/)
Simple loop frequency regulators in Python with an API similar to ``rospy.Rate``:
```python
from loop_rate_limiters import RateLimiter
from time import perf_counter
rate = RateLimiter(frequency=400.0)
while True:
    print(f"Hello from loop at {perf_counter():.3f} s")
    rate.sleep()
```
A similar ``AsyncRateLimiter`` class is available for [asynchronous code](https://github.com/stephane-caron/loop-rate-limiters#asynchronous-io).
## Installation
### From conda-forge
```console
conda install -c conda-forge loop-rate-limiters
```
### From PyPI
```console
pip install loop-rate-limiters
```
## Usage
While the example above is synchronous, this library also provides an ``AsyncRateLimiter`` class for [asyncio](https://docs.python.org/3/library/asyncio.html):
```python
import asyncio
from loop_rate_limiters import AsyncRateLimiter
async def main():
    rate = AsyncRateLimiter(frequency=400.0)
    while True:
        loop_time = asyncio.get_event_loop().time()
        print(f"Hello from loop at {loop_time:.3f} s")
        await rate.sleep()
asyncio.run(main())
```
This can be used when there are several tasks executed in parallel at different frequencies.
## See also
- [ischedule](https://github.com/aleksve/ischedule): single-thread interval scheduler in Python
            
         
        Raw data
        
            {
    "_id": null,
    "home_page": null,
    "name": "loop-rate-limiters",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "St\u00e9phane Caron <stephane.caron@normalesup.org>",
    "keywords": "rate, loop, frequency, regulator, limiter",
    "author": null,
    "author_email": "St\u00e9phane Caron <stephane.caron@normalesup.org>",
    "download_url": "https://files.pythonhosted.org/packages/c7/dc/ebbe468e7a71073879b322968a02e37594343ca2cc4b3ba65baf4db60adb/loop_rate_limiters-1.2.0.tar.gz",
    "platform": null,
    "description": "# Loop rate limiters\n\n[](https://github.com/stephane-caron/loop-rate-limiters/actions)\n[](https://stephane-caron.github.io/loop-rate-limiters/)\n[](https://coveralls.io/github/stephane-caron/loop-rate-limiters?branch=main)\n[](https://anaconda.org/conda-forge/loop-rate-limiters)\n[](https://pypi.org/project/loop-rate-limiters/)\n\nSimple loop frequency regulators in Python with an API similar to ``rospy.Rate``:\n\n```python\nfrom loop_rate_limiters import RateLimiter\nfrom time import perf_counter\n\nrate = RateLimiter(frequency=400.0)\nwhile True:\n    print(f\"Hello from loop at {perf_counter():.3f} s\")\n    rate.sleep()\n```\n\nA similar ``AsyncRateLimiter`` class is available for [asynchronous code](https://github.com/stephane-caron/loop-rate-limiters#asynchronous-io).\n\n## Installation\n\n### From conda-forge\n\n```console\nconda install -c conda-forge loop-rate-limiters\n```\n\n### From PyPI\n\n```console\npip install loop-rate-limiters\n```\n\n## Usage\n\nWhile the example above is synchronous, this library also provides an ``AsyncRateLimiter`` class for [asyncio](https://docs.python.org/3/library/asyncio.html):\n\n```python\nimport asyncio\nfrom loop_rate_limiters import AsyncRateLimiter\n\nasync def main():\n    rate = AsyncRateLimiter(frequency=400.0)\n    while True:\n        loop_time = asyncio.get_event_loop().time()\n        print(f\"Hello from loop at {loop_time:.3f} s\")\n        await rate.sleep()\n\nasyncio.run(main())\n```\n\nThis can be used when there are several tasks executed in parallel at different frequencies.\n\n## See also\n\n- [ischedule](https://github.com/aleksve/ischedule): single-thread interval scheduler in Python\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Loop rate limiters.",
    "version": "1.2.0",
    "project_urls": {
        "Changelog": "https://github.com/stephane-caron/loop-rate-limiters/blob/master/CHANGELOG.md",
        "Homepage": "https://github.com/stephane-caron/loop-rate-limiters",
        "Source": "https://github.com/stephane-caron/loop-rate-limiters",
        "Tracker": "https://github.com/stephane-caron/loop-rate-limiters/issues"
    },
    "split_keywords": [
        "rate",
        " loop",
        " frequency",
        " regulator",
        " limiter"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e26dd56be57340baf2e6f6361386f4c21b8b5e001251c64af954787f8d01ec78",
                "md5": "c3794c21a46106ab0d42d635232b0522",
                "sha256": "482f720f409e05dfca8b7b63df180217afa9a51564def681853cb7370a020b74"
            },
            "downloads": -1,
            "filename": "loop_rate_limiters-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c3794c21a46106ab0d42d635232b0522",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 10917,
            "upload_time": "2025-08-13T12:46:26",
            "upload_time_iso_8601": "2025-08-13T12:46:26.700974Z",
            "url": "https://files.pythonhosted.org/packages/e2/6d/d56be57340baf2e6f6361386f4c21b8b5e001251c64af954787f8d01ec78/loop_rate_limiters-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c7dcebbe468e7a71073879b322968a02e37594343ca2cc4b3ba65baf4db60adb",
                "md5": "7488fb563f4958bc72a9be7210a2ae6f",
                "sha256": "7187ec1f76f282ee7166d85c8e29eb13dd850422577decaf7e6bfc803173b421"
            },
            "downloads": -1,
            "filename": "loop_rate_limiters-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7488fb563f4958bc72a9be7210a2ae6f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 35581,
            "upload_time": "2025-08-13T12:46:29",
            "upload_time_iso_8601": "2025-08-13T12:46:29.235492Z",
            "url": "https://files.pythonhosted.org/packages/c7/dc/ebbe468e7a71073879b322968a02e37594343ca2cc4b3ba65baf4db60adb/loop_rate_limiters-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-13 12:46:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stephane-caron",
    "github_project": "loop-rate-limiters",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "loop-rate-limiters"
}