loop-rate-limiters


Nameloop-rate-limiters JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryLoop rate limiters.
upload_time2024-02-09 09:48:41
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords rate loop frequency regulator limiter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Loop rate limiters

[![Build](https://img.shields.io/github/actions/workflow/status/upkie/loop-rate-limiters/main.yml?branch=main)](https://github.com/upkie/loop-rate-limiters/actions)
[![Documentation](https://img.shields.io/github/actions/workflow/status/upkie/loop-rate-limiters/docs.yml?branch=main&label=docs)](https://upkie.github.io/loop-rate-limiters/)
[![Coverage](https://coveralls.io/repos/github/upkie/loop-rate-limiters/badge.svg?branch=main)](https://coveralls.io/github/upkie/loop-rate-limiters?branch=main)
[![Conda version](https://anaconda.org/conda-forge/loop-rate-limiters/badges/version.svg)](https://anaconda.org/conda-forge/loop-rate-limiters)
[![PyPI version](https://img.shields.io/pypi/v/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/upkie/loop-rate-limiters#asynchronous-io).

## Installation

You can install the library straight from PyPI:

```console
$ pip install loop-rate-limiters
```

Or equivalently from Conda:

```console
$ conda install -c conda-forge loop-rate-limiters
```

## Asynchronous I/O

The ``AsyncRateLimiter`` class provides a loop frequency limiter 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()

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

            

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/95/d8/6bc6854f0ad03623d42211ae45cba6913d23d471572a5ff9cc3c43371662/loop_rate_limiters-1.0.0.tar.gz",
    "platform": null,
    "description": "# Loop rate limiters\n\n[![Build](https://img.shields.io/github/actions/workflow/status/upkie/loop-rate-limiters/main.yml?branch=main)](https://github.com/upkie/loop-rate-limiters/actions)\n[![Documentation](https://img.shields.io/github/actions/workflow/status/upkie/loop-rate-limiters/docs.yml?branch=main&label=docs)](https://upkie.github.io/loop-rate-limiters/)\n[![Coverage](https://coveralls.io/repos/github/upkie/loop-rate-limiters/badge.svg?branch=main)](https://coveralls.io/github/upkie/loop-rate-limiters?branch=main)\n[![Conda version](https://anaconda.org/conda-forge/loop-rate-limiters/badges/version.svg)](https://anaconda.org/conda-forge/loop-rate-limiters)\n[![PyPI version](https://img.shields.io/pypi/v/loop-rate-limiters)](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/upkie/loop-rate-limiters#asynchronous-io).\n\n## Installation\n\nYou can install the library straight from PyPI:\n\n```console\n$ pip install loop-rate-limiters\n```\n\nOr equivalently from Conda:\n\n```console\n$ conda install -c conda-forge loop-rate-limiters\n```\n\n## Asynchronous I/O\n\nThe ``AsyncRateLimiter`` class provides a loop frequency limiter 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\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Loop rate limiters.",
    "version": "1.0.0",
    "project_urls": {
        "Changelog": "https://github.com/upkie/loop-rate-limiters/blob/master/CHANGELOG.md",
        "Source": "https://github.com/upkie/loop-rate-limiters",
        "Tracker": "https://github.com/upkie/loop-rate-limiters/issues"
    },
    "split_keywords": [
        "rate",
        "loop",
        "frequency",
        "regulator",
        "limiter"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "92ad3cd3e1992e79bbc535dcf8ea5591bed7967d6fe2437fbc737f3f14898b6b",
                "md5": "60c53c659594c84ad38bdf0581470048",
                "sha256": "1bec278411fc4d3f35a94f1342cf211e9ad81d8a3d3b9b08f2eeb5e4fd6e9e9d"
            },
            "downloads": -1,
            "filename": "loop_rate_limiters-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "60c53c659594c84ad38bdf0581470048",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 10455,
            "upload_time": "2024-02-09T09:48:38",
            "upload_time_iso_8601": "2024-02-09T09:48:38.835802Z",
            "url": "https://files.pythonhosted.org/packages/92/ad/3cd3e1992e79bbc535dcf8ea5591bed7967d6fe2437fbc737f3f14898b6b/loop_rate_limiters-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "95d86bc6854f0ad03623d42211ae45cba6913d23d471572a5ff9cc3c43371662",
                "md5": "bdf91443df95a06fcd8ef16aaf80ad1b",
                "sha256": "589218f978421debe221eeadf4de3e64cff8c34c58bbaeb878e6326490f4f370"
            },
            "downloads": -1,
            "filename": "loop_rate_limiters-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bdf91443df95a06fcd8ef16aaf80ad1b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 11978,
            "upload_time": "2024-02-09T09:48:41",
            "upload_time_iso_8601": "2024-02-09T09:48:41.589826Z",
            "url": "https://files.pythonhosted.org/packages/95/d8/6bc6854f0ad03623d42211ae45cba6913d23d471572a5ff9cc3c43371662/loop_rate_limiters-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-09 09:48:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "upkie",
    "github_project": "loop-rate-limiters",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "loop-rate-limiters"
}
        
Elapsed time: 0.18125s