Skip to content

Retry

sppyte.retry

Opt-in retry of transient failures for read requests.

Enable with Site(..., retry=True) or Site(..., retry=RetryOptions(...)). Reads (GET requests and CAML List.query) are retried; writes never are. Delays use exponential backoff with full jitter, random(0, min(max_delay, base_delay * 2**attempt)), unless the server sent Retry-After, in which case that wait is used as-is; if it exceeds RetryOptions.max_delay retrying stops and the error propagates.

RETRYABLE_STATUSES module-attribute

RETRYABLE_STATUSES = frozenset({429, 502, 503, 504})

HTTP statuses treated as transient by is_transient.

RetryOptions dataclass

RetryOptions(retries: int = 2, base_delay: float = 0.2, max_delay: float = 5.0, retry_on: Callable[[BaseException, int], bool] | None = None)

Settings for Site(retry=...).

retries class-attribute instance-attribute

retries: int = 2

Extra attempts after the first failure.

base_delay class-attribute instance-attribute

base_delay: float = 0.2

Base delay in seconds; doubles each attempt.

max_delay class-attribute instance-attribute

max_delay: float = 5.0

Upper bound on one delay, including a server-requested Retry-After.

retry_on class-attribute instance-attribute

retry_on: Callable[[BaseException, int], bool] | None = None

Decides whether a failed attempt is retried.

Receives the exception and the 1-based attempt number. Defaults to is_transient.

is_transient

is_transient(exc: BaseException) -> bool

Return whether an exception is worth retrying.

This is the default RetryOptions.retry_on: connection failures, timeouts, and SharePointError with status 429, 502, 503 or 504.

with_retry

with_retry(options: RetryOptions | None, attempt: Callable[[], T]) -> T

Run attempt, retrying on transient failure according to options.

Parameters:

Name Type Description Default
options RetryOptions | None

The retry policy; None runs attempt exactly once.

required
attempt Callable[[], T]

The operation to run.

required

Returns:

Type Description
T

The result of the first successful attempt.

Raises:

Type Description
Exception

the last failure, once retries are exhausted or the failure is not retryable.