Resilience layer for Python HTTP clients (smart retries, jitter backoff, circuit breaker)
Project description
resilient-http
Resilience layer for Python HTTP clients: smart retries (idempotency-aware), jitter backoff, and a circuit breaker with half-open probes.
Designed for production workloads where flaky upstreams, throttling (429) and transient 5xx failures are reality.
Install
pip install resilient-http
Development install:
pip install -e .[dev]
Quickstart
from resilient_http.session import ResilientRequestsSession
from resilient_http.retry_policy import RetryPolicy
session = ResilientRequestsSession(
retry_policy=RetryPolicy(max_attempts=4)
)
resp = session.get("https://httpbin.org/status/503")
print("HTTP:", resp.status_code)
Expected behavior:
- retry on 503 (and timeouts, 502/504, 429)
- exponential backoff + jitter
- stops retrying on permanent errors (400/401/403/404)
Features
✅ Smart retry (status/exception aware)
✅ Exponential backoff (full jitter / equal jitter)
✅ Circuit breaker (closed → open → half-open trial)
✅ Idempotent-method policy by default
✅ Drop-in wrapper for requests.Session
Planned
- HTTPX wrapper (
sync+async) - Prometheus metrics hooks
- Persistent circuit state
- Policy plugins
Why?
Naive sleeps and dumb retry loops don’t survive production load.
This library implements practices from:
- AWS retry strategy (full jitter)
- Google SRE (equal jitter)
- Netflix Hystrix-style circuit breaking
Make upstream failures boring. 🧊
Design Principles
- Sensible defaults, override when needed
- Zero global state
- Pure python, no patching
requests - Type-safe (
mypyclean) - Works under real latency & chaos scenarios
Development
python -m venv .venv
. .venv/Scripts/activate # Windows
# source .venv/bin/activate # Linux/macOS
pip install -e .[dev]
pytest -q
black resilient_http tests
flake8 resilient_http tests
mypy resilient_http
License
MIT © 2025 Plamen Nikolov
Project details
Release history Release notifications | RSS feed
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_http-0.1.1b5.tar.gz.
File metadata
- Download URL: resilient_http-0.1.1b5.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c63653e5ef8093cf2503fa537ac05c17134b5e69fb78ac9c35d8aaae5f57d306
|
|
| MD5 |
512e2bcf0160d9cacb1ae697e501b25d
|
|
| BLAKE2b-256 |
7f7c54cc4722bd99452f1360222b1dd2747f0aab3bd248d1066024d683c17a73
|
File details
Details for the file resilient_http-0.1.1b5-py3-none-any.whl.
File metadata
- Download URL: resilient_http-0.1.1b5-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8c62733d9862f58f22b33917324bfa6eae501fcda29dba4560cbf6449d31510
|
|
| MD5 |
fe039d23148e4204bee9e50f34c43587
|
|
| BLAKE2b-256 |
1c20e59c521cde45a54f0d896d1d69fe677dabcd3901c19fac718fa39d93aa14
|