Skip to main content

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

Project description

pyresilience

CI Coverage PyPI version Python versions Downloads License Documentation

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

import requests
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

Comparison reflects built-in capabilities and unified API model, not every possible custom composition.

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.2.tar.gz (19.3 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.2-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

Details for the file pyresilience-0.1.2.tar.gz.

File metadata

  • Download URL: pyresilience-0.1.2.tar.gz
  • Upload date:
  • Size: 19.3 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.2.tar.gz
Algorithm Hash digest
SHA256 af650ea19d8b795f82a6302ef1006d48bc98078734c469585dbba660c50ab572
MD5 02959e10175f74c4047febc655f947c5
BLAKE2b-256 1c374f3abb59942e7301420180e3cf93cdd2095233ca65cef982b930fad09259

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyresilience-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: pyresilience-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 25.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ee244be6b788e0891e7318cc6b0bc2b6004b229b5ef9b9327b32b3fe78eebf7d
MD5 b7e7c990991972010ca3b0179c314656
BLAKE2b-256 7e6b737dd5c8ea22679738e2fb13053b904728f99e5aee0bd648f19d88bf7a24

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyresilience-0.1.2-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