Retry potentially-transient HTTP errors.
Project description
retryhttp
Retry potentially-transient HTTP errors.
Note: This project is in beta status. The API may change significantly.
Overview
Under the hood, retryhttp
extends tenacity
with custom retry and wait strategies, as well as a decorator that wraps tenacity.retry()
with sensible defaults.
Supports both requests
and httpx
.
Quickstart
Install from git:
pip install git+https://github.com/austind/retryhttp.git@main
import httpx
from retryhttp import retry_http_errors
# See Default Behavior section below for what happens here
@retry_http_errors()
def get_example():
response = httpx.get("https://example.com/")
response.raise_for_status()
Default Behavior
By default, retryhttp.retry_http_errors()
retries the following conditions:
- If the response status code is:
- 429 Too Many Requests
- 500 Internal Server Error
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
- If one of the following other exceptions is raised:
- Network errors
httpx.ConnectError
httpx.ReadError
httpx.WriteError
requests.ConnectionError
- Network timeouts
httpx.TimeoutError
requests.Timeout
- Network errors
Based on which error is raised, a different wait strategy is used:
- 429 Too Many Requests: Respect the
Retry-After
header, if present. If not, fall back totenacity.wait_exponential()
- 5xx Server Errors:
tenacity.wait_exponential_jitter()
- Network errors:
tenacity.wait_exponential()
- Network timeouts:
tenacity.wait_exponential_jitter()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
retryhttp-0.1.0.tar.gz
(18.1 kB
view hashes)
Built Distribution
retryhttp-0.1.0-py3-none-any.whl
(15.0 kB
view hashes)
Close
Hashes for retryhttp-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85c332f41a1c8b91f924e313221ac68dc8eccad55643dcc1721b881ef23e35bc |
|
MD5 | 5ead7b67846477e26fa1f064bd73047d |
|
BLAKE2b-256 | 9abab39b31f49b13082434f4fbb4890ed5a4b6a600b4924b431609b14b1629b4 |