Skip to main content

fastapi-cb

fastapi-cb is a Python implementation of the Circuit Breaker pattern, described in Michael T. Nygard's book Release It!_.

Circuit breakers exist to allow one subsystem to fail without destroying the entire system. This is done by wrapping dangerous operations (typically integration points) with a component that can circumvent calls when the system is not healthy.

This project is a fork of aiobreaker by Alexander Lyon that add support for integration with FastAPI.

Features

  • Works well with FastAPI framework
  • Configurable list of excluded exceptions (e.g. business exceptions)
  • Configurable failure threshold and reset timeout
  • Support for several event listeners per circuit breaker
  • Can guard generator functions
  • Functions and properties for easy monitoring and management
  • asyncio support
  • Optional redis backing
  • Synchronous and asynchronous event listeners

Requirements

All you need is python 3.8 or higher.

Installation

To install, simply download from pypi:

pip install fastapi_cb

Usage

The first step is to create an instance of CircuitBreaker for each integration point you want to protect against.

from fastapi_cb import CircuitBreaker

# Used in database integration points
db_breaker = CircuitBreaker(fail_max=5, reset_timeout=timedelta(seconds=60))

@db_breaker
async def outside_integration():
    """Hits the api"""
    ...

At that point, go ahead and get familiar with the documentation.

Release files for fastapi-cb 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-cb 1.1.0
File Size Uploaded
fastapi_cb-1.1.0.tar.gz 16.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-cb 1.1.0
File Interpreter ABI Platform
fastapi_cb-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.7 kB

Release files / fastapi_cb-1.1.0.tar.gz

Download URL fastapi_cb-1.1.0.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ebe664f8b508fbb93b81f4aa95d3bac3a539ade7a0f881e488c3b3ae70508b79
BLAKE2b-256 checksum
How to use checksums
672e0363a1398271677c51fbff416b23e241f4559eb5b9c9488bc584327a5fc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.4

Release files / fastapi_cb-1.1.0-py3-none-any.whl

Download URL fastapi_cb-1.1.0-py3-none-any.whl
Size 20.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
295023d5782c943b8f4825630540915c5e0345dc91657807c5cc2c76862d650b
BLAKE2b-256 checksum
How to use checksums
a99e1dbc5fb9bf6526d3456745092e5779e826a18325041aa7333314f3fa5770
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.4

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page