registry
@automindzsheets 01–77shadcn 4.x
SHEET 61

HTTP Retry (Python)

item / server / http

The one retrying HTTP client for Python server items: timeout, capped full-jitter backoff, Retry-After, status 0 when the request never landed, plus RateLimiter and TTLCache. Stdlib urllib.

type
item
files
2
registry deps
none
npm deps
none

installs

  • ~/backend/http_retry.py
  • ~/backend/tests/test_http_retry.py
  • Stdlib urllib only — no pip install, no env, nothing to mount
  • Never raises on an HTTP status; status 0 means the request never reached the server
  • Retry-After beats the jittered backoff, and both are capped

No env, no mount: import http_retry, then http_retry.get(url) or http_retry.post(url, json={...}, headers={...}); request(method, url, ...) for anything else. Every call returns a Response (status, lower-cased headers, body, .text, .json(), .ok) and never raises for an HTTP status — Linear, Stripe and Prospeo all put the reason for a 4xx in the body, so read res.ok and decide. status == 0 means the request never reached the server and res.error says why. Defaults: 15 s timeout, three attempts (retries=2), retry only on {0, 408, 425, 429, 500, 502, 503, 504}, full-jitter backoff from 0.5 s capped at 8 s, Retry-After (seconds or HTTP-date) winning when sent. Drop 0 from retry_on for a POST that must be sent at most once. RateLimiter(per_second).wait() and TTLCache(ttl_seconds, max_items=N) are per-process. urlopen, sleep, random and monotonic are keyword arguments, which is how the shipped test runs with no network. Logs method, URL without query string, status and attempt — never a header or body.

Variations

one state per section

No previews for this item yet.