Skip to main content

aretry

Lightweight retry decorator for sync and async Python functions. Zero dependencies.

invl/retry — the most popular Python retry library — gets 8M+ weekly downloads but hasn't shipped a release since 2018 and has no async support. This is the modern replacement.

Install

pip install aretry

Usage

from aretry import retry

# Works on sync functions
@retry(times=3, on=requests.Timeout, backoff=2.0)
def fetch():
    return requests.get(url, timeout=5)

# Works on async functions — same decorator, no changes needed
@retry(times=3, on=aiohttp.ClientError, backoff=2.0, jitter=True)
async def fetch_async():
    async with session.get(url) as r:
        return await r.json()

# @retry with no parens uses all defaults (3 attempts, 1s delay, 2x backoff)
@retry
def simple():
    ...

Parameters

Parameter Default Description
times 3 Total attempts (1 = try once, no retry)
on Exception Exception type or tuple of types to catch
delay 1.0 Initial wait in seconds before first retry
backoff 2.0 Multiply delay by this after each attempt
jitter False Add ±20% random noise to avoid thundering herd
before_retry None Callback (exc, attempt, delay) called before each retry

Backoff example

With times=4, delay=1.0, backoff=2.0:

Attempt Wait before next
1 (fail) 1s
2 (fail) 2s
3 (fail) 4s
4 (fail) raises RetryExhausted

Error handling

from aretry import RetryExhausted

try:
    fetch()
except RetryExhausted as e:
    print(f"Gave up after {e.attempts} attempts. Last error: {e.last_exc}")

RetryExhausted is a subclass of Exception. The original exception is also accessible via standard __cause__ chaining.

License

MIT

Metadata

Release files for aretry 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aretry 0.1.0
File Size Uploaded
aretry-0.1.0.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aretry 0.1.0
File Interpreter ABI Platform
aretry-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / aretry-0.1.0.tar.gz

Download URL aretry-0.1.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9811d1588ca5eb201c7f4f806290945070780d53146a890ad47fda02bd8539c6
BLAKE2b-256 checksum
How to use checksums
f531e2935e6bf42c80362bbd85d24b9f12a242bdffab0eaa6246db16b4ae408f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.

Transparency log

Release files / aretry-0.1.0-py3-none-any.whl

Download URL aretry-0.1.0-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4b45739db539dc31674406a4389165de9fcb49aa8bb47a86ea1820d27880f9e
BLAKE2b-256 checksum
How to use checksums
96f3a17634605a034d823a0ed77f8f07ffda773b91807c69ec3f36ef62f276dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page