Aiohttp-retry

Latest version: v2.9.1

Safety actively analyzes 682334 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 5 of 6

2.3

You can define your own timeouts logic or use:
- ExponentialRetry with exponential backoff
- RandomRetry for random backoff
- ListRetry with backoff you predefine by list

2.2

RetryClient` add *current attempt number* to `request_trace_ctx` (for more info see [aiohttp doc](https://docs.aiohttp.org/en/stable/client_advanced.html#aiohttp-client-tracing)).

python
import logging
import sys
from types import SimpleNamespace

from aiohttp import ClientSession, TraceConfig, TraceRequestStartParams

from aiohttp_retry import RetryClient, RetryOptions


handler = logging.StreamHandler(sys.stdout)
logging.basicConfig(handlers=[handler])
logger = logging.getLogger(__name__)
retry_options = RetryOptions(attempts=2)


async def on_request_start(
session: ClientSession,
trace_config_ctx: SimpleNamespace,
params: TraceRequestStartParams,
) -> None:
current_attempt = trace_config_ctx.trace_request_ctx['current_attempt']
if retry_options.attempts <= current_attempt:
logger.warning('Wow! We are in last attempt')


async def main():
trace_config = TraceConfig()
trace_config.on_request_start.append(on_request_start)
retry_client = RetryClient(retry_options=retry_options, trace_configs=[trace_config])

response = await retry_client.get('https://httpstat.us/503', ssl=False)
print(response.status)

await retry_client.close()

2.1

Make request awaitable:

python
from aiohttp_retry import RetryClient, RetryOptions

async def main():
retry_options = RetryOptions(attempts=1)
retry_client = RetryClient(raise_for_status=False, retry_options=retry_options)

response = await retry_client.get('/ping')
print(response.status)

await retry_client.close()


v.2.0
Rewrite working with retry options.
Make it possible to specify retry options for RetryClient.

1.2

Set deprecation warnings

1.1.5

Import Protocol from typing_extensions for python < 3.8 due to https://github.com/inyutin/aiohttp_retry/issues/7

1.1

Added log attempts to debug log due to https://github.com/inyutin/aiohttp_retry/issues/3.

Page 5 of 6

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.