This is a mini tool that overwrite aiohttp session to provide rate limit function within a same session.
Project description
aiohttp_client_rate_limiter
This is a mini tool that overwrites ClientSession class from aiohttp (https://pypi.org/project/aiohttp/). This subclass introduces rate limter functionality while leaving all the other parent behaviors untouched.
Example:
import asyncio
from aiohttp_client_rate_limiter.ClientSession import RateLimitedClientSession
rl_session = RateLimitedClientSession(
max_concur=5,
reqs_per_period=10,
period_in_secs=60
)
tasks = [asyncio.create_task(rl_session.get(f"https://www.google.com/?q={i}", ssl=False)) for i in range(10)]
await asyncio.gather(*tasks)
await rl_session.close()
Or, we could simply do this, using the native context manager as provided by aiohttp:
import asyncio
from aiohttp_client_rate_limiter.ClientSession import RateLimitedClientSession
async with RateLimitedClientSession(
max_concur=60,
reqs_per_period=5,
period_in_secs=10
) as rl_session:
tasks = [asyncio.create_task(rl_session.get(f"https://www.google.com/?q={i}", ssl=False)) for i in range(10)]
await asyncio.gather(*tasks)
The above example could provide a steady rate of 10 requests/60 seconds at the maximum concurrency of 5.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aiohttp_client_rate_limiter-1.0.3.tar.gz
.
File metadata
- Download URL: aiohttp_client_rate_limiter-1.0.3.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7c2429096a407d96cfc310661c989c55064dd4e7a00d3ff2acda8c96ae4b45e |
|
MD5 | 1ac7c8ceca079892cf29033c2b1dd74c |
|
BLAKE2b-256 | 422281309ddd60bf3069130e9fd7e0411504f19b7aff9d9631d119268f186a15 |
File details
Details for the file aiohttp_client_rate_limiter-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: aiohttp_client_rate_limiter-1.0.3-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6584379c1293e59f156443ccc2cf3eb05607d974a91b694e18199cde72aa51bd |
|
MD5 | c1f1cba4c4c2dc464d2a2bf36bc5c7ed |
|
BLAKE2b-256 | 2919aa71e67ed5a9e3c3ef2f86dff74a769b0991cc54358647825a6bf57dca3a |