throttle-controller


Namethrottle-controller JSON
Version 0.3.1 PyPI version JSON
download
home_pageNone
SummaryA simple throttling controller
upload_time2025-01-31 17:29:31
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseCopyright 2022-2025 Kitsu Yui Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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": null,
    "name": "throttle-controller",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Yui KITSU <kitsuyui+github@kitsuyui.com>",
    "download_url": "https://files.pythonhosted.org/packages/18/7d/741afb3ed199e4e6230c4c5368b13a8143a06cedaa46df82beaf407531bb/throttle_controller-0.3.1.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": "Copyright 2022-2025 Kitsu Yui\n        \n        Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n        \n        1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n        \n        2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n        \n        3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n        \n        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n        ",
    "summary": "A simple throttling controller",
    "version": "0.3.1",
    "project_urls": {
        "Homepage": "https://github.com/kitsuyui/python-throttle-controller"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8cb20a661ce3b4122a1ea0ceabcb6d866da4c88f471103159294d5061d1df311",
                "md5": "6fb281ec767157240aa8cf78d3321e5c",
                "sha256": "621d32b3cceb6b839539dbd8a8e2f7dd9226f664c2754f8bdfb2030b9100f802"
            },
            "downloads": -1,
            "filename": "throttle_controller-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6fb281ec767157240aa8cf78d3321e5c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6388,
            "upload_time": "2025-01-31T17:29:30",
            "upload_time_iso_8601": "2025-01-31T17:29:30.100852Z",
            "url": "https://files.pythonhosted.org/packages/8c/b2/0a661ce3b4122a1ea0ceabcb6d866da4c88f471103159294d5061d1df311/throttle_controller-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "187d741afb3ed199e4e6230c4c5368b13a8143a06cedaa46df82beaf407531bb",
                "md5": "16a3f26f8e7327e0dbe7dc31406fc6ae",
                "sha256": "2b0f19ea3d42d26af5518cd69d2d41d2ed82d1aed5ff80128d5e580d717bc1e2"
            },
            "downloads": -1,
            "filename": "throttle_controller-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "16a3f26f8e7327e0dbe7dc31406fc6ae",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 32470,
            "upload_time": "2025-01-31T17:29:31",
            "upload_time_iso_8601": "2025-01-31T17:29:31.702236Z",
            "url": "https://files.pythonhosted.org/packages/18/7d/741afb3ed199e4e6230c4c5368b13a8143a06cedaa46df82beaf407531bb/throttle_controller-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-31 17:29:31",
    "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.49718s