Skip to main content

aioretry

Handy decorator to set retry policies for async callables with some useful features

Usage examples

@retry(
    tries=5,
    allowed_exceptions=(RuntimeError,),
    intervals=(5, 7, 10),
    fail_cb=make_request_callback,
)
async def make_request(address, client):

    ... http request code goes here...

    if response.status_code >= 300:
        raise RuntimeError()

def make_request_callback(address, client)
    ...
  • 5 retries will be performed
  • with 5, 7, 10, 10 and 10 seconds interval between retries. I.e. if intervals tuple length more than tries number, the last tuple interval will be used for the rest of the tries.
  • make_request_callback() synchronous function will be called if all attempts are failed
  • The accepted exceptions tuple allows you to control when to retry.
  • You can optionally pass a custom logger: logging.Logger to the decorator within a logger= parameter. Otherwise retry_decorator logger will be created to log retries.

Other possible ways to use this decorator:

@retry(5, (MyCustomError,), (5, 7, 10), make_request_callback)

@retry(3, (MyCustomError,), (1,))

# this actually will either successfully return or fail on first exception occured
@retry(3)

Look into tests.py to see more on usage.

Installation

Available as a package on pypi:

pip install aioretry-decorator

Or install it directly from GitHub:

pip install git+https://github.com/remort/aioretry.git#egg=aioretry_decorator

Release files for aioretry-decorator 1.0.6

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

Source distribution (sdist)

Source distribution for aioretry-decorator 1.0.6
File Size Uploaded
aioretry_decorator-1.0.6.tar.gz 2.8 kB Details

Release files / aioretry_decorator-1.0.6.tar.gz

Download URL aioretry_decorator-1.0.6.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d0d150dd6fe42a5758f0b5778f7b8316eb1e08b4da76e8b42f3cf6f3d9a97fdc
BLAKE2b-256 checksum
How to use checksums
61790fcb5acc69079e464daf606dfe69a952623d8d48ea28bef98ed42f2450a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

1.0.6 This release

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

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