Retry policy¶
RetryPolicy opts the client into transient-failure retries. Default-off — pass
retry_policy=RetryPolicy(...) to Dhis2Client and the underlying httpx
transport gets wrapped with exponential backoff, jitter, and Retry-After
support.
Only idempotent methods (GET, HEAD, PUT, DELETE, OPTIONS) retry by default. Set
retry_non_idempotent=True to also retry POST and PATCH — leave it off unless
the specific endpoint is known to be idempotent.
retry
¶
Retry policy + httpx transport wrapper for transient HTTP failures.
Default-off. Opt in by passing retry_policy=RetryPolicy(...) to
Dhis2Client — the client wraps its httpx transport with _RetryTransport
which retries on the configured status codes and on connection-level
errors (ConnectError, ReadTimeout, etc.) with exponential backoff + jitter.
Design:
- Only idempotent HTTP methods (GET, HEAD, PUT, DELETE, OPTIONS) retry by
default. POST / PATCH are skipped unless
retry_non_idempotent=True— double-writes can cause DHIS2-side duplicates (duplicate create, double delete, etc). Caller opts in explicitly when they know the endpoint is safe (analytics refresh kick-offs, for instance). - A server-provided
Retry-Afterheader (sent on 429 / 503) overrides the computed backoff for that attempt. - Exponential:
delay = min(max_delay, base_delay * backoff_factor ** (attempt - 1))with a ± jitter applied before sleeping.
Classes¶
RetryPolicy
¶
Bases: BaseModel
Retry config for transient HTTP failures.
Source code in packages/dhis2w-client/src/dhis2w_client/retry.py
Functions¶
compute_delay(attempt, *, rng=None)
¶
Compute the sleep before attempt attempt (1-based; compute_delay(1) is before the 2nd try).
Source code in packages/dhis2w-client/src/dhis2w_client/retry.py
Functions¶
build_retry_transport(policy, *, inner=None)
¶
Compose a retry-wrapped transport; defaults to wrapping a fresh AsyncHTTPTransport.