Metadata-Version: 2.4
Name: resilient-http
Version: 0.1.1b5
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
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: flake8; 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

**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.

[![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/)
[![Typing](https://img.shields.io/badge/typing-mypy%20strict-blue.svg)](#)

---

## Install

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

Development install:

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

---

## Quickstart

```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("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 (`mypy` clean)
* Works under real latency & chaos scenarios

---

## Development

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