the-retry
Retry decorator for both synchronous and asynchronous functions.
Features
- No external dependencies.
- Supports asyncio. Works with both synchronous and asynchronous functions.
- Exponential backoff with jitter.
- Able to call custom function or await custom coroutine on exception occurs.
Installation
pip install the-retry
Decorator parameters
Arguments:
expected_exception: exception or tuple of exceptions (default BaseException).
Keyword arguments:
attempts: how much times the function will be retried, value -1 is infinite (default 2).backoff: time interval between theattemps(default 0).exponential_backoff:current_backoff = backoff * 2 ** retries(default False).ignore_exceptions: only log error but not raise exception ifattemptsexceeds (default False).jitter: maximum value of deviation from thecurrent_backoff(default 0).maximum_backoff:current_backoff = min(current_backoff, maximum_backoff)(default 0).on_exception: function that called or await on error occurs (default None). Be aware if a decorating function is synchronouson_exceptionfunction must be synchronous too and accordingly for asynchronous functionon_exceptionmust be asynchronous.
Examples
Immediately retry once without delay on any exception occurs
from the_retry import retry
@retry()
def some_function():
print("some function")
Immediately retry once without delay on ValueError occurs with calling side effect function
from the_retry import retry
def side_effect():
print("side effect")
@retry(expected_exception=ValueError, on_exception=side_effect)
def some_function():
print("some function")
Retry async function with 10 attempts with exponential backoff on ValueError or AttributeError occurs with calling side effect coroutine
from the_retry import retry
async def async_side_effect():
print("async side effect")
@retry(
expected_exception=(ValueError, AttributeError)
attempts=10,
backoff=1,
exponential_backoff=True,
jitter=1,
maximum_backoff=60,
on_exception=async_side_effect,
)
async def async_some_function():
print("some function")
Metadata
Release files for the-retry 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| the-retry-0.1.1.tar.gz | 4.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| the_retry-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.2 kB
Release files / the-retry-0.1.1.tar.gz
| Download URL | the-retry-0.1.1.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab6b801adc3ef40c9ec6b2def3890621572ee1f33b51972503a1cb7e4759e687
|
|
BLAKE2b-256 checksum How to use checksums |
2f764cd9f60ec057d9548e404a209997fb236e435e96e382ca74b935997b1f4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.1 CPython/3.10.4 Linux/5.15.0-58-generic
|
Release files / the_retry-0.1.1-py3-none-any.whl
| Download URL | the_retry-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c5c3ad10629b255e47e5f9ade8314f34ca46aa723092a983f0b9f0232fa2220d
|
|
BLAKE2b-256 checksum How to use checksums |
5fcac240e3467db7832a5ea755da6b93b20b8a3347e8c5950f669d7eff41e21f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.1 CPython/3.10.4 Linux/5.15.0-58-generic
|
Security for the-retry 0.1.1
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.