Skip to main content

Retry potentially transient HTTP errors in Python.

Project description

RetryHTTP

Retry potentially transient HTTP errors in Python.

See documentation.

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 both requests, httpx and aiohttp natively, but could be customized to use with any library that raises exceptions for the conditions listed above.

Install

Install from PyPI:

pip install retryhttp  # Supports HTTPX, requests and aiohttp

You can also install support for only HTTPX or requests, if you would rather not install unnecessary dependencies:

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

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 safely retryable status codes (429, 500, 502, 503, 504), network errors,
# and timeouts, up to a total of 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! Bug fixes and minor tweaks can jump straight to a pull request. For more involved changes, open an issue and let's chat about your idea. Thanks for your contribution!

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-1.4.0.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

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

retryhttp-1.4.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file retryhttp-1.4.0.tar.gz.

File metadata

  • Download URL: retryhttp-1.4.0.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for retryhttp-1.4.0.tar.gz
Algorithm Hash digest
SHA256 9bba1ef1b46b67f251ac80b0ee6a846d93dcbbe8c49b7959cd1142fc6c393c99
MD5 ea1c58481dc451ccc0e16ba1ac93e58e
BLAKE2b-256 0080ac82d3d6c4b65fd752d9f5483d1ea3bbb0220ba9e51f26199c45f0e5039e

See more details on using hashes here.

File details

Details for the file retryhttp-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: retryhttp-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for retryhttp-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cdf77b92d2dfee599fb78b8c19d633eea53b9f529da9a4b9325213cc8f3841a4
MD5 ec41a201734f832aeca0e8b845814d1f
BLAKE2b-256 023310910709a90b5e19875ad5cc5fde88221c389dc75a379540670990388f68

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