Install & Compatibility
Where this runs
tested against v1.4.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.022s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.022s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
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
Demonstrates how to use the `@retry` decorator with `stop_max_attempt_number` and `wait_fixed` to retry a function that might fail intermittently. By default, `@retry` retries on any exception indefinitely and without delay, so it's crucial to configure stop and wait conditions.
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}")
Debug
Known issues
breakingThe `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.fixConsider 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.
affects: All versions
gotchaThe 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.fixAlways 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)`.
affects: All versions
gotchaOlder 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")`).fixUpdate any `print` statements in your code or copied examples from `print "hello"` to `print("hello")` to be compatible with Python 3. affects: <=1.3.3 (examples), all versions (user code)
breakingThe `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.fixVerify 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.
affects: All versions (due to potential version mismatch or Python compatibility issues with unmaintained `retrying` library)
Upgrade
Version history
1.4.2latest on PyPI · released Aug 3, 2025
Audit
Dependencies
sixrequiredCompatibility layer for Python 2 and 3, required by the library.