API reference
Policies
Policy,AsyncPolicy- Unified resilience containers; use
Policy(retry=Retry(...)) .call(func, on_metric=None, on_log=None, operation=None, abort_if=None, sleep=None, before_sleep=None, sleeper=None, on_attempt_start=None, on_attempt_end=None).execute(func, on_metric=None, on_log=None, operation=None, abort_if=None, sleep=None, before_sleep=None, sleeper=None, on_attempt_start=None, on_attempt_end=None, capture_timeline=False).context(on_metric=None, on_log=None, operation=None, abort_if=None, sleep=None, before_sleep=None, sleeper=None, on_attempt_start=None, on_attempt_end=None)Retry,AsyncRetry- Retry components with
result_classifiersupport - Support per-attempt timeouts via
attempt_timeout_s .call(..., abort_if=None, sleep=None, before_sleep=None, sleeper=None, on_attempt_start=None, on_attempt_end=None).execute(..., abort_if=None, sleep=None, before_sleep=None, sleeper=None, on_attempt_start=None, on_attempt_end=None, capture_timeline=False).context(..., abort_if=None, sleep=None, before_sleep=None, sleeper=None, on_attempt_start=None, on_attempt_end=None).from_config(config, classifier=...)RetryPolicy,AsyncRetryPolicy- Backward-compatible sugar for
Policy(retry=Retry(...)) .call(..., abort_if=None, sleep=None, before_sleep=None, sleeper=None, on_attempt_start=None, on_attempt_end=None).execute(..., abort_if=None, sleep=None, before_sleep=None, sleeper=None, on_attempt_start=None, on_attempt_end=None, capture_timeline=False).context(..., abort_if=None, sleep=None, before_sleep=None, sleeper=None, on_attempt_start=None, on_attempt_end=None)CircuitBreaker- State machine with open/half-open/closed transitions
failure_threshold=5failures inwindow_s=60.0seconds to openrecovery_timeout_s=30.0before half-open probetrip_onset of ErrorClass values that count (default: TRANSIENT, SERVER_ERROR)class_thresholdsper-class override thresholdsclockoptional monotonic clock override- Use with
Policy(circuit_breaker=...) CircuitStateenum
Budgets
Budget(max_retries, window_s)for shared retry limits across policies
Decorator
retry- Defaults:
classifier=default_classifier,strategy=decorrelated_jitter(max_s=5.0) - Works on sync and async callables
Classifiers
default_classifierstrict_classifierhttp_classifier,http_retry_after_classifiersqlstate_classifier,pyodbc_classifier- Optional extras:
aiohttp_classifier,grpc_classifier,boto3_classifier,redis_classifier,urllib3_classifier Classificationdataclass for structured classifier outputs
Strategies
decorrelated_jitterequal_jittertoken_backoffretry_after_oradaptiveBackoffContextfor context-aware strategy functions
Errors
ErrorClassenumCircuitOpenErrorfail-fast error when breaker is openStopReasonenumRetryExhaustedErrorterminal error (result-based exhaustion)AbortRetryErrorcooperative abort signal (alias:AbortRetry)- Marker exceptions:
PermanentError,RateLimitError,ConcurrencyError,ServerError
Outcomes
RetryOutcome[T]fromexecute()with attempts, stop_reason, and last error infoRetryOutcome.next_sleep_swhen retries are deferred via a sleep handlerRetryOutcome.timelinecontains aRetryTimelinewhencapture_timeline=TrueRetryTimelinewithTimelineEvententries (attempt, event, stop_reason, cause, sleep_s, elapsed_s)capture_timelineacceptsTrueor aRetryTimelineinstance to reuse a collector
Metrics helpers
prometheus_metric_hook(counter)otel_metric_hook(meter, name="redress_attempts")redress.contrib.otel.otel_hooks(tracer=None, meter=None)(spans + metrics)
Events
EventNameenum (redress.events.EventName) for hook event constantsStopReasonenum is re-exported fromredress.events
Sleep handlers
SleepDecisionenum (sleep,defer,abort)SleepFnfor custom sleep handling (decide sleep/defer/abort)BeforeSleepHook/AsyncBeforeSleepHookrun right before an actual sleepSleeperFn/AsyncSleeperFnreplace the actual sleep call
Testing utilities
Available under redress.testing:
DeterministicStrategy,instant_retries,no_retriesRecordingPolicy,FakePolicyFakeCircuitBreaker,BreakerDecision