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 requests, httpx, httpx2 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[httpx2]  # Supports only HTTPX2
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.5.0.tar.gz (26.1 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.5.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: retryhttp-1.5.0.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for retryhttp-1.5.0.tar.gz
Algorithm Hash digest
SHA256 6ad975fef6603eba8acf6e4eaaeda8cf37d1db8527bb4bbf118ccde65f32cca0
MD5 13d65f11bae7e2b6c49ac6f1cf7f95e3
BLAKE2b-256 a0983148ad5abd7cfc5f34d519b81d617ed218f1c1a292444bcd5e388e79958f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: retryhttp-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for retryhttp-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ea01cf0b2f2a4c8755ac995dcc40b338102cb7965fd502376a95a8c61869ea0
MD5 9daf2774cdf83ac335f6dca4827f361b
BLAKE2b-256 bebe4ade6ab2caeb01db0f273231ec94a390a5447fe5b4b3e42f244d52c7665b

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