aioretry is an asyncio utility for Python 3.7+ that provides flexible retry mechanisms for asynchronous operations. It supports various retry policies, including fixed delay, exponential backoff, and custom strategies, handling transient failures in async code gracefully. The current version is 6.3.1, and it maintains an 'active' release cadence with regular updates.
pip install aioretryVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates using the `@retry` decorator with a custom asynchronous retry policy. The `flaky_async_call` function simulates transient failures, and `my_retry_policy` specifies when to give up and how long to delay between attempts.
Update your retry policies to use `info.since` as a float directly (e.g., `time.monotonic() - info.since`) instead of `datetime` methods like `.total_seconds()`.
Upgrade `aioretry` to `6.2.0` or higher if you need to use `async def` for your retry policies. For older versions, policies must be synchronous functions.
Ensure your custom policy function (sync or async) consistently returns a tuple of exactly two elements: a boolean indicating whether to stop retrying, and a float for the delay before the next attempt.
Replace `(datetime.now() - info.since).total_seconds()` or similar with `time.monotonic() - info.since` to calculate elapsed time, as `info.since` is already a `float`.
If you intend to use an `async def` retry policy, upgrade `aioretry` to version 6.2.0 or newer. If your policy doesn't require `await`, define it as a regular `def` function.
Modify your custom retry policy to explicitly return a 2-element tuple: the first element as a boolean (`True` to give up, `False` to retry), and the second as a float for the delay in seconds. Example: `return info.fails > MAX_ATTEMPTS, info.fails * 0.1`.
No dependency data recorded yet.