Skip to main content

Circuit Breaker implementation for FastAPI.

Project description

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.

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

fastapi_cb-1.1.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_cb-1.1.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_cb-1.1.0.tar.gz.

File metadata

  • Download URL: fastapi_cb-1.1.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.4

File hashes

Hashes for fastapi_cb-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ebe664f8b508fbb93b81f4aa95d3bac3a539ade7a0f881e488c3b3ae70508b79
MD5 b1bc7aaaf0aae4d2fcecdf97584fcbaa
BLAKE2b-256 672e0363a1398271677c51fbff416b23e241f4559eb5b9c9488bc584327a5fc6

See more details on using hashes here.

File details

Details for the file fastapi_cb-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: fastapi_cb-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.4

File hashes

Hashes for fastapi_cb-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 295023d5782c943b8f4825630540915c5e0345dc91657807c5cc2c76862d650b
MD5 1fa330381b5cef226c961facd2d1fcb5
BLAKE2b-256 a99e1dbc5fb9bf6526d3456745092e5779e826a18325041aa7333314f3fa5770

See more details on using hashes here.

Supported by

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