Install & Compatibility
Where this runs
tested against v0.9.9.20260408 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.054s · 66.7MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 1.6s · import 0.050s · 18MB
66MB installed
● package 66MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
retry
✓ from retry import retry
This is the primary decorator for adding retry logic to functions.
retry_call
✓ from retry import retry_call
Used to call a function with retry logic directly, without a decorator.
This quickstart demonstrates how to apply the `@retry` decorator to an unreliable function. It configures the decorator to retry specifically on `ConnectionError` exceptions, up to 3 times, with a 2-second delay between attempts. Without `types-retry`, type checkers would have limited understanding of the decorator's effects on the function signature; with it, they can provide more accurate analysis.
import random
from retry import retry
import os
# Example function that might fail
def unreliable_service_call() -> str:
if random.random() < 0.7: # 70% chance of failure
raise ConnectionError("Failed to connect to service!")
return "Service data retrieved successfully!"
# Decorate the function with retry logic
@retry(exceptions=ConnectionError, tries=3, delay=2000) # Retry 3 times, with 2-second delay
def call_with_retry() -> str:
print("Attempting service call...")
return unreliable_service_call()
if __name__ == "__main__":
try:
result = call_with_retry()
print(result)
except Exception as e:
print(f"All retry attempts failed: {e}")
Debug
Known issues
gotchaThe `types-retry` package only provides type hints. You must separately install the actual `retry` runtime library (`pip install retry`) for your code to function. Forgetting the runtime library is a common oversight.fixEnsure both `pip install retry` and `pip install types-retry` are executed in your environment.
affects: All versions
gotchaThere are multiple Python libraries offering retry functionality (e.g., `retry`, `retrying`, `tenacity`). `types-retry` specifically provides stubs for the `retry` library (often associated with `github.com/invl/retry`). Ensure you are using the correct runtime library if you are relying on these type stubs.fixVerify that your `import` statements and usage align with the `retry` library, not `retrying` or `tenacity`.
affects: All versions
gotchaBy default, the `@retry` decorator retries indefinitely if no `tries` parameter is specified. This can lead to infinite loops in case of persistent errors, consuming resources or hanging applications.fixAlways set a `tries` limit (e.g., `tries=3`) or a `stop` condition (e.g., `stop_max_delay`) to prevent infinite retries.
affects: All versions of `retry` (runtime library)
breakingAs part of `typeshed`, `types-retry` aims to provide accurate annotations for specific versions of the `retry` library (e.g., `retry==0.9.*` for `types-retry==0.9.*`). Major updates to the `retry` library's API might cause type-checking failures if your `types-retry` version is not compatible with your installed `retry` version.fixPin your `types-retry` version to match the expected `retry` library version, or explicitly manage compatibility. For example, if you use `retry==0.9.x`, use `types-retry>=0.9.0,<1.0.0` or `types-retry==0.9.9.20260408` (specific release of stubs).
affects: All versions
gotchaType changes in stub packages can sometimes cause type checkers to fail even if the runtime code remains unchanged. `typeshed` strives to minimize this, but it can occur. Older `mypy` versions might also misinterpret newer `typeshed` features, silently losing type precision.fixConsider pinning specific versions of `types-retry` and your type checker (e.g., `mypy`) in your development environment to ensure consistent type checking results.
affects: All versions, especially with older type checkers
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'retry'
The actual 'retry' library, which `types-retry` provides type stubs for, is not installed. `types-retry` does not provide the runtime functionality.
error: Cannot find implementation or library stub for module named 'retry'
A type checker (like MyPy or Pyright) cannot locate the type stubs for the 'retry' library, which are provided by the `types-retry` package.
fixpip install types-retry
error: Call to untyped function "retry"
MyPy is unable to find or apply type information for the `retry` function, typically because the `types-retry` stub package is missing or not correctly accessible to MyPy.
fixpip install types-retry
error: Argument "delay" to "retry" has incompatible type "float"; expected "int"
A type checker detected that an argument passed to the `retry` function (e.g., `delay`) does not match the expected type defined in the `types-retry` stubs, potentially due to incorrect usage or a version mismatch.
fixConsult the `retry` library documentation for the correct argument types. Ensure your `retry` and `types-retry` package versions are compatible. Adjust the argument type in your code (e.g., `delay=int(0.5)`).
Upgrade
Version history
0.9.9.20260408latest on PyPI · released Apr 8, 2026
Audit
Dependencies
retryrequiredProvides type hints for the runtime 'retry' library.