Skip to main content

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!

Metadata

Release files for retryhttp 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for retryhttp 1.5.0
File Size Uploaded
retryhttp-1.5.0.tar.gz 26.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for retryhttp 1.5.0
File Interpreter ABI Platform
retryhttp-1.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.7 kB

Release files / retryhttp-1.5.0.tar.gz

Download URL retryhttp-1.5.0.tar.gz
Size 26.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6ad975fef6603eba8acf6e4eaaeda8cf37d1db8527bb4bbf118ccde65f32cca0
BLAKE2b-256 checksum
How to use checksums
a0983148ad5abd7cfc5f34d519b81d617ed218f1c1a292444bcd5e388e79958f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / retryhttp-1.5.0-py3-none-any.whl

Download URL retryhttp-1.5.0-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ea01cf0b2f2a4c8755ac995dcc40b338102cb7965fd502376a95a8c61869ea0
BLAKE2b-256 checksum
How to use checksums
bebe4ade6ab2caeb01db0f273231ec94a390a5447fe5b4b3e42f244d52c7665b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

1.5.0 This release

2 release files

1.4.0

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page