python-retry

raw JSON →
0.0.1 verified Mon Apr 27 auth: no python

A simple, lightweight Python package for retrying operations with configurable retry counts, delays, and backoff strategies. Version 0.0.1 is the initial release, with minimal API surface and basic functionality. The package is in early development with slow release cadence.

pip install python-retry
error ImportError: cannot import name 'retry' from 'retry'
cause Trying to import from the wrong package or the module structure has changed.
fix
Use pip install python-retry and then from retry import retry.
error AttributeError: module 'retry' has no attribute 'Retry'
cause Importing Retry from the top-level module instead of the submodule.
fix
from retry.retry import Retry
gotcha The @retry decorator does not catch exceptions by default; it only retries on exceptions that inherit from Exception. If your function raises BaseException directly (e.g., SystemExit), it will not be retried.
fix Ensure your functions raise Exception subclasses, or use the 'exceptions' parameter to specify custom exception types.
gotcha The backoff parameter is multiplicative, not additive. For example, with delay=1 and backoff=2, delays are 1, 2, 4 seconds. Users often expect additive backoff (e.g., 1, 2, 3).
fix Set backoff=1 for constant delay; otherwise, calculate expected delays accordingly.

Decorate a function to retry up to 3 times with exponential backoff.

from retry import retry

@retry(count=3, delay=1, backoff=2)
def unstable_call():
    import random
    if random.random() < 0.7:
        raise ValueError("transient error")
    return "success"

print(unstable_call())