Easy to use retry decorator
raw JSON → 0.9.2 verified Tue May 12 auth: no python install: verified quickstart: verified abandoned
The `retry` library (version 0.9.2) provides a simple decorator for adding retry logic to Python functions. It allows configuration of exceptions to catch, number of attempts, delay between retries, backoff strategy, and optional jitter. This library is largely unmaintained, with its last release in 2016, and is superseded by more actively developed alternatives like `tenacity`.
pip install retry Common errors
error ModuleNotFoundError: No module named 'retry' ↓
cause The 'retry' library has not been installed in your Python environment.
fix
Run 'pip install retry' in your terminal.
error TypeError: retry() missing 1 required positional argument: 'f' ↓
cause The `@retry` decorator was called with arguments but without the necessary parentheses for the decorator factory, causing it to be interpreted as if it's decorating a function directly.
fix
Always use parentheses when providing arguments to the decorator, even if empty:
@retry(tries=3) instead of @retry(tries=3). error AttributeError: module 'retry' has no attribute 'retry' ↓
cause After `import retry`, the user attempted to access `retry.retry`. The `retry` module itself is the decorator function, so you should use `retry` directly.
fix
If you
import retry, use @retry(...) or retry(func, ...). If you from retry import retry, then use @retry(...) or retry(func, ...). error TypeError: retry() got an unexpected keyword argument 'wait' ↓
cause The 'retry' library does not recognize the keyword argument 'wait' (commonly used in other retry libraries like 'tenacity'). It expects 'delay' for the wait time.
fix
Replace unsupported arguments like 'wait' with the correct argument 'delay' (e.g.,
@retry(delay=2) instead of @retry(wait=2)). Warnings
breaking This 'retry' library (invl/retry) is largely unmaintained, with its last release in 2016. Its API is not compatible with 'tenacity', which is the actively maintained successor to the 'retrying' library (another distinct, unmaintained project). ↓
fix Consider migrating to `tenacity` (pip install tenacity) for active development, better features, and bug fixes. Tenacity offers a more robust and flexible API for retry strategies.
gotcha By default, the `@retry` decorator will retry indefinitely if the `tries` parameter is not explicitly set or set to -1. ↓
fix Always set a finite `tries` value (e.g., `tries=5`) or a `max_delay` to prevent infinite loops in production environments.
gotcha The `retry` decorator does not inherently support asynchronous functions (async/await syntax). ↓
fix For asynchronous code, you will need to use a different retry library that explicitly supports `async/await`, such as `tenacity` with `AsyncRetrying` or `stamina`.
gotcha When using `jitter`, if a tuple `(min, max)` is provided, the extra delay is chosen randomly. If a single number is provided, the jitter is fixed. ↓
fix Be aware of the type of `jitter` parameter passed. For true random jitter to prevent 'thundering herd' problems, provide a tuple (e.g., `jitter=(0, 1)`).
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.03s 18.8M
3.10 alpine (musl) - - 0.03s 18.8M
3.10 slim (glibc) wheel 1.6s 0.02s 19M
3.10 slim (glibc) - - 0.02s 19M
3.11 alpine (musl) wheel - 0.08s 20.8M
3.11 alpine (musl) - - 0.07s 20.8M
3.11 slim (glibc) wheel 1.8s 0.05s 21M
3.11 slim (glibc) - - 0.05s 21M
3.12 alpine (musl) wheel - 0.06s 12.6M
3.12 alpine (musl) - - 0.06s 12.6M
3.12 slim (glibc) wheel 1.7s 0.06s 13M
3.12 slim (glibc) - - 0.06s 13M
3.13 alpine (musl) wheel - 0.08s 12.4M
3.13 alpine (musl) - - 0.06s 12.3M
3.13 slim (glibc) wheel 1.6s 0.06s 13M
3.13 slim (glibc) - - 0.06s 13M
3.9 alpine (musl) wheel - 0.03s 18.3M
3.9 alpine (musl) - - 0.03s 18.3M
3.9 slim (glibc) wheel 1.9s 0.02s 19M
3.9 slim (glibc) - - 0.02s 19M
Imports
- retry wrong
from retrying import retrycorrectfrom retry import retry
Quickstart verified last tested: 2026-04-24
import random
from retry import retry
import logging
logging.basicConfig(level=logging.INFO)
@retry(exceptions=(IOError, ValueError), tries=3, delay=2, backoff=2, max_delay=10)
def unreliable_function():
if random.randint(0, 5) > 2:
raise IOError("Simulated network error")
elif random.randint(0, 5) < 1:
raise ValueError("Simulated data error")
else:
print("Function succeeded!")
return "Success"
try:
result = unreliable_function()
print(f"Final result: {result}")
except (IOError, ValueError) as e:
print(f"Function failed after all retries: {e}")