{"id":6855,"library":"retry-decorator","title":"Retry Decorator","description":"The `retry-decorator` library provides a simple yet powerful decorator for retrying function calls upon specified exceptions. It supports features like setting maximum retries, exponential backoff, and logging failed attempts. Version 1.1.1 is the latest release, with future versions planned to drop Python 2 support. The project appears to be actively maintained, though releases are infrequent.","status":"active","version":"1.1.1","language":"en","source_language":"en","source_url":"https://github.com/pnpnpn/retry-decorator","tags":["decorator","retry","backoff","resilience","error-handling"],"install":[{"cmd":"pip install retry-decorator","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The PyPI package is 'retry-decorator', but the main decorator is imported from 'python_retry'. Some older examples might show 'from retry_decorator import *' but this is not the recommended current pattern.","wrong":"from retry_decorator import retry","symbol":"retry","correct":"from python_retry import retry"}],"quickstart":{"code":"import logging\nfrom python_retry import retry\n\nLOGGER = logging.getLogger(__name__)\n\n@retry(max_retries=3,\n       backoff_factor=1,\n       retry_on=(ValueError,),\n       retry_logger=LOGGER)\ndef flaky_function():\n    print(\"Attempting flaky operation...\")\n    if hasattr(flaky_function, 'calls'):\n        flaky_function.calls += 1\n    else:\n        flaky_function.calls = 1\n\n    if flaky_function.calls < 3:\n        raise ValueError(\"Simulated transient error\")\n    print(\"Operation successful!\")\n    return \"Success Data\"\n\nif __name__ == \"__main__\":\n    try:\n        result = flaky_function()\n        print(f\"Final result: {result}\")\n    except ValueError as e:\n        print(f\"Operation failed after multiple retries: {e}\")","lang":"python","description":"This example demonstrates how to use the `@retry` decorator with explicit exception handling, a maximum number of retries, and a basic backoff factor. It also configures a logger to show retry attempts."},"warnings":[{"fix":"Ensure your project runs on Python 3 for future compatibility or pin your dependency to `retry-decorator<2.0` if Python 2 support is critical.","message":"Version 1.1.1 is the last to officially support Python 2. While minor backports might be considered for Python 2.7, future major versions will likely be Python 3 only, potentially breaking compatibility for older environments.","severity":"breaking","affected_versions":"1.1.1 and earlier"},{"fix":"Always use `from python_retry import retry` to import the decorator.","message":"The PyPI package name is `retry-decorator`, but the correct Python import statement is `from python_retry import retry`. Using `from retry_decorator import ...` will result in an `ImportError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always explicitly list the exceptions you intend to retry using the `retry_on` parameter (e.g., `retry_on=(ConnectionError, TimeoutError)`). This makes your retry logic more robust and prevents unintended behavior.","message":"By default, the `@retry()` decorator catches `Exception` (i.e., all exceptions) if the `retry_on` parameter is not explicitly specified. This broad catching can mask unexpected errors in your application logic that should not trigger a retry.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Verify that `pip install retry-decorator` was used and that `from python_retry import retry` is the correct import for this specific library. Cross-reference the documentation if you encounter API discrepancies.","message":"There are several Python libraries with similar names and functionality (e.g., `retry`, `retrying`, `retry-reloaded`). Users might accidentally install or import the wrong library, leading to different APIs and unexpected behavior.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}