async-throttle


Nameasync-throttle JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryMultipurpose asyncio throttle
upload_time2023-09-21 06:17:21
maintainer
docs_urlNone
authorJoe Nudell
requires_python>=3.10,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Async Throttle
===

Multipurpose concurrency primitive for `asyncio` coroutines.

## Features

This throttle is configured with two related, but different parameters:

```py
Throttle(capacity: float, concurrency: int = 0, period: float = 1.0)
```

`capacity` - Sets the **rate limit** for requests, as `capacity` per `period` seconds.

`concurrency` - The number of jobs that can be executing at a given time.

Usually, servers will set policies on both of these dimensions, and will suspend clients that violate either of them.

### `Throttle#pause(td: int)`

The `pause` method will lock the throttle for the given number of seconds.

For example, if an API bans your client from accessing resources due to violating their rate-limit, you can tell your code to sleep for a period of time and try again later.

## Usage

The throttle can be a drop-in replacement for another primitive like `asyncio.Semaphore`.
In fact, it's really just an `asyncio.Semaphore` (which handles the `concurrency` limit) mixed with a token bucket to provide rate limiting.

```py
throttle = Throttle(10, 2)  # Two concurrent coros limited to 10qps (total).

# Perform one task when the budget allows
async with throttle:
    # Do some (async) thing

# For tasks that should consume more of the budget, you can call the throttle:
async with throttle(5):
    # Do some more expensive thing, equivalent to 5 requests
```

Like other `asyncio` primitives, `Throttle` is not thread-safe.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "async-throttle",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Joe Nudell",
    "author_email": "jnudell@hks.harvard.edu",
    "download_url": "https://files.pythonhosted.org/packages/05/cf/7056117cb35d4f6040464e669b763103a6419d65c04af487f131b4ba79b6/async_throttle-1.0.0.tar.gz",
    "platform": null,
    "description": "Async Throttle\n===\n\nMultipurpose concurrency primitive for `asyncio` coroutines.\n\n## Features\n\nThis throttle is configured with two related, but different parameters:\n\n```py\nThrottle(capacity: float, concurrency: int = 0, period: float = 1.0)\n```\n\n`capacity` - Sets the **rate limit** for requests, as `capacity` per `period` seconds.\n\n`concurrency` - The number of jobs that can be executing at a given time.\n\nUsually, servers will set policies on both of these dimensions, and will suspend clients that violate either of them.\n\n### `Throttle#pause(td: int)`\n\nThe `pause` method will lock the throttle for the given number of seconds.\n\nFor example, if an API bans your client from accessing resources due to violating their rate-limit, you can tell your code to sleep for a period of time and try again later.\n\n## Usage\n\nThe throttle can be a drop-in replacement for another primitive like `asyncio.Semaphore`.\nIn fact, it's really just an `asyncio.Semaphore` (which handles the `concurrency` limit) mixed with a token bucket to provide rate limiting.\n\n```py\nthrottle = Throttle(10, 2)  # Two concurrent coros limited to 10qps (total).\n\n# Perform one task when the budget allows\nasync with throttle:\n    # Do some (async) thing\n\n# For tasks that should consume more of the budget, you can call the throttle:\nasync with throttle(5):\n    # Do some more expensive thing, equivalent to 5 requests\n```\n\nLike other `asyncio` primitives, `Throttle` is not thread-safe.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Multipurpose asyncio throttle",
    "version": "1.0.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9125f26c43a09e194240927b00da3e2bccb24eea3bb4e3e0c3f25ce552b274f",
                "md5": "9877517715fe39f0686bd61921e799a8",
                "sha256": "db0df33190357548383e46b4e8189a81bb3e0bc609c9952f3ed3fa70dba1ce64"
            },
            "downloads": -1,
            "filename": "async_throttle-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9877517715fe39f0686bd61921e799a8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 6234,
            "upload_time": "2023-09-21T06:17:20",
            "upload_time_iso_8601": "2023-09-21T06:17:20.079967Z",
            "url": "https://files.pythonhosted.org/packages/c9/12/5f26c43a09e194240927b00da3e2bccb24eea3bb4e3e0c3f25ce552b274f/async_throttle-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "05cf7056117cb35d4f6040464e669b763103a6419d65c04af487f131b4ba79b6",
                "md5": "fdb8b6b9d5e00d64b9b3a959becc4e85",
                "sha256": "9bb35cd57a55164c4f8c54bc15c0161b0068f89b4785caf468ab298c96ed1989"
            },
            "downloads": -1,
            "filename": "async_throttle-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fdb8b6b9d5e00d64b9b3a959becc4e85",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 4821,
            "upload_time": "2023-09-21T06:17:21",
            "upload_time_iso_8601": "2023-09-21T06:17:21.756206Z",
            "url": "https://files.pythonhosted.org/packages/05/cf/7056117cb35d4f6040464e669b763103a6419d65c04af487f131b4ba79b6/async_throttle-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-21 06:17:21",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "async-throttle"
}
        
Elapsed time: 0.12509s