Skip to main content

A Python decorator respecting Retry-After headers

Project description

Retry After

A lightweight, dependency-free Python decorator to automatically handle HTTP 429 Rate Limits and respect Retry-After headers. Built for modern APIs, web scrapers etc, supporting both sync and async clients.

Table of contents

Quick Start

Synchronous Client

import httpx
from retryafter import auto_retry

@auto_retry(max_attempts=3, default_wait=2.0)
def fetch_api_data(url: str) -> dict:
    response = httpx.get(url)
    response.raise_for_status()  # This triggers the retry logic on 429
    return response.json()

Asynchronous Client

import httpx
import anyio
from retryafter import auto_retry

@auto_retry(max_attempts=5)
async def fetch_api_data_async(url: str) -> dict:
    async with httpx.AsyncClient() as client:
        response = await client.get(url)
        response.raise_for_status()
        return response.json()

Configuration

You can customize the decorator behavior using the following parameters:

Parameter Type Default Description
max_attempts int 3 The maximum number of attempts before raising the original exception.
default_wait float 2.0 Fallback wait time (in seconds) if the server does not return a Retry-After header.
reraise bool True If True, bubbles up the original httpx.HTTPStatusError instead of tenacity's RetryError.

License

MIT License © 2026 Dawid Wielechowski

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

retryafter-0.2.0.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

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

retryafter-0.2.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file retryafter-0.2.0.tar.gz.

File metadata

  • Download URL: retryafter-0.2.0.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for retryafter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0f24bdcf8582a6dc1752153406077aaf364016a02b32efe6091ea33ef06f0ebe
MD5 595ac5150ff537e9a7d55a1e1d473da7
BLAKE2b-256 0eb7b391cd1dcd9bfabb4f09f36aa5a217bd336367f9fc12635e53b56081f1bf

See more details on using hashes here.

File details

Details for the file retryafter-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: retryafter-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for retryafter-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a72094da2dfa1c7e7ddc255ca29f98624eb4652c7c24b41337bde8b2cd9a5b4
MD5 6ad93ca4c0890b0dd954f2118922a4d6
BLAKE2b-256 dc9a71b5ad481207aa2726e2d1fcfe1a95deec10ea709dd2e0cf7ae22f68a3d2

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