Skip to main content

retrymax

Tiny retry decorator for Python, works for sync and async functions, with optional verbose output and callback hooks.


Installation

pip install retrymax

Features

  • Retry synchronous or asynchronous functions
  • Optional exponential backoff
  • Optional verbose output to see retry attempts
  • Optional callback hook for custom actions on retry
  • Safe handling of exceptions, only retries specified exceptions

Usage

Synchronous example

from retrymax import retry

@retry(times=3, delay=1, verbose=True)
def fetch_data():
    print("Trying to fetch data...")
    raise ValueError("Failed!")

try:
    fetch_data()
except ValueError:
    print("All retries failed!")

Output:

Trying to fetch data...
[retrymax] Attempt 1 failed: Failed!
Trying to fetch data...
[retrymax] Attempt 2 failed: Failed!
Trying to fetch data...
[retrymax] Attempt 3 failed: Failed!
All retries failed!

Asynchronous example

import asyncio
from retrymax import retry

@retry(times=3, delay=0.5, verbose=True)
async def fetch_async():
    print("Trying async fetch...")
    raise ValueError("Async fail!")

async def main():
    try:
        await fetch_async()
    except ValueError:
        print("All async retries failed!")

asyncio.run(main())

Output:

Trying async fetch...
[retrymax] Attempt 1 failed: Async fail!
Trying async fetch...
[retrymax] Attempt 2 failed: Async fail!
Trying async fetch...
[retrymax] Attempt 3 failed: Async fail!
All async retries failed!

Using a callback hook

from retrymax import retry

def my_callback(exception, attempt):
    print(f"[callback] Retry {attempt} failed: {exception}")

@retry(times=3, delay=0.5, verbose=True, on_retry=my_callback)
def fetch_with_callback():
    print("Attempting fetch with callback...")
    raise ValueError("Failed again!")

try:
    fetch_with_callback()
except ValueError:
    print("All retries failed with callback!")

Output:

Attempting fetch with callback...
[retrymax] Attempt 1 failed: Failed again!
[callback] Retry 1 failed: Failed again!
Attempting fetch with callback...
[retrymax] Attempt 2 failed: Failed again!
[callback] Retry 2 failed: Failed again!
Attempting fetch with callback...
[retrymax] Attempt 3 failed: Failed again!
[callback] Retry 3 failed: Failed again!
All retries failed with callback!

Parameters

  • times (int): Number of retry attempts (default: 3)
  • delay (float): Delay between retries in seconds (default: 0)
  • backoff (str or None): "exp" for exponential backoff (default: None)
  • exceptions (tuple): Exceptions to catch and retry (default: (Exception,))
  • verbose (bool): Print retry attempts (default: False)
  • on_retry (callable): Optional callback called on each retry with (exception, attempt)

License

MIT License


Notes

  • Works with Python 3.8+
  • Supports both synchronous and asynchronous functions
  • Safe and consistent retry behavior
  • Perfect for network calls, flaky APIs, or any operation that may fail intermittently

Metadata

Release files for retrymax 0.1.2

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

Source distribution (sdist)

Source distribution for retrymax 0.1.2
File Size Uploaded Provenance Actions
retrymax-0.1.2.tar.gz 4.1 kB Without provenance Details for retrymax-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 8.0 kB

Release files / retrymax-0.1.2.tar.gz

Download URL retrymax-0.1.2.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b86b344d155c3541e94f4a93ce359c7eea9ffe6e421d6c2dbd3a9f34862880c4
BLAKE2b-256 checksum
How to use checksums
d7f761ab6ca05a3bf9b84e3b17ee906df16b60b20c305b1fa3925e9f6da8209a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / retrymax-0.1.2-py3-none-any.whl

Download URL retrymax-0.1.2-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
913c99c113dc4b96bf1e70f276a2e76837e7668fe7f05ab872d4497e6e550423
BLAKE2b-256 checksum
How to use checksums
7aef8c08e7da3d2359aa3cfe76a27c8d1c5db78708d0a37893aa8eb11346c640
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Security for retrymax 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

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