Documentation Index
Fetch the complete documentation index at: https://mintlify.com/danielfm/pybreaker/llms.txt
Use this file to discover all available pages before exploring further.
CircuitBreakerListener is the base class for event hooks that observe a
CircuitBreaker instance’s activity. Subclass it and
override only the methods you need — the base class provides no-op
implementations for all callbacks, so unimplemented methods are silently
ignored. Multiple listeners can be registered on a single breaker and all are
notified for every event.
Callbacks
before_call(cb, func, *args, **kwargs) → None
Called immediately before the circuit breaker cb attempts to invoke
func. Use this hook for pre-call logging, distributed tracing spans, or
metrics timers.
The circuit breaker instance that is about to make the call.
The function that is about to be called.
The positional and keyword arguments that will be forwarded to
func.failure(cb, exc) → None
Called when a function invocation raises an exception that is not in the
breaker’s exclusion list (i.e., cb.is_system_error(exc) returns True).
This callback fires before the state transition logic runs, so it is called
regardless of whether the failure actually trips the breaker.
The circuit breaker instance that recorded the failure.
The exception that was raised by the guarded function.
success(cb) → None
Called when a guarded function invocation completes without raising a
system error. This includes calls where an excluded exception is raised — the
breaker treats those as successes for counter purposes.
The circuit breaker instance that recorded the success.
state_change(cb, old_state, new_state) → None
Called whenever the circuit breaker transitions to a new state. This happens
when the breaker opens after hitting fail_max, enters half-open after the
reset timeout, or closes after reaching success_threshold.
The circuit breaker instance whose state changed.
The previous state object. May be
None on the very first state
notification after the listener is attached, when no prior state exists in
the listener’s context.The newly entered state object. The
name attribute returns the
human-readable state string ('closed', 'open', or 'half-open').Example Implementation
Registering Listeners
Listeners can be attached at construction time via thelisteners parameter,
or dynamically at runtime using add_listener / add_listeners. See the
Event Listeners guide for full usage examples and
patterns.