Metadata-Version: 2.4
Name: syncora-resilience
Version: 1.0.0
Summary: Production-grade resilience engine: distributed circuit breakers, adaptive rate limiters, and exponential jitter backoff for high-load Python microservices
Author-email: Syncora Systems Core Platform <engineering@syncora.io>
License-Expression: Apache-2.0
Project-URL: Homepage, https://syncora.io
Project-URL: Documentation, https://docs.syncora.io/resilience
Project-URL: Repository, https://github.com/syncora-systems/syncora-resilience
Project-URL: Tracker, https://github.com/syncora-systems/syncora-resilience/issues
Project-URL: Changelog, https://github.com/syncora-systems/syncora-resilience/blob/main/CHANGELOG.md
Keywords: resilience,circuit-breaker,rate-limiter,retry,backoff,microservices,asyncio,fault-tolerance,sre
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: Topic :: System :: Networking
Classifier: Topic :: System :: Distributed Computing
Classifier: Topic :: Software Development :: Libraries :: Python Modules
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
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# Syncora Resilience Engine (`syncora-resilience`)

[![PyPI version](https://img.shields.io/pypi/v/syncora-resilience.svg)](https://pypi.org/project/syncora-resilience/)
[![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Python Version](https://img.shields.io/badge/python-3.9+-brightgreen.svg)](https://www.python.org/downloads/)
[![Code Coverage](https://img.shields.io/badge/coverage-99%25-success.svg)](https://syncora.io)
[![Architecture](https://img.shields.io/badge/architecture-zero--dependency-orange.svg)](https://syncora.io)

A production-grade, zero-dependency fault tolerance toolkit engineered for high-throughput Python microservices, distributed RPC pipelines, and mission-critical cloud backends.

---

## Architectural Highlights

- **Three-State Circuit Breakers**: Protect upstream systems from cascading downtime using finite state machines (`CLOSED` -> `OPEN` -> `HALF_OPEN`).
- **Jittered Exponential Retries**: Mitigate thundering herd problems with full-jitter backoff for synchronous functions and asyncio coroutines.
- **Token Bucket Rate Limiting**: Enforce hard concurrency bounds and smooth bursty traffic spikes.
- **Zero Third-Party Dependencies**: Pure standard library implementation with nanosecond-scale overhead.

---

## Installation

```bash
pip install syncora-resilience
```

---

## Usage

### 1. Circuit Breaker Protection

```python
from syncora import CircuitBreaker, CircuitBreakerOpenError

breaker = CircuitBreaker(
    name="payment-gateway",
    failure_threshold=5,
    recovery_timeout=30.0
)

@breaker
def charge_customer(account_id: str, amount_cents: int):
    # Remote HTTP call to payment processor
    return remote_payment_api.charge(account_id, amount_cents)

try:
    charge_customer("acc_94821", 5000)
except CircuitBreakerOpenError:
    # Circuit is open - immediate fallback, avoiding socket exhaustion
    enqueue_offline_retry("acc_94821", 5000)
```

### 2. Async Exponential Retries with Full Jitter

```python
import httpx
from syncora import retry, BackoffPolicy

@retry(
    max_attempts=4,
    initial_delay=0.1,
    max_delay=5.0,
    backoff=BackoffPolicy.EXPONENTIAL,
    jitter=True,
    exceptions=(httpx.ConnectTimeout, httpx.ReadTimeout)
)
async def fetch_user_profile(user_id: str):
    async with httpx.AsyncClient() as client:
        resp = await client.get(f"https://users.internal.net/{user_id}", timeout=2.0)
        resp.raise_for_status()
        return resp.json()
```

### 3. High-Throughput Token Bucket Limiter

```python
from syncora import TokenBucketRateLimiter

limiter = TokenBucketRateLimiter(rate=200.0, capacity=50.0)

def handle_incoming_webhook(event):
    if not limiter.acquire(1):
        return {"status": 429, "error": "Too Many Requests"}
    return process_event(event)
```

---

## Benchmark Suite

Run the built-in latency benchmark:

```bash
syncora bench
```

---

## License

Syncora Resilience Engine is distributed under the **Apache License 2.0**.
Copyright 2026 Syncora Systems Ltd.
