refire
A flexible Python decorator for retrying functions upon failure with support for exponential backoff, jitter, and configurable retry policies.
Features
- Retry functions automatically when exceptions occur.
- Configurable number of retries or infinite retries.
- Adjustable initial delay and exponential backoff.
- Optional maximum delay to cap wait times.
- Support for random jitter to prevent retry storms (thundering herd problem).
- Specify which exception types trigger retries.
Installation
Install via pip:
pip install refire
# or
uv add refire
Or clone the repository:
git clone https://github.com/maxscheijen/refire.git
cd refire
pip install .
# or
uv sync
Usage
Basic Example
import random
from refire import refire
@refire(tries=5, delay=2, backoff=2, jitter=(0, 1))
def flaky_function():
if random.random() < 0.7:
raise ValueError("Unlucky!")
return "Success!"
result = flaky_function()
print(result) # "Success!" after several retries
Custom Exception
class CustomError(Exception):
pass
@refire(exceptions=CustomError, tries=3, delay=1)
def risky_function():
raise CustomError("Oops!")
risky_function()
Logging
Retries are by default logged at WARNING level:
Caught ValueError: Unlucky!. Retrying in 2.00s (remaining=4)
Development
This project uses uv. To set up a local development environment:
# Clone the repository
git clone https://github.com/maxscheijen/refire.git
cd refire
# Install dependencies (using uv)
uv sync --extra dev
# Or using pip
pip install -e ".[dev]"
Tests
This project uses pytest:
pytest
Metadata
Release files for refire 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 | |
|---|---|---|---|---|
| refire-0.1.1.tar.gz | 3.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| refire-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.9 kB
Release files / refire-0.1.1.tar.gz
| Download URL | refire-0.1.1.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cfce163e4a9997797bf4d2282d22aef275512cce23b9ba2181857ae4e788cffa
|
|
BLAKE2b-256 checksum How to use checksums |
2897b36b52ef25203d785c0e2234318a9122a29ccb51ffe2b263c1aa6888db46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|
Release files / refire-0.1.1-py3-none-any.whl
| Download URL | refire-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d5510c32373ebb1902c0af7822cf6ac3fde4f25c188624a4d426a2fd349aa235
|
|
BLAKE2b-256 checksum How to use checksums |
3b4ad57463d5b1ffe378b5d5a3555d1963f8bc0eb0f2a607285b24282d84a27a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|
Security for refire 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.