Skip to main content

Unified resilience patterns for Python — retry, circuit breaker, timeout, fallback, and bulkhead in one decorator.

Project description

pyresilience

CI codecov PyPI PyPI - Downloads Python Documentation License: MIT

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

pyresilience-0.1.1.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyresilience-0.1.1-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

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

Hashes for pyresilience-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6d61260543e1828a18e80514ebc56dadb8cd25245e8880b22083c2ab7602cfb5
MD5 8a04e3e9a4f3f9cc057c1c7e083a5488
BLAKE2b-256 b7158e19dad5155605ab0201d4db9e1030f7f2833e946017fff5a646e3289a9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyresilience-0.1.1.tar.gz:

Publisher: ci.yml on AhsanSheraz/pyresilience

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pyresilience-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cde02bd30a414573d7d5baf7810f41d1c8a9a252035319eac08893a0f6791e26
MD5 6d52183c77df2e87bac7b62e3845dfee
BLAKE2b-256 7ec08c2552565b32f2f8df828799ae14b8add8f8bc3869b8594297c2daa03297

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyresilience-0.1.1-py3-none-any.whl:

Publisher: ci.yml on AhsanSheraz/pyresilience

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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