PyBreaker gives you three distinct ways to wrap code with a circuit breaker. All three share the same underlying state machine — they differ only in how you apply them. Pick the pattern that best matches your codebase style and constraints.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.
Decorator Pattern
The decorator pattern is the most idiomatic PyBreaker usage. Apply@db_breaker directly to a function definition, and every subsequent call to that function automatically passes through the circuit breaker.
@db_breaker uses functools.wraps, so the wrapped function’s __name__, __doc__, and other metadata are fully preserved. Introspection tools and logging that rely on func.__name__ will continue to see the original function name.
Direct Call Pattern
Usecb.call() when you cannot or do not want to modify the function definition — for example, with third-party functions, lambdas, or dynamically resolved callables.
CircuitBreaker.call(func, *args, **kwargs) -> T
All positional and keyword arguments after func are forwarded to the function as-is. The return value is whatever func returns.
Context Manager Pattern
Usecb.calling() to protect an inline block of code without extracting it into a separate function. The with statement executes the block according to the circuit breaker’s current state rules.
Generator Functions
The circuit breaker can guard generator functions. Failures that occur inside the generator body — including during iteration — are correctly handled and counted against the failure threshold.Choosing a Pattern
- Decorator
- .call()
- .calling()
Best for: Functions you own and want permanently protected.
- Applied once at definition time — no call-site changes needed
- Preserves function metadata via
functools.wraps - Works with regular functions and generator functions
- Most readable when the same function is always called through the breaker
