A flexible retry decorator for Python functions
Project description
Retrywrap
A flexible and lightweight retry decorator for Python functions.
Installation
pip install retrywrap
Quick Start
from retrywrap import retry
# Basic usage with default settings (3 attempts, 1 second delay)
@retry
def fetch_data():
# Your code here
pass
# With custom parameters
@retry(attempts=5, delay=0.5, backoff=2, exceptions=(TimeoutError, ConnectionError))
def call_api():
print("Calling API...")
raise TimeoutError("API timeout")
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
attempts |
int | 3 | Maximum number of retry attempts |
delay |
float | 1 | Initial delay between retries (seconds) |
backoff |
float | 1 | Multiplier for delay after each retry |
exceptions |
tuple | (Exception,) | Exception types to catch and retry |
Examples
Basic Retry
from retrywrap import retry
@retry
def unreliable_function():
# Will retry 3 times with 1 second delay
...
Custom Attempts and Delay
@retry(attempts=5, delay=2)
def slow_service():
# Will retry 5 times with 2 second delay
...
Exponential Backoff
@retry(attempts=4, delay=1, backoff=2)
def api_call():
# Delays: 1s, 2s, 4s between retries
...
Specific Exceptions
@retry(attempts=3, exceptions=(ConnectionError, TimeoutError))
def network_request():
# Only retries on ConnectionError or TimeoutError
# Other exceptions will be raised immediately
...
License
MIT License - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
retrywrap-0.1.0.tar.gz
(5.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file retrywrap-0.1.0.tar.gz.
File metadata
- Download URL: retrywrap-0.1.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39e9a7911ee6b24ef1ffb1c0272571342a339dc6a5985bdc41d20403359affdb
|
|
| MD5 |
4cde8bfbcf5c2f51457dd1d305185580
|
|
| BLAKE2b-256 |
69d8441ee13f01aa24d1d99e32ebda6c74acb488d43b62361ba5284ea5974a19
|
File details
Details for the file retrywrap-0.1.0-py3-none-any.whl.
File metadata
- Download URL: retrywrap-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
278e227af29ec980f045c821cc29d00e87f00d3f7b437844fdd7712cb31e8822
|
|
| MD5 |
d5bb781eeaf95ae3790a1a8748554109
|
|
| BLAKE2b-256 |
6e27cec97989ffdae43854306ee24a17c926abba3b7d167dbb2977cda023c696
|