Skip to main content

Requests Resilient

Wrapper around the requests python library to make it resilient to network failures.

Drop-in for the requests top-level API: swap the import and requests retry themselves on transient failures, with exponential backoff, jitter, and respect for a server's Retry-After.

Getting started

Synchronous requests

import requests_resilient

r = requests_resilient.get('https://google.com')
print(r.status_code)  # int, 200
print(r.text)  # str

For connection pooling, shared headers or auth, create a session instead of using the module-level functions:

from requests_resilient import ResilientSession, RetryConfig

session = ResilientSession(retry_config=RetryConfig(max_retries=5, backoff_base=0.5))
r = session.get('https://api.example.com/v1/items')

What gets retried

By default: 5xx responses, 429 Too Many Requests, and connection/timeout errors — and only on idempotent methods (GET, HEAD, OPTIONS, PUT, DELETE). POST and PATCH are left alone unless you pass retry_on_post=True, because retrying a non-idempotent request can duplicate a side effect.

Rate limits: Retry-After

When a retryable response carries a Retry-After header, that value is used as the wait instead of the computed backoff. Both wire formats from RFC 9110 are understood — Retry-After: 120 and Retry-After: Wed, 21 Oct 2026 07:28:00 GMT — and a malformed value falls back to the normal backoff rather than raising.

The server's value is honoured exactly: no jitter, and not added to the exponential backoff. It named a time, and retrying earlier than it asked is how a client earns a hard ban.

from requests_resilient import ResilientSession, RetryConfig

# Wait up to 5 minutes when a server asks us to; beyond that, hand the response back.
session = ResilientSession(retry_config=RetryConfig(retry_after_max=300.0))

# Or ignore the header entirely and always use the configured backoff.
session = ResilientSession(retry_config=RetryConfig(respect_retry_after=False))

If a server asks for longer than retry_after_max (default 120s), the response is returned to you rather than blocking the call. Sleeping less than the server asked practically guarantees another 429, and silently blocking a library call for an hour is worse than letting you decide: the response still carries the header, so you can queue the work, fail the job, or wait.

The parser is exported if you want it on its own:

from requests_resilient import parse_retry_after

parse_retry_after('120')                              # 120.0
parse_retry_after('Wed, 21 Oct 2026 07:28:00 GMT')    # seconds from now, never negative
parse_retry_after('soon')                             # None -> no usable hint

Asynchronous requests

Removed in v0.3.0. There is no async_get. For async HTTP with retry, use httpx with tenacity, or run the synchronous call in a thread so it does not block the event loop:

import asyncio
import requests_resilient

r = await asyncio.to_thread(requests_resilient.get, 'https://google.com')

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

requests_resilient-0.3.1.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

requests_resilient-0.3.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file requests_resilient-0.3.1.tar.gz.

File metadata

  • Download URL: requests_resilient-0.3.1.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for requests_resilient-0.3.1.tar.gz
Algorithm Hash digest
SHA256 88cb060aaf010d21ba2ec592f165121652c26380f0b00c92eb5b0a6dda95ebee
MD5 7dddd847ff080b5856f6c9f51ca01850
BLAKE2b-256 c41ccbdb324216573a5033bd2bea6dd8cfc390b4b7a6e880c2ff7d66f792d7a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for requests_resilient-0.3.1.tar.gz:

Publisher: publish.yml on LeonardoSanBenitez/requests_resilient

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file requests_resilient-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for requests_resilient-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33e1f78d758979c627d69ab04db7cf614521046e36e0fb81890fd4354339433e
MD5 5216db214a0e624d00d6314f5863ef39
BLAKE2b-256 edf5e7673be0420bfe84c52a147c07435037db4af64100743182931c78503a97

See more details on using hashes here.

Provenance

The following attestation bundles were made for requests_resilient-0.3.1-py3-none-any.whl:

Publisher: publish.yml on LeonardoSanBenitez/requests_resilient

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page