httpx_ratelimiter


Namehttpx_ratelimiter JSON
Version 0.0.6 PyPI version JSON
download
home_pageNone
SummaryRatelimiting for httpx
upload_time2024-06-11 14:32:17
maintainerNone
docs_urlNone
authorNone
requires_python>3.9
licenseNone
keywords httpx rate-limiting leaky-bucket
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # httpx-ratelimit
[![PyPI version](https://badge.fury.io/py/httpx_ratelimiter.svg)](https://badge.fury.io/py/httpx_ratelimiter)


Simple wrapper around
[PyrateLimiter](https://pyratelimiter.readthedocs.io/en/latest/)
that adds integration with
[httpx](https://www.python-httpx.org/) library

### Usage
##### Using per_* kwargs:
```py
from time import time

from httpx import Client

from httpx_ratelimiter import LimiterTransport

# Apply a rate limit of 5 requests per second to all requests
# if wait time between request will be more than 600ms, raise an BucketFullException
with Client(transport=LimiterTransport(per_second=5, max_delay=600)) as c:
    start = time()
    for _i in range(100):
        print(
            f'[t + {time() - start: .2f}] got response: {c.get("https://httpbin.org/status/200,429")}'
        )
```
##### Using custom list of rates
```py
from time import time

from httpx import Client

from httpx_ratelimiter import LimiterTransport
from pyrate_limiter import Limiter, Rate, Duration

# limit 5 requests over 2 seconds and 10 requests over 1 minute
rates = [Rate(5, Duration.SECOND * 2), Rate(10, Duration.MINUTE)]
# if wait time between request will be more than 600ms, silently fail
with Client(transport=LimiterTransport(rates=rates, max_delay=600, raise_when_fail=False)) as c:
    start = time()
    for _i in range(100):
        print(
            f'[t + {time() - start: .2f}] got response: {c.get("https://httpbin.org/status/200,429")}'
        )
```


### Thanks
Thank to original [Requests-ratelimiter](https://github.com/JWCook/requests-ratelimiter/tree/main) author for idea and backbone of a project.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "httpx_ratelimiter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">3.9",
    "maintainer_email": null,
    "keywords": "httpx, rate-limiting, leaky-bucket",
    "author": null,
    "author_email": "Anatoly Raev <cralixraev@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/38/35/8912e02d6e09f58bc024657592799abffc69b01c65fcc1fcd1af657f1f7a/httpx_ratelimiter-0.0.6.tar.gz",
    "platform": null,
    "description": "# httpx-ratelimit\n[![PyPI version](https://badge.fury.io/py/httpx_ratelimiter.svg)](https://badge.fury.io/py/httpx_ratelimiter)\n\n\nSimple wrapper around\n[PyrateLimiter](https://pyratelimiter.readthedocs.io/en/latest/)\nthat adds integration with\n[httpx](https://www.python-httpx.org/) library\n\n### Usage\n##### Using per_* kwargs:\n```py\nfrom time import time\n\nfrom httpx import Client\n\nfrom httpx_ratelimiter import LimiterTransport\n\n# Apply a rate limit of 5 requests per second to all requests\n# if wait time between request will be more than 600ms, raise an BucketFullException\nwith Client(transport=LimiterTransport(per_second=5, max_delay=600)) as c:\n    start = time()\n    for _i in range(100):\n        print(\n            f'[t + {time() - start: .2f}] got response: {c.get(\"https://httpbin.org/status/200,429\")}'\n        )\n```\n##### Using custom list of rates\n```py\nfrom time import time\n\nfrom httpx import Client\n\nfrom httpx_ratelimiter import LimiterTransport\nfrom pyrate_limiter import Limiter, Rate, Duration\n\n# limit 5 requests over 2 seconds and 10 requests over 1 minute\nrates = [Rate(5, Duration.SECOND * 2), Rate(10, Duration.MINUTE)]\n# if wait time between request will be more than 600ms, silently fail\nwith Client(transport=LimiterTransport(rates=rates, max_delay=600, raise_when_fail=False)) as c:\n    start = time()\n    for _i in range(100):\n        print(\n            f'[t + {time() - start: .2f}] got response: {c.get(\"https://httpbin.org/status/200,429\")}'\n        )\n```\n\n\n### Thanks\nThank to original [Requests-ratelimiter](https://github.com/JWCook/requests-ratelimiter/tree/main) author for idea and backbone of a project.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Ratelimiting for httpx",
    "version": "0.0.6",
    "project_urls": {
        "Home": "https://github.com/CralixRaev/httpx_ratelimiter"
    },
    "split_keywords": [
        "httpx",
        " rate-limiting",
        " leaky-bucket"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ea9affb494b35cd8e52ec7462afd5f7564afc4b7b769bd4a5c19c5e3d8d9d604",
                "md5": "518f773e82aa7293353627ebb2ed2492",
                "sha256": "0b81bb25d4cf5cf9b7a817f93d4df2ed3bd2571f74bfc0701450440285c131ec"
            },
            "downloads": -1,
            "filename": "httpx_ratelimiter-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "518f773e82aa7293353627ebb2ed2492",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">3.9",
            "size": 5875,
            "upload_time": "2024-06-11T14:32:15",
            "upload_time_iso_8601": "2024-06-11T14:32:15.363547Z",
            "url": "https://files.pythonhosted.org/packages/ea/9a/ffb494b35cd8e52ec7462afd5f7564afc4b7b769bd4a5c19c5e3d8d9d604/httpx_ratelimiter-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "38358912e02d6e09f58bc024657592799abffc69b01c65fcc1fcd1af657f1f7a",
                "md5": "1dfe69ecd78cf645029c74b1a534e9c6",
                "sha256": "30b23e749c3c639e9d4fc3ff35ff883a05c563469b0a2c79b60a13e9c7826931"
            },
            "downloads": -1,
            "filename": "httpx_ratelimiter-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "1dfe69ecd78cf645029c74b1a534e9c6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">3.9",
            "size": 7395,
            "upload_time": "2024-06-11T14:32:17",
            "upload_time_iso_8601": "2024-06-11T14:32:17.815230Z",
            "url": "https://files.pythonhosted.org/packages/38/35/8912e02d6e09f58bc024657592799abffc69b01c65fcc1fcd1af657f1f7a/httpx_ratelimiter-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-11 14:32:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "CralixRaev",
    "github_project": "httpx_ratelimiter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "httpx_ratelimiter"
}
        
Elapsed time: 3.75941s