Registry / http-networking / purgatory

purgatory

JSON →
library3.0.1pypypi✓ verified 82d ago

A circuit breaker implementation for asyncio. Current version 3.0.1, requires Python >=3.9. Releases are sporadic.

pip install purgatory
INSTALL
IMPORT
SIG · PURGATORY
P
purgatory
http-networkingpythonv3.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AsyncCircuitBreakerFactory
from purgatory import AsyncCircuitBreakerFactory
from purgatory import CircuitBreaker
SyncCircuitBreakerFactory
from purgatory import SyncCircuitBreakerFactory
from purgatory import CircuitBreaker
Event
from purgatory import Event
from purgatory import CircuitBreaker

Basic usage of Purgatory's CircuitBreaker context manager.

import asyncio from purgatory import CircuitBreaker async def main(): breaker = CircuitBreaker( failure_threshold=5, recovery_timeout=30, half_open_max_calls=1 ) for _ in range(10): async with breaker: print("Call succeeded") asyncio.run(main())
Debug
Known issues
breakingVersion 3.0 changed the import path: CircuitBreaker is now directly importable from `purgatory` instead of `purgatory.circuit_breaker`.
fix
Change imports from `from purgatory.circuit_breaker import CircuitBreaker` to `from purgatory import CircuitBreaker`.
affects: >=3.0.0
gotchaThe `CircuitBreaker` context manager does NOT automatically retry. If the breaker is open, it raises `CircuitBreakerOpenError` immediately. You must implement retry logic yourself.
fix
Wrap the `async with breaker:` block in a try/except and implement exponential backoff retries.
affects: all
gotchaThe `failure_threshold` counts consecutive failures. A single success resets the counter. This differs from some other circuit breaker implementations (e.g., Hystrix) that use a sliding window.
fix
Be aware of the reset behavior; adjust threshold accordingly.
affects: all
Upgrade
Version history
3.0.1latest on PyPI · released Nov 2, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
26
OpenAI (training)
2
Resources
purgatory — pip install purgatory · libregistry