Skip to main content

A circuit breaker implementation for asyncio

Project description

Documentation Continuous Integration Status Code Coverage Report

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 an 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.

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.

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

purgatory-3.0.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

purgatory-3.0.1-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file purgatory-3.0.1.tar.gz.

File metadata

  • Download URL: purgatory-3.0.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.19.3 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for purgatory-3.0.1.tar.gz
Algorithm Hash digest
SHA256 c4ce9b93f7a54244bea6aa281af36767ff91bbd9665591cb46fb9cf89bf18d47
MD5 e4e581c7e62a7d573f7cb455996c039d
BLAKE2b-256 21e49d33c714ea9161448ce8b05d66fe139fb20d55df4c1a3855c1901bc012ac

See more details on using hashes here.

File details

Details for the file purgatory-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: purgatory-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.19.3 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for purgatory-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ee8ac2d949b09ebacc8a58b947115d49518593492cad84c14f0feedd1b22a21
MD5 83bff01ff639cfe2f19039f9a5515d4d
BLAKE2b-256 5d6745778e3bf3af6a401ec94a19efe649a81fe451cd0964dfa8d8d89233f9fa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page