Skip to main content

Resilient HTTP client with automatic retries and backoff.

Project description

philiprehberger-http-retry

Resilient HTTP client with automatic retries and backoff.

Install

pip install philiprehberger-http-retry

Usage

from philiprehberger_http_retry import resilient_get, resilient_post, Session

Simple Requests

# GET request with default retries (3 attempts, exponential backoff)
response = resilient_get("https://api.example.com/data")
print(response.read().decode())

# POST with JSON body
response = resilient_post(
    "https://api.example.com/items",
    json_data={"name": "widget", "count": 5},
)

Session with Defaults

session = Session(
    base_url="https://api.example.com",
    default_headers={"Authorization": "Bearer token123"},
    retries=5,
    timeout=15,
)

response = session.get("/users")
response = session.post("/users", json_data={"name": "Alice"})

Custom Retry Configuration

from philiprehberger_http_retry import resilient_request

response = resilient_request(
    "PUT",
    "https://api.example.com/resource/1",
    data=b'{"status": "active"}',
    headers={"Content-Type": "application/json"},
    retries=5,
    backoff=True,
    timeout=60,
    retry_on=(429, 500, 502, 503, 504),
)

Error Handling

from philiprehberger_http_retry import resilient_get, RetryExhaustedError

try:
    response = resilient_get("https://unreliable-api.example.com/data")
except RetryExhaustedError as err:
    print(f"Failed after {err.attempts} attempts: {err.last_error}")

API

Function / Class Description
resilient_request(method, url, **kwargs) Core retry function. Supports data, headers, retries, backoff, timeout, retry_on.
resilient_get(url, **kwargs) GET convenience wrapper around resilient_request.
resilient_post(url, data=None, json_data=None, **kwargs) POST wrapper. Auto-serializes json_data and sets Content-Type.
Session(base_url, default_headers, retries, backoff, timeout, retry_on) Stores defaults. Methods: get(path), post(path).
RetryExhaustedError Raised after all retries fail. Attributes: .attempts, .last_error.

License

MIT

Project details


Download files

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

Source Distribution

philiprehberger_http_retry-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_http_retry-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_http_retry-0.1.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_http_retry-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9084a322f434023495b5596e1a85bdbc769ae75deda61fccf34fa8a839bb1afb
MD5 3ef4dc0a9c716e3955bd9b118a014c62
BLAKE2b-256 f6b87f3f5fcff0e5a745b9ed94237d64d811d0ec21abef354c2aa495adfba72b

See more details on using hashes here.

File details

Details for the file philiprehberger_http_retry-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_http_retry-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 572734e44d3a3ea47e3996946097e5e507322b2072e069dcdfa57945406e6009
MD5 c94a9657db82d2548e97ac29f0d6e9e4
BLAKE2b-256 24c8de3e5df65982a4444b980de52168c9c846641425a23033863268a5884648

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page