Skip to content

Add configurable retry policies to the Python SDK - #110

Closed
Geoff-Robin wants to merge 6 commits into
prooflinedev:mainfrom
Geoff-Robin:main
Closed

Geoff-Robin wants to merge 6 commits into
prooflinedev:mainfrom
Geoff-Robin:main

Conversation

@Geoff-Robin

Copy link
Copy Markdown

Problem

The SDK’s retry behavior was hard-coded to four attempts for HTTP 429 and 503 responses. Users could not adjust the retry limit, statuses, backoff, or jitter for their environment.

Solution

Add a public, immutable RetryPolicy accepted by both ProoflineClient and AsyncProoflineClient.

It supports:

  • Maximum attempts
  • Configurable retryable HTTP statuses
  • Initial and maximum backoff
  • Backoff multiplier
  • Optional jitter

The default policy preserves the SDK’s existing behavior.

from proofline import ProoflineClient, RetryPolicy, SecretStr

policy = RetryPolicy(
    max_attempts=3,
    retryable_statuses=frozenset({429, 500, 503}),
    initial_backoff=0.5,
    backoff_multiplier=2,
    max_backoff=10,
    jitter=0.1,
)

client = ProoflineClient(
    SecretStr(token),
    retry_policy=policy,
)

Safety and behavior

  • Only GET requests are retried; POST requests remain single-attempt.
  • HTTP 401 and 403 cannot be configured as retryable.
  • Retry-After continues to take precedence over computed backoff.
  • Malformed or excessive Retry-After values do not trigger an early retry.
  • Caller deadlines continue to limit retry waits.
  • Sync and async clients use the same policy behavior.
  • Invalid settings consistently raise ValueError.

Proofline review

I ran Proofline on this PR and addressed several findings:

  • Validate individual status values before deduplicating them.
  • Convert oversized numeric configuration failures into ValueError.
  • Test deadline classification with non-default retry statuses.
  • Strengthen the installed-package smoke test so both clients must obey max_attempts=1.

A separate pre-existing response-body error-classification issue was left out of this focused change.

Verification

  • Unit and HTTP integration tests
  • Sync and async custom-policy coverage
  • Ruff lint and formatting checks
  • Mypy type checking
  • Wheel and source distribution builds
  • Installed-package smoke tests for both clients

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant