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=...) - Policy admissions are released on cancellation or an escaping exception when no final breaker outcome was recorded; cancellation and process-exit exceptions propagate unchanged.
- Only the execution that owns the current half-open probe can complete or release it. Rejected calls and preflight aborts do not alter another execution's admission.
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, *, label_names=None)(uses the counter's declared label schema)otel_metric_hook(meter, name="redress_attempts")redress.contrib.otel.otel_hooks(tracer=None, meter=None)(spans + metrics)
Contrib integrations
Contrib modules are optional integrations built on top of the core retry and policy APIs. They are supported public APIs, but they also track third-party ecosystems that evolve independently. Prefer the documented helper functions and wrappers over depending on internal implementation details.
redress.contrib.aiohttp.AsyncRetryingAiohttpSession(session, policy, ...)(async session wrapper)redress.contrib.aiohttp.arequest_with_retry(...)(async request wrapper)redress.contrib.aiohttp.default_operation(method, url)(METHOD + path)redress.contrib.aiohttp.default_result_classifier(response)(429/408/409/5xx mapper with Retry-After support)redress.contrib.aiohttp.is_idempotent_method(method)(HTTP method guard helper)redress.contrib.asgi.retry_middleware(...)(generic Starlette-style ASGI middleware helper)redress.contrib.asgi.default_operation(request)/scope_operation(request)(METHOD + scope["path"])redress.contrib.asgi.is_idempotent_request(request)(HTTP idempotency guard helper)redress.contrib.celery.execute_task_with_retry(task, policy, func, ...)(run task bodies throughpolicy.execute(...)with deferred sleeps)redress.contrib.celery.default_operation(task)(task name helper)redress.contrib.celery.default_retry_kwargs(outcome, task)(countdown/excmapping fortask.retry(...))redress.contrib.celery.defer_sleep(...)(SleepDecision.DEFERhelper for external schedulers)redress.contrib.fastapi.retry_middleware(...)(FastAPI/Starlette middleware helper)redress.contrib.fastapi.default_operation(request)(method + route path)redress.contrib.httpx.RetryingHttpxClient(client, policy, ...)(sync wrapper class)redress.contrib.httpx.AsyncRetryingHttpxClient(client, policy, ...)(async wrapper class)redress.contrib.httpx.request_with_retry(...)(sync request wrapper)redress.contrib.httpx.arequest_with_retry(...)(async request wrapper)redress.contrib.httpx.default_result_classifier(response)(429/408/409/5xx mapper with Retry-After support)redress.contrib.httpx.is_idempotent_method(method)(HTTP method guard helper)redress.contrib.requests.RetryingRequestsSession(session, policy, ...)(sync session wrapper)redress.contrib.requests.request_with_retry(...)(sync request wrapper)redress.contrib.requests.default_operation(method, url)(METHOD + path)redress.contrib.requests.default_result_classifier(response)(429/408/409/5xx mapper with Retry-After support)redress.contrib.requests.is_idempotent_method(method)(HTTP method guard helper)redress.contrib.grpc.unary_unary_client_interceptor(...)(sync unary-unary client interceptor factory)redress.contrib.grpc.aio_unary_unary_client_interceptor(...)(async unary-unary client interceptor factory)redress.contrib.grpc.default_operation(call_details)(operation tag from RPC method path)redress.contrib.grpc.rpc_service_name(call_details)/rpc_method_name(call_details)(RPC name helpers)redress.contrib.openai.openai_classifier(exc)/openai_aware_backoff(...)(OpenAI SDK exception mapping + Retry-After-aware backoff helper; useOpenAI(max_retries=0))redress.contrib.anthropic.anthropic_classifier(exc)/anthropic_aware_backoff(...)(Anthropic SDK exception mapping + Retry-After-aware backoff helper; useAnthropic(max_retries=0))redress.contrib.prometheus.prometheus_hooks(*, events, retry_sleep_seconds=None, event_labels=None, retry_sleep_labels=None)(Prometheus metric hook adapter; see label schemas)redress.contrib.datadog.datadog_hooks(statsd=None, prefix="redress", constant_tags=None)(DogStatsD metric hook adapter)redress.contrib.sentry.sentry_hooks(sentry=None, capture_terminal=True)(Sentry breadcrumb/log hook adapter)- Note: ASGI contrib targets
request/call_nextmiddleware shape, not raw(scope, receive, send).
The HTTPX request helpers and client wrappers snapshot buffered body values before
entering the policy and give each attempt fresh containers. content accepts
bytes, str, or None; JSON/form containers and multipart parts must contain
buffered values. Iterators, async iterators, file objects (including seekable
files), arbitrary objects, cyclic containers, and mappings with duplicate keys
raise TypeError before any request or policy attempt. For repeated form fields,
use list values; for repeated uploads, use a list of (name, part) pairs.
This applies even when the policy allows only one
attempt. A true skip_if sends once without validation or policy execution.
See request body replay for the supported
types, stream migration example, and requests/aiohttp limitations.
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