throttle-controller


Namethrottle-controller JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/kitsuyui/python-throttle-controller
SummaryA simple throttling controller
upload_time2023-10-06 05:16:04
maintainer
docs_urlNone
authorYui Kitsu
requires_python>=3.8
licenseBSD-3-Clause
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # throttle-controller

[![Python](https://img.shields.io/pypi/pyversions/throttle-controller.svg?style=plastic)](https://badge.fury.io/py/throttle-controller)
[![PyPI version shields.io](https://img.shields.io/pypi/v/throttle-controller.svg)](https://pypi.python.org/pypi/throttle-controller/)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![codecov](https://codecov.io/gh/kitsuyui/python-throttle-controller/branch/main/graph/badge.svg?token=90X7WXZDD2)](https://codecov.io/gh/kitsuyui/python-throttle-controller)

## Motivation

This package provides a simple throttle controller for general use-cases.
For example, you can use this package to throttle API requests to avoid rate-limiting.

## Usage

```python
from throttle_controller import SimpleThrottleController

throttle = SimpleThrottleController.create(default_cooldown_time=3.0)
throttle.wait_if_needed("http://example.com/path/to/api")
throttle.record_use_time_as_now("http://example.com/path/to/api")
... # requests
throttle.wait_if_needed("http://example.com/path/to/api")  # wait 3.0 seconds
throttle.record_use_time_as_now("http://example.com/path/to/api")
```

### `with` statement

```python
from throttle_controller import SimpleThrottleController
throttle = SimpleThrottleController.create(default_cooldown_time=3.0)

for _ in range(10):
    with throttle.use("http://example.com/path/to/api"):
        # wait if cooldown needed
        requests.get("http://example.com/path/to/api")
```

# Caution

Currently this package supports only to use in single thread / single process use-cases.

# LICENSE

The 3-Clause BSD License. See also LICENSE file.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kitsuyui/python-throttle-controller",
    "name": "throttle-controller",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Yui Kitsu",
    "author_email": "kitsuyui+github@kitsuyui.com",
    "download_url": "https://files.pythonhosted.org/packages/de/7e/6167f904bd3550c5247f066489d4595f7a16e58182c257e799af8206845f/throttle-controller-0.2.0.tar.gz",
    "platform": null,
    "description": "# throttle-controller\n\n[![Python](https://img.shields.io/pypi/pyversions/throttle-controller.svg?style=plastic)](https://badge.fury.io/py/throttle-controller)\n[![PyPI version shields.io](https://img.shields.io/pypi/v/throttle-controller.svg)](https://pypi.python.org/pypi/throttle-controller/)\n[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)\n[![codecov](https://codecov.io/gh/kitsuyui/python-throttle-controller/branch/main/graph/badge.svg?token=90X7WXZDD2)](https://codecov.io/gh/kitsuyui/python-throttle-controller)\n\n## Motivation\n\nThis package provides a simple throttle controller for general use-cases.\nFor example, you can use this package to throttle API requests to avoid rate-limiting.\n\n## Usage\n\n```python\nfrom throttle_controller import SimpleThrottleController\n\nthrottle = SimpleThrottleController.create(default_cooldown_time=3.0)\nthrottle.wait_if_needed(\"http://example.com/path/to/api\")\nthrottle.record_use_time_as_now(\"http://example.com/path/to/api\")\n... # requests\nthrottle.wait_if_needed(\"http://example.com/path/to/api\")  # wait 3.0 seconds\nthrottle.record_use_time_as_now(\"http://example.com/path/to/api\")\n```\n\n### `with` statement\n\n```python\nfrom throttle_controller import SimpleThrottleController\nthrottle = SimpleThrottleController.create(default_cooldown_time=3.0)\n\nfor _ in range(10):\n    with throttle.use(\"http://example.com/path/to/api\"):\n        # wait if cooldown needed\n        requests.get(\"http://example.com/path/to/api\")\n```\n\n# Caution\n\nCurrently this package supports only to use in single thread / single process use-cases.\n\n# LICENSE\n\nThe 3-Clause BSD License. See also LICENSE file.\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "A simple throttling controller",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/kitsuyui/python-throttle-controller"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "055f071919b661326e7c73818fb009d4eadfd9e1204ac5c7d5b7456cdcb4da52",
                "md5": "f7b588f41f120b7e47492fcdbd98dbb1",
                "sha256": "1ac2f4b111219032dc60ad7d2b37557f727967850e0800d90568df6662376ed1"
            },
            "downloads": -1,
            "filename": "throttle_controller-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f7b588f41f120b7e47492fcdbd98dbb1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6645,
            "upload_time": "2023-10-06T05:16:03",
            "upload_time_iso_8601": "2023-10-06T05:16:03.380938Z",
            "url": "https://files.pythonhosted.org/packages/05/5f/071919b661326e7c73818fb009d4eadfd9e1204ac5c7d5b7456cdcb4da52/throttle_controller-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "de7e6167f904bd3550c5247f066489d4595f7a16e58182c257e799af8206845f",
                "md5": "598448cc2510cdffe972be77f9e9840c",
                "sha256": "95904c8ed09eb9f6df3089d7cd33a6c1d36b2ed30ed21001165366b2bd1b23b8"
            },
            "downloads": -1,
            "filename": "throttle-controller-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "598448cc2510cdffe972be77f9e9840c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 21316,
            "upload_time": "2023-10-06T05:16:04",
            "upload_time_iso_8601": "2023-10-06T05:16:04.496493Z",
            "url": "https://files.pythonhosted.org/packages/de/7e/6167f904bd3550c5247f066489d4595f7a16e58182c257e799af8206845f/throttle-controller-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-06 05:16:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kitsuyui",
    "github_project": "python-throttle-controller",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "throttle-controller"
}
        
Elapsed time: 0.11701s