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`.
pip install retryhttpVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
Refer to both `retryhttp`'s documentation for its provided decorators and `tenacity`'s documentation for advanced customization options when creating complex retry policies.