aiobreaker is a Python implementation of the Circuit Breaker pattern, specifically designed for asynchronous applications using `asyncio`. It helps improve the resilience of microservices by preventing an application from repeatedly trying to execute an operation that is likely to fail, such as calling a service that is temporarily down. The current version is 1.2.0, with a stable, infrequent release cadence reflecting its focused scope.
pip install aiobreakerVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to apply a `CircuitBreaker` to an `async` function that simulates failures. It shows how the breaker opens after `fail_max` attempts and how to catch `CircuitBreakerError` to implement fallback logic or notify users of service unavailability.
Always wrap calls to `@breaker` decorated functions in a `try...except CircuitBreakerError` block to implement fallback logic or notify users gracefully.
Ensure that any function decorated with `@breaker` is an `async def` function and is always called using `await`.
Carefully consider the typical latency, error rates, and recovery times of your target service. Start with conservative values and adjust based on monitoring and testing in a production-like environment.
Use `exclude` only for exceptions that you are certain are transient and should not contribute to tripping the breaker (e.g., specific HTTP 4xx errors that indicate client-side issues, not service unavailability). Ensure that common service-failure exceptions (e.g., `ConnectionError`, `TimeoutError`, HTTP 5xx) are *not* excluded.
This is expected behavior. Implement a fallback mechanism or error handling in your `except CircuitBreakerError:` block. Monitor the underlying service to understand why it is failing.
Ensure the function decorated with `@breaker` is defined as `async def` and always invoke it with `await function_name(...)`.
Add `from aiobreaker import CircuitBreaker` at the top of your script or module.
No dependency data recorded yet.