Unified resilience patterns for Python — retry, circuit breaker, timeout, fallback, and bulkhead in one decorator.
Project description
pyresilience
All resilience patterns. One decorator. Zero dependencies.
Stop juggling tenacity for retries, pybreaker for circuit breakers, and custom code for everything else. pyresilience gives you retry, circuit breaker, timeout, fallback, bulkhead, rate limiter, and cache — all through a single @resilient() decorator that works with sync and async.
Install
pip install pyresilience
Also works with uv, poetry, and pdm.
Quick Start
from pyresilience import resilient, RetryConfig, TimeoutConfig, CircuitBreakerConfig
@resilient(
retry=RetryConfig(max_attempts=3, delay=1.0),
timeout=TimeoutConfig(seconds=10),
circuit_breaker=CircuitBreakerConfig(failure_threshold=5),
)
def call_api(endpoint: str) -> dict:
return requests.get(endpoint).json()
Retries with exponential backoff. Times out at 10s. Opens the circuit after 5 failures. That's it.
Why pyresilience?
- One library instead of many — No need to wire together
tenacity+pybreaker+ custom timeout/fallback/rate limiting code. One config, one decorator. - Patterns that work together — Circuit breaker state is shared across retries. Rate limiting respects bulkhead limits. Cache short-circuits the entire pipeline. Everything is coordinated.
- Zero dependencies — Pure Python. Nothing to conflict with your stack.
- Sync and async — Same API for both. No separate libraries or different patterns to learn.
- Production observability — Built-in event listeners for logging, metrics, and alerting. Know when circuits open, retries fire, or rate limits hit.
- Framework integrations — Drop-in support for FastAPI, Django, and Flask.
All Seven Patterns
| Pattern | Config | What it does |
|---|---|---|
| Retry | RetryConfig |
Exponential backoff with jitter |
| Timeout | TimeoutConfig |
Per-call time limits |
| Circuit Breaker | CircuitBreakerConfig |
Stop calling failing services |
| Fallback | FallbackConfig |
Graceful degradation |
| Bulkhead | BulkheadConfig |
Concurrency limiting |
| Rate Limiter | RateLimiterConfig |
Token bucket rate limiting |
| Cache | CacheConfig |
LRU result caching with TTL |
Comparison
| pyresilience | tenacity | pybreaker | backoff | stamina | |
|---|---|---|---|---|---|
| Retry | Yes | Yes | - | Yes | Yes |
| Circuit Breaker | Yes | - | Yes | - | - |
| Timeout | Yes | - | - | - | - |
| Fallback | Yes | - | - | - | - |
| Bulkhead | Yes | - | - | - | - |
| Rate Limiter | Yes | - | - | - | - |
| Cache | Yes | - | - | - | - |
| Unified API | Yes | - | - | - | - |
| Zero Dependencies | Yes | Yes | - | - | - |
| Async | Yes | Yes | - | Yes | Yes |
Documentation
Full guides, API reference, and examples at pyresilience.readthedocs.io.
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyresilience-0.1.1.tar.gz.
File metadata
- Download URL: pyresilience-0.1.1.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d61260543e1828a18e80514ebc56dadb8cd25245e8880b22083c2ab7602cfb5
|
|
| MD5 |
8a04e3e9a4f3f9cc057c1c7e083a5488
|
|
| BLAKE2b-256 |
b7158e19dad5155605ab0201d4db9e1030f7f2833e946017fff5a646e3289a9f
|
Provenance
The following attestation bundles were made for pyresilience-0.1.1.tar.gz:
Publisher:
ci.yml on AhsanSheraz/pyresilience
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyresilience-0.1.1.tar.gz -
Subject digest:
6d61260543e1828a18e80514ebc56dadb8cd25245e8880b22083c2ab7602cfb5 - Sigstore transparency entry: 1127785652
- Sigstore integration time:
-
Permalink:
AhsanSheraz/pyresilience@27b9e710db302f0a01f15ffb3ba53f5e7dedfe5f -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/AhsanSheraz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@27b9e710db302f0a01f15ffb3ba53f5e7dedfe5f -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyresilience-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyresilience-0.1.1-py3-none-any.whl
- Upload date:
- Size: 25.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cde02bd30a414573d7d5baf7810f41d1c8a9a252035319eac08893a0f6791e26
|
|
| MD5 |
6d52183c77df2e87bac7b62e3845dfee
|
|
| BLAKE2b-256 |
7ec08c2552565b32f2f8df828799ae14b8add8f8bc3869b8594297c2daa03297
|
Provenance
The following attestation bundles were made for pyresilience-0.1.1-py3-none-any.whl:
Publisher:
ci.yml on AhsanSheraz/pyresilience
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyresilience-0.1.1-py3-none-any.whl -
Subject digest:
cde02bd30a414573d7d5baf7810f41d1c8a9a252035319eac08893a0f6791e26 - Sigstore transparency entry: 1127785724
- Sigstore integration time:
-
Permalink:
AhsanSheraz/pyresilience@27b9e710db302f0a01f15ffb3ba53f5e7dedfe5f -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/AhsanSheraz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@27b9e710db302f0a01f15ffb3ba53f5e7dedfe5f -
Trigger Event:
push
-
Statement type: