Skip to main content

Retry commonly transient HTTP errors.

Project description

RetryHTTP

Retry potentially transient HTTP errors in Python.

See documentation.

Note: This project is in beta status. The API may change significantly. Please open a discussion if you see something that you think should change!

Overview

Several HTTP errors are often transient, and might succeed if retried:

  • HTTP status codes
    • 429 Too Many Requests (rate limited)
    • 500 Internal Server Error
    • 502 Bad Gateway
    • 503 Service Unavailable
    • 504 Gateway Timeout
  • Network errors
  • Timeouts

This project aims to simplify retrying these, by extending tenacity with custom retry and wait strategies, as well as a custom decorator. Defaults are sensible for most use cases, but are fully customizable.

Supports exceptions raised by both requests and httpx.

Install

Install

Install from PyPI:

# Supports both HTTPX and requests
pip install retryhttp

You can also install support for only HTTPX or requests:

pip install retryhttp[httpx] # Supports only HTTPX
pip install retryhttp[requests] # Supports only requests

Or, install the latest development snapshot from git:

pip install git+https://github.com/austind/retryhttp.git@develop

Quickstart

import httpx
from retryhttp import retry

# Retries retryable status codes (429, 500, 502, 503, 504), network errors,
# and timeouts, up to 3 times, with appropriate wait strategies for each
# type of error. All of these behaviors are customizable.
@retry
def example():
    response = httpx.get("https://example.com/")
    response.raise_for_status()
    return response.text

Contributing

Contributions welcome! Open a discussion and let's chat about your idea. Looking forward to working with you!

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.2.0.tar.gz (22.3 kB view hashes)

Uploaded Source

Built Distribution

retryhttp-0.2.0-py3-none-any.whl (15.1 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