Python Retrying Library
raw JSON → 1.4.2 verified Tue May 12 auth: no python install: verified quickstart: stale maintenance
Retrying is an Apache 2.0 licensed general-purpose Python library designed to simplify the task of adding retry behavior to functions. It allows developers to configure retry logic for transient failures, specifying stop conditions, wait strategies (like exponential backoff), and conditions for retrying based on exceptions or return values. The current version is 1.4.2.
pip install retrying Warnings
breaking The `retrying` library is generally considered unmaintained. Its active development ceased some time ago, and `tenacity` is an actively developed fork that addresses shortcomings and adds new features. Users are strongly encouraged to migrate to `tenacity` for ongoing support, bug fixes, and new capabilities. ↓
fix Consider migrating to `tenacity` (`pip install tenacity`). Be aware that `tenacity` is not API-compatible with `retrying`, requiring code changes. Refer to `tenacity`'s documentation for migration guidance.
gotcha The default behavior of the `@retry` decorator is to retry *forever* on any exception, with *no delay* between attempts. This can lead to infinite loops, high CPU usage, and rapid resource exhaustion in production systems if not explicitly configured with stop and wait strategies. ↓
fix Always configure `stop_max_attempt_number`, `stop_max_delay`, `wait_fixed`, `wait_exponential`, or similar parameters to define clear termination conditions and appropriate delays. For example: `@retry(stop_max_attempt_number=7, wait_fixed=2000)`.
gotcha Older examples or documentation for `retrying` (especially from its earlier development stages) might use Python 2 `print` syntax (e.g., `print "message"`). Since the library now requires Python 3.6+, ensure all `print` statements use the function syntax (`print("message")`). ↓
fix Update any `print` statements in your code or copied examples from `print "hello"` to `print("hello")` to be compatible with Python 3.
breaking The `ImportError: cannot import name 'stop_after_attempt' from 'retrying'` indicates that the `stop_after_attempt` function (and potentially other helper functions like `wait_fixed`) is not directly available for import from the top-level `retrying` module in the installed version. This commonly occurs due to an outdated or incompatible version of the `retrying` library being installed, or potential conflicts with newer Python environments (like Python 3.13) which the unmaintained `retrying` library may not fully support. ↓
fix Verify the installed version of `retrying` and ensure it is compatible with your code and Python version. A more robust solution is to migrate to the actively maintained `tenacity` library, where stop and wait conditions are structured as `from tenacity import retry, stop_after_attempt, wait_fixed` (and usage patterns might differ). Refer to `tenacity` documentation for correct usage.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.01s 17.8M
3.10 alpine (musl) - - 0.01s 17.8M
3.10 slim (glibc) wheel 1.5s 0.01s 18M
3.10 slim (glibc) - - 0.01s 18M
3.11 alpine (musl) wheel - 0.03s 19.6M
3.11 alpine (musl) - - 0.04s 19.6M
3.11 slim (glibc) wheel 1.7s 0.03s 20M
3.11 slim (glibc) - - 0.03s 20M
3.12 alpine (musl) wheel - 0.03s 11.5M
3.12 alpine (musl) - - 0.03s 11.5M
3.12 slim (glibc) wheel 1.4s 0.03s 12M
3.12 slim (glibc) - - 0.03s 12M
3.13 alpine (musl) wheel - 0.03s 11.3M
3.13 alpine (musl) - - 0.03s 11.2M
3.13 slim (glibc) wheel 1.5s 0.03s 12M
3.13 slim (glibc) - - 0.03s 12M
3.9 alpine (musl) wheel - 0.01s 17.3M
3.9 alpine (musl) - - 0.02s 17.3M
3.9 slim (glibc) wheel 1.8s 0.01s 18M
3.9 slim (glibc) - - 0.01s 18M
Imports
- retry
from retrying import retry - stop_after_attempt
from retrying import stop_after_attempt - wait_fixed
from retrying import wait_fixed - wait_exponential
from retrying import wait_exponential
Quickstart stale last tested: 2026-04-24
import random
import os
from retrying import retry, stop_after_attempt, wait_fixed
@retry(stop_max_attempt_number=5, wait_fixed=1000) # Retry up to 5 times, waiting 1 second between attempts
def do_something_unreliable():
if random.randint(0, 10) > 2: # Simulate a failure 70% of the time
print("Operation failed, retrying...")
raise IOError("Simulated transient error")
else:
print("Operation successful!")
return "Awesome sauce!"
try:
result = do_something_unreliable()
print(f"Final result: {result}")
except IOError as e:
print(f"Operation failed after multiple retries: {e}")