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.0.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.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: resilient_http-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 0ec6ec183bcd814be6bcaa18e22df058762a80ac67b123e99f09c4b1943a4e47
MD5 838a577623520910a563f469d1566ac1
BLAKE2b-256 53348051f90a12468d4e25e213e1e2ddec1cfee3dc7edcda4148672de8bfd2e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: resilient_http-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d91a3bbb2c250c1771c4b06574092c7bebd9ad324ef8b3ebb45e631678e2d51
MD5 bc61583c27cd36c4166095c4c9f4f9ed
BLAKE2b-256 893843928f02d614ca19ece45cf44000eadf277d3fa1b76701af39e9fc7c9e26

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