Retry potentially transient HTTP errors in Python.
Project description
RetryHTTP
Retry potentially transient HTTP errors in Python.
See documentation.
Overview
Several HTTP errors are often transient, and might succeed if retried:
- HTTP status codes
429 Too Many Requests
(rate limited)500 Internal Server Error
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
- Network errors
- Timeouts
This project aims to simplify retrying these, by extending tenacity
with custom retry and wait strategies, as well as a custom decorator. Defaults are sensible for most use cases, but are fully customizable.
Supports exceptions raised by both requests
and httpx
.
Install
Install from PyPI:
# Supports both HTTPX and requests
pip install retryhttp
You can also install support for only HTTPX or requests:
pip install retryhttp[httpx] # Supports only HTTPX
pip install retryhttp[requests] # Supports only requests
Or, install the latest development snapshot from git:
pip install git+https://github.com/austind/retryhttp.git@develop
Quickstart
import httpx
from retryhttp import retry
# Retries retryable status codes (429, 500, 502, 503, 504), network errors,
# and timeouts, up to 3 times, with appropriate wait strategies for each
# type of error. All of these behaviors are customizable.
@retry
def example():
response = httpx.get("https://example.com/")
response.raise_for_status()
return response.text
Contributing
Contributions welcome! Open a discussion and let's chat about your idea. Looking forward to working with you!
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
Built Distribution
File details
Details for the file retryhttp-1.2.0.tar.gz
.
File metadata
- Download URL: retryhttp-1.2.0.tar.gz
- Upload date:
- Size: 25.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 436329d120dbeeaab74964f117b0617072195ac41bac15b0ff425e94c0c713c3 |
|
MD5 | b8c5b11688f26c87e118332972977f45 |
|
BLAKE2b-256 | 27dc1067eb186a2d7236c409223e83ef132fb4cd7554d159fcda78f1d15f7dea |
File details
Details for the file retryhttp-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: retryhttp-1.2.0-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bd3994cc972092a001edb4643455a1829ccd653bf3b31f1925d9767b01599c2 |
|
MD5 | ee9ece5a5001d84d5cc220fa9fde6fc3 |
|
BLAKE2b-256 | a331c6c23de1ff2273eae5288adc0768eea6243b2844a44cc710ae5721a42d8e |