Resilient Circuit is a powerful resilience library for building fault-tolerant Python applications. It provides implementations of the Circuit Breaker and Retry patterns, with optional PostgreSQL support for distributed systems.
Perfect for microservices, distributed systems, and any application that needs to gracefully handle external service failures.
Getting Started
User Guide
Reference
Key Featuresο
- π Circuit Breaker Pattern
Prevents cascading failures by stopping calls to failing services
- π Retry with Backoff
Automatically retries failed operations with exponential or fixed backoff
- ποΈ PostgreSQL Storage
Optional distributed state management for multi-instance deployments
- π― Composable Policies
Chain multiple resilience patterns together with SafetyNet
- π Pythonic API
Clean decorator-based syntax that feels natural in Python
- π State Monitoring
Track circuit breaker state and execution history
- β‘ Production Ready
Battle-tested with comprehensive test coverage
Quick Exampleο
from datetime import timedelta from fractions import Fraction from resilient_circuit import CircuitProtectorPolicy # Create a circuit breaker circuit_breaker = CircuitProtectorPolicy( resource_key="payment_service", cooldown=timedelta(seconds=30), failure_limit=Fraction(3, 10) # Trip after 30% failure rate ) @circuit_breaker def process_payment(amount): # Your payment logic here return payment_api.charge(amount)
For distributed systems with PostgreSQL:
# Set environment variables # RC_DB_HOST=localhost # RC_DB_NAME=resilient_circuit_db # RC_DB_PASSWORD=secret # All instances share the same circuit breaker state! circuit_breaker = CircuitProtectorPolicy( resource_key="shared_payment_service" )
Why Resilient Circuit?ο
For Distributed Systems
When you have multiple instances of a service, you want them all to coordinate failure handling. Resilient Circuitβs PostgreSQL backend ensures all instances see the same circuit breaker state, preventing cascading failures across your entire infrastructure.
Production-Grade Reliability
β 91/91 tests passing (100% test coverage)
β Works with and without PostgreSQL
β Automatic fallback to in-memory storage
β Thread-safe operations with PostgreSQL row locking
β Comprehensive error handling
Developer Friendly
Clean, intuitive API
Excellent documentation
Type hints throughout
Clear error messages
Use Casesο
- Microservices
Coordinate circuit breakers across service instances
- External APIs
Protect against third-party service outages
- Database Calls
Handle temporary database connection issues
- Message Queues
Gracefully handle queue connection failures
- Cloud Services
Resilience for AWS, GCP, Azure service calls
Installationο
Basic installation:
pip install resilient-circuit
With PostgreSQL support for distributed systems:
pip install resilient-circuit[postgres]
Whatβs Next?ο
New to Resilient Circuit? Start with the Quick Start guide
Setting up PostgreSQL? See the PostgreSQL Storage for Distributed Systems guide
Building distributed systems? Check out Distributed Systems
Need API details? View the API Reference reference
Licenseο
Resilient Circuit is distributed under the Apache Software License 2.0.