Async HTTP client with retry, backoff, and proxy rotation
Project description
resilient-httpx
Async HTTP client with retry, backoff, and proxy rotation. Built on top of httpx, tenacity, and structlog.
Installation
pip install resilient-httpx
Usage
Basic (no proxies)
from resilient_httpx import ProxyHttpClient, RetryPolicy
async with ProxyHttpClient(retry=RetryPolicy(max_attempts=5), timeout=15.0) as client:
response = await client.get("https://api.example.com/data")
With proxy rotation
from resilient_httpx import ProxyHttpClient, RetryPolicy
client = ProxyHttpClient(
proxies=[
"http://proxy1:8080",
"http://user:pass@proxy2:8080",
"socks5://proxy3:1080",
],
proxy_strategy="round-robin", # or "random"
retry=RetryPolicy(max_attempts=5, backoff="exponential"),
timeout=15.0,
blacklist_threshold=3,
blacklist_ttl=300.0,
)
async with client:
response = await client.get("https://api.example.com/data")
data = response.json()
Custom retry policy
import httpx
from resilient_httpx import RetryPolicy
policy = RetryPolicy(
max_attempts=5,
backoff="exponential", # "exponential" | "fixed" | "random_jitter"
min_wait=1.0,
max_wait=30.0,
retry_on=[429, 500, 502, 503, 504],
retry_on_exception=[httpx.TimeoutException, httpx.ConnectError],
)
Error handling
from resilient_httpx import ProxyHttpClient, AllProxiesExhausted, MaxRetriesExceeded
async with ProxyHttpClient(proxies=proxy_list) as client:
try:
response = await client.get("https://api.example.com/data")
except AllProxiesExhausted:
... # all proxies blacklisted
except MaxRetriesExceeded as exc:
... # retries exhausted, exc.__cause__ has the last error
Configuration Reference
| Parameter | Type | Default | Description |
|---|---|---|---|
proxies |
list[str] | None |
None |
Proxy URLs |
proxy_strategy |
str |
"round-robin" |
"round-robin" or "random" |
retry |
RetryPolicy |
RetryPolicy() |
Retry configuration |
timeout |
float |
30.0 |
Request timeout in seconds |
headers |
dict[str, str] | None |
None |
Default headers |
blacklist_threshold |
int |
3 |
Consecutive failures before blacklisting |
blacklist_ttl |
float |
300.0 |
Blacklist duration in seconds |
fallback_to_direct |
bool |
False |
Request without proxy when all are blacklisted |
Development
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest
Run with coverage:
pytest --cov=resilient_httpx --cov-report=term-missing
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file resilient_httpx-0.3.0.tar.gz.
File metadata
- Download URL: resilient_httpx-0.3.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc0cb1ca1ed20dfce597e159fdb0661cbdff4dff27aee230d212d6605d485440
|
|
| MD5 |
d48d6cc4526653b8c436bb7045ad29c0
|
|
| BLAKE2b-256 |
f44535efe02fd52aff4df6f5e47eae18b2cce1079758fbd846f4c415ec1dcc23
|
Provenance
The following attestation bundles were made for resilient_httpx-0.3.0.tar.gz:
Publisher:
publish.yml on galthran-wq/resilient-httpx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
resilient_httpx-0.3.0.tar.gz -
Subject digest:
dc0cb1ca1ed20dfce597e159fdb0661cbdff4dff27aee230d212d6605d485440 - Sigstore transparency entry: 953072398
- Sigstore integration time:
-
Permalink:
galthran-wq/resilient-httpx@d0af7aee0122a27ccc300032e7a9e156dbc10b74 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/galthran-wq
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d0af7aee0122a27ccc300032e7a9e156dbc10b74 -
Trigger Event:
push
-
Statement type:
File details
Details for the file resilient_httpx-0.3.0-py3-none-any.whl.
File metadata
- Download URL: resilient_httpx-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3ae560328e22be6b4e16fcbddf51d90b337d547f529814e0135a15b9cb18f3e
|
|
| MD5 |
8dc5e4649a85d6c580b4c65f7fb33b84
|
|
| BLAKE2b-256 |
4a4a28f3b2e1b38fc3b0c0bcb96e70de9bbd4242843c3e1eab602e9838816b19
|
Provenance
The following attestation bundles were made for resilient_httpx-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on galthran-wq/resilient-httpx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
resilient_httpx-0.3.0-py3-none-any.whl -
Subject digest:
e3ae560328e22be6b4e16fcbddf51d90b337d547f529814e0135a15b9cb18f3e - Sigstore transparency entry: 953072399
- Sigstore integration time:
-
Permalink:
galthran-wq/resilient-httpx@d0af7aee0122a27ccc300032e7a9e156dbc10b74 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/galthran-wq
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d0af7aee0122a27ccc300032e7a9e156dbc10b74 -
Trigger Event:
push
-
Statement type: