Simple aiohttp retry client
This package is similar to Tornado-retry-client.
pip install aiohttp-retry.
Example of usage:
async def test(): async with ClientSession() as client: retry_client = RetryClient(client) async with retry_client.get("https://google.com") as response: text = await response.text() print(text) await retry_client.close()
Look tests for more examples.
Be aware: last request returns as it is.
RetryClient takes a single argument:
RetryClient has methods:
They are same as for
ClientSession, but take additional arguments:
from typing import Optional, Set, Type retry_attempts: int = 3, # How many times we should retry retry_start_timeout: float = 0.1, # Base timeout time, then it exponentially grow retry_max_timeout: float = 30, # Max possible timeout between tries retry_factor: float = 2, # How much we increase timeout each time retry_for_statuses: Optional[Set[int]] = None, # On which statuses we should retry retry_exceptions: Optional[Set[Type]] = None, # On which exceptions we should retry
RetryClient should be closed by
Before creating PR please run mypy:
mypy -m aiohttp_retry
- Add more tests