Skip to main content

Resilience layer for Python HTTP clients (smart retries, jitter backoff, circuit breaker)

Project description

Resilient HTTP

Production‑grade resilience layer for Python HTTP clients

Smart retries, jitter backoff, and a circuit breaker with half‑open probes. Works with both requests and httpx (async).

CI Python License PyPI version


🚀 Install

pip install resilient-http

Development:

pip install -e .[dev]

🍰 Quickstart (Requests)

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(resp.status_code)

✅ Retries on 503 / 502 / 504 / 429 ✅ Exponential backoff + jitter ✅ Stops retrying on 400/401/403/404


⚡ Quickstart (HTTPX Async)

import httpx
from resilient_http.httpx_async import ResilientAsyncClient
from resilient_http.retry_policy import RetryPolicy

async def main():
    client = ResilientAsyncClient(retry_policy=RetryPolicy(max_attempts=3))
    response = await client.get("https://httpbin.org/status/503")
    print(response.status_code)

import asyncio; asyncio.run(main())

✅ Features

Capability Description
Smart retries Status + exception aware
Backoff strategies Full jitter / exponential
Circuit breaker closed → open → half‑open
Idempotency‑aware Retries only safe methods by default
Sync + Async requests + httpx support
Pluggable Custom retry logic/backoff hooks

🧠 Why this exists

Production APIs fail. Networks glitch. SaaS rate‑limits you.

This project makes failures boring using proven patterns:

  • AWS retry strategy (full jitter)
  • Google SRE (equal jitter)
  • Netflix Hystrix circuit breaker

🧱 Design

  • No monkey‑patching
  • Zero global state
  • Strict typing (mypy clean)
  • Deterministic backoff math
  • Works with chaos testing / latency injection

🧪 Development

pytest -q
ruff check .
black .
mypy .

📜 License

MIT © 2025 Plamen Nikolov

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

resilient_http-1.0.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

resilient_http-1.0.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file resilient_http-1.0.1.tar.gz.

File metadata

  • Download URL: resilient_http-1.0.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for resilient_http-1.0.1.tar.gz
Algorithm Hash digest
SHA256 cc0b91320bad460d21d1b2eb491d661ac39f8652bbecdea0fdb4568b802aac18
MD5 d3d0df655853ceac80e77959c283c612
BLAKE2b-256 14a6050204921f5915c2c269eadca80c8728c35029fe7135f39dc2455a14862c

See more details on using hashes here.

File details

Details for the file resilient_http-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: resilient_http-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for resilient_http-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 899212328f5fc01c849a772658eaeba6451ae567978273389bedec0d73fb0757
MD5 e0d1024cbf344efa946395b14eb9399a
BLAKE2b-256 105ad59f59766ad8a1c15f98821459f9937ba01a6839f0ccfb1d7b4474b64b3d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page