{"id":2751,"library":"retryhttp","title":"RetryHTTP","description":"RetryHTTP is a Python library designed to simplify retrying potentially transient HTTP errors. It extends the `tenacity` library with custom retry and wait strategies, offering sensible defaults while remaining fully customizable. The library provides decorators to automatically retry HTTP requests in applications using `requests`, `httpx`, or `aiohttp`.","status":"active","version":"1.4.0","language":"en","source_language":"en","source_url":"https://github.com/austind/retryhttp.git","tags":["http","retry","network","requests","httpx","aiohttp","tenacity","error-handling"],"install":[{"cmd":"pip install retryhttp","lang":"bash","label":"Full support for HTTPX, requests, and aiohttp"},{"cmd":"pip install retryhttp[httpx]","lang":"bash","label":"HTTPX-only support"},{"cmd":"pip install retryhttp[requests]","lang":"bash","label":"requests-only support"},{"cmd":"pip install retryhttp[aiohttp]","lang":"bash","label":"aiohttp-only support"}],"dependencies":[{"reason":"Core dependency; retryhttp extends its functionality.","package":"tenacity"},{"reason":"Enables HTTPX integration for retries.","package":"httpx","optional":true},{"reason":"Enables requests integration for retries.","package":"requests","optional":true},{"reason":"Enables aiohttp integration for retries.","package":"aiohttp","optional":true}],"imports":[{"symbol":"retry","correct":"from retryhttp import retry"}],"quickstart":{"code":"import httpx\nfrom retryhttp import retry\n\n@retry\ndef fetch_data_with_retries():\n    \"\"\"Fetches data from example.com, retrying on transient HTTP errors.\"\"\"\n    print(\"Attempting to fetch data...\")\n    try:\n        response = httpx.get(\"https://example.com/\")\n        response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)\n        print(\"Successfully fetched data!\")\n        return response.text\n    except httpx.HTTPStatusError as e:\n        print(f\"HTTP error occurred: {e.response.status_code}\")\n        raise # Re-raise to trigger retry logic if it's a retryable status\n    except httpx.RequestError as e:\n        print(f\"Request error occurred: {e}\")\n        raise # Re-raise to trigger retry logic on network errors/timeouts\n\nif __name__ == \"__main__\":\n    data = fetch_data_with_retries()\n    # In a real scenario, you'd process 'data' here\n    # For this example, we just show successful fetch or final failure\n","lang":"python","description":"This quickstart demonstrates how to use the `@retry` decorator with `httpx`. The decorated function will automatically retry on transient HTTP status codes (429, 500, 502, 503, 504), network errors, and timeouts, with appropriate backoff strategies. The `raise_for_status()` call is crucial to convert HTTP error responses into exceptions that `retryhttp` can intercept and retry."},"warnings":[{"fix":"Carefully configure `retry` decorator parameters (`retry_exceptions`, `retry_on_exception`, `retry_codes`) or wrap non-idempotent calls with more restrictive retry policies if there's any doubt about idempotency.","message":"Be cautious when retrying non-idempotent HTTP methods like POST, PUT, or DELETE by default. While `retryhttp` has sensible defaults for many scenarios, blindly retrying these can lead to unintended side effects (e.g., duplicate resource creation). Always understand your API's idempotency guarantees.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install the necessary client-specific extras: `pip install retryhttp[httpx]`, `pip install retryhttp[requests]`, or `pip install retryhttp[aiohttp]` depending on your chosen HTTP client library.","message":"For full integration and client-specific error handling, remember to install `retryhttp` with the relevant optional dependencies (e.g., `pip install retryhttp[httpx]` for HTTPX support). Without these, `retryhttp` may still catch generic exceptions but won't be able to leverage client-specific error types for more granular retry logic.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to both `retryhttp`'s documentation for its provided decorators and `tenacity`'s documentation for advanced customization options when creating complex retry policies.","message":"If customizing retry behavior, be aware that `retryhttp` extends `tenacity`. While it provides its own decorator, deeper customizations might involve understanding `tenacity`'s retry strategies, wait strategies, and stop conditions. Ensure your custom logic correctly integrates with `retryhttp`'s opinionated defaults.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}