Metadata-Version: 2.4
Name: resilient-http
Version: 1.0.1
Summary: Resilience layer for Python HTTP clients (smart retries, jitter backoff, circuit breaker)
Author: Plamen Nikolov
License: MIT License
        
        Copyright (c) 2025 Plamen Nikolov
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/pgnikolov/resilient-http
Project-URL: Issues, https://github.com/pgnikolov/resilient-http/issues
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Internet :: WWW/HTTP
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28
Requires-Dist: httpx>=0.27
Provides-Extra: dev
Requires-Dist: ruff; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-asyncio; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: types-requests; extra == "dev"
Requires-Dist: check-wheel-contents; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# 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](https://img.shields.io/github/actions/workflow/status/pgnikolov/resilient-http/ci.yml?label=CI)](https://github.com/pgnikolov/resilient-http/actions)
![Python](https://img.shields.io/badge/python-3.9--3.13-blue.svg)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![PyPI version](https://img.shields.io/pypi/v/resilient-http?color=blue)](https://pypi.org/project/resilient-http/)

---

## 🚀 Install

```bash
pip install resilient-http
```

Development:

```bash
pip install -e .[dev]
```

---

## 🍰 Quickstart (Requests)

```python
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)

```python
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

```bash
pytest -q
ruff check .
black .
mypy .
```

---

## 📜 License

MIT © 2025 Plamen Nikolov
