API¶
pico_resilience.decorators ¶
Marker decorators: store the policy on the function and attach the matching interceptor via intercepted_by (same idiom as pico-pydantic).
retryable(_func=None, *, max_attempts=3, backoff_seconds=0.1, retry_on=(Exception,)) ¶
Retry on failure with exponential backoff. Sync or async. Raises RetryExhaustedError when every attempt failed.
Source code in src/pico_resilience/decorators.py
circuit_breaker(_func=None, *, failure_threshold=5, reset_timeout_seconds=30.0) ¶
Per-method circuit: opens after N consecutive failures (calls raise CircuitOpenError), half-opens after the reset timeout.
Source code in src/pico_resilience/decorators.py
timeout(seconds) ¶
Bound an async method with asyncio.timeout. Sync methods are rejected at import time — a thread cannot be cancelled, so a sync timeout would lie.
Source code in src/pico_resilience/decorators.py
pico_resilience.interceptors ¶
Resilience interceptors (pico-ioc MethodInterceptor singletons).
Chain rule: retry attempts after the first re-invoke the method directly, so interceptors inside retry's position are skipped on retries. Combine policies with @retryable as the TOP decorator (it attaches last and runs innermost): @cacheable/@circuit_breaker below it wrap the whole retry loop — the cache stores the final result and the circuit counts exhausted retries, not individual attempts.
RetryInterceptor ¶
Retries the method per its @retryable policy.
Source code in src/pico_resilience/interceptors.py
CircuitBreakerInterceptor ¶
Per-method circuit: closed -> open -> half-open -> closed.
Source code in src/pico_resilience/interceptors.py
TimeoutInterceptor ¶
Bounds async methods with asyncio.timeout.
Source code in src/pico_resilience/interceptors.py
pico_resilience.config ¶
Settings for the resilience interceptors (prefix resilience, zero-config).
ResilienceSettings dataclass ¶
enabled: false turns every interceptor into a pass-through.
Source code in src/pico_resilience/config.py
pico_resilience.exceptions ¶
Exceptions for pico-resilience.
PicoResilienceError ¶
RetryExhaustedError ¶
Bases: PicoResilienceError
Raised when a @retryable method fails on every attempt.
Attributes:
| Name | Type | Description |
|---|---|---|
method_name | The method that kept failing. | |
attempts | How many attempts were made. | |
last_error | The exception raised by the final attempt. |
Source code in src/pico_resilience/exceptions.py
CircuitOpenError ¶
Bases: PicoResilienceError
Raised when a call is rejected because the circuit is open.
Attributes:
| Name | Type | Description |
|---|---|---|
method_name | The protected method. | |
retry_after_seconds | Seconds until the circuit allows a trial call. |