Skip to main content

Retry potentially-transient HTTP errors.

Project description

retryhttp

Retry potentially-transient HTTP errors.

Note: This project is in beta status. The API may change significantly.

Overview

Under the hood, retryhttp extends tenacity with custom retry and wait strategies, as well as a decorator that wraps tenacity.retry() with sensible defaults.

Supports both requests and httpx.

Quickstart

Install from git:

pip install git+https://github.com/austind/retryhttp.git@main
import httpx
from retryhttp import retry_http_errors

# See Default Behavior section below for what happens here
@retry_http_errors()
def get_example():
    response = httpx.get("https://example.com/")
    response.raise_for_status()

Default Behavior

By default, retryhttp.retry_http_errors() retries the following conditions:

  • If the response status code is:
    • 429 Too Many Requests
    • 500 Internal Server Error
    • 502 Bad Gateway
    • 503 Service Unavailable
    • 504 Gateway Timeout
  • If one of the following other exceptions is raised:
    • Network errors
      • httpx.ConnectError
      • httpx.ReadError
      • httpx.WriteError
      • requests.ConnectionError
    • Network timeouts
      • httpx.TimeoutError
      • requests.Timeout

Based on which error is raised, a different wait strategy is used:

  • 429 Too Many Requests: Respect the Retry-After header, if present. If not, fall back to tenacity.wait_exponential()
  • 5xx Server Errors: tenacity.wait_exponential_jitter()
  • Network errors: tenacity.wait_exponential()
  • Network timeouts: tenacity.wait_exponential_jitter()

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

retryhttp-0.1.0.tar.gz (18.1 kB view hashes)

Uploaded Source

Built Distribution

retryhttp-0.1.0-py3-none-any.whl (15.0 kB view hashes)

Uploaded Python 3

Supported by

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