Purgatory is an implementation of the circuit breaker pattern.
Note
It is used to detect failures and encapsulates the logic of preventing a failure from constantly recurring, during maintenance, temporary external system failure or unexpected system difficulties.
Source: https://en.wikipedia.org/wiki/Circuit_breaker_design_pattern
The Purgatory library has been develop to be used in blacksmith where the library aiobreaker was used but I encountered limitation so, I decide to build my own implementation that feet well with blacksmith.
Purgatory supports the creation of many circuit breakers easily, that can be used as context manager or decorator. Circuit breaker can be asynchronous or synchronous.
from purgatory import AsyncCircuitBreakerFactory circuitbreaker = AsyncCircuitBreakerFactory() async with await circuitbreaker.get_breaker("my_circuit"): ...
from purgatory import AsyncCircuitBreakerFactory circuitbreaker = AsyncCircuitBreakerFactory() @circuitbreaker("another circuit") async def function_that_may_fail(): ...
from purgatory import SyncCircuitBreakerFactory circuitbreaker = SyncCircuitBreakerFactory() with circuitbreaker.get_breaker("my_circuit"): ...
The state of every circuits can be stored in memory, shared in redis, or be completly customized.
It also support monitoring, using event hook.
Purgatory is fully typed and fully tested.
You can read the full documentation of this library here.
Here is a list of alternatives, which may or may not support coroutines.
- aiobreaker - https://pypi.org/project/aiobreaker/
- circuitbreaker - https://pypi.org/project/circuitbreaker/
- pycircuitbreaker - https://pypi.org/project/pycircuitbreaker/
- pybreaker - https://pypi.org/project/pybreaker/
- lasier - https://pypi.org/project/lasier/
- breakers - https://pypi.org/project/breakers/
- pybreaker - https://pypi.org/project/pybreaker/
- python-circuit - https://pypi.org/project/python-circuit/