retryhttp 1.4.0


pip install retryhttp

  Latest version

Released: Oct 23, 2025


Meta
Author: Austin de Coup-Crank
Maintainer: Austin de Coup-Crank
Requires Python: >=3.9

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

License
  • OSI Approved :: Apache Software License

Programming Language
  • Python
  • Python :: 3
  • Python :: 3 :: Only
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13

Topic
  • Internet :: WWW/HTTP
  • Utilities

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!

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
pydantic
tenacity