Purgatory
Purgatory is a Python library for robust failure management, built to prevent repetitive errors in synchronous and asynchronous systems through an easy-to-use circuit breaker pattern.
Circuit breakers are essential in Python failure management, as they help maintain system safety by preventing cascading failures when dependencies or external services are temporarily unavailable, ensuring that your application remains stable even under unpredictable conditions.
Features
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.
Purgatory allows you to store circuit states in multiple backends, like in-memory or Redis, or even customize the storage backend to suit specific needs. This flexibility is useful for distributed systems, where keeping state in a shared location like Redis can improve synchronization.
Purgatory supports monitoring via event hooks, allowing developers to track circuit state changes and receive notifications on important events (like opening, closing, or half-opening a circuit). This feature provides better insight into the system’s health and makes it easier to react to circuit changes in real time.
Purgatory is fully typed and rigorously tested, which can make it easier to debug and integrate into larger, type-safe codebases.
Usage
Example with a context manager for an async API
from purgatory import AsyncCircuitBreakerFactory
circuitbreaker = AsyncCircuitBreakerFactory()
async with await circuitbreaker.get_breaker("my_circuit"):
...
Example with a decorator
from purgatory import AsyncCircuitBreakerFactory
circuitbreaker = AsyncCircuitBreakerFactory()
@circuitbreaker("another circuit")
async def function_that_may_fail():
...
Example with a context manager for a synchronous API
from purgatory import SyncCircuitBreakerFactory
circuitbreaker = SyncCircuitBreakerFactory()
with circuitbreaker.get_breaker("my_circuit"):
...
Circuit breakers states and monitoring
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.
Read More
You can read the full documentation of this library here.
Alternatives
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/
Why another Circuit Breaker implementation ?
Purgatory 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.
Metadata
Release files for purgatory 3.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| purgatory-3.0.2.tar.gz | 13.4 kB | Without provenance | Details for purgatory-3.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| purgatory-3.0.2-py3-none-any.whl | Python 3 | none | any | Details for purgatory-3.0.2-py3-none-any.whl |
Total release size: 35.0 kB
Release files / purgatory-3.0.2.tar.gz
| Download URL | purgatory-3.0.2.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8be0c0457884b6a61b95195fc0ef77b9062d1e072fbf15f48ea38b13ea595d2f
|
|
BLAKE2b-256 checksum How to use checksums |
b60a674b98378f2f1760ded1aa466e67d7396bd6c8352ae70b1960c4693a6c2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.29.7 CPython/3.12.16 Linux/7.0.0-1017-azure
|
Release files / purgatory-3.0.2-py3-none-any.whl
| Download URL | purgatory-3.0.2-py3-none-any.whl |
|---|---|
| Size | 21.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7fcebcd73413d040d9cff3b4fb23f1fc2b9fd4325082dba291c075544a55ca56
|
|
BLAKE2b-256 checksum How to use checksums |
82f61ad4ffae1ce51aa64283e03123bd8341bc8829c735f14949b330743f48eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.29.7 CPython/3.12.16 Linux/7.0.0-1017-azure
|
Security for purgatory 3.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.