Skip to main content

Smart retry decorator with exponential backoff

Project description

retryit 🔄

Smart retry decorator with exponential backoff for Python.

Installation

pip install retryit

Usage

from retryit import retry

@retry(max_attempts=3, delay=1, backoff=2)
def fetch_data():
    return requests.get("https://api.example.com/data")

# With specific exceptions
@retry(max_attempts=5, exceptions=(ConnectionError, TimeoutError))
def connect_to_db():
    return database.connect()

# With callback on retry
def log_retry(exception, attempt):
    print(f"Attempt {attempt} failed: {exception}")

@retry(max_attempts=3, on_retry=log_retry)
def unreliable_function():
    # ...

Async Support

from retryit import retry_async

@retry_async(max_attempts=3, delay=1)
async def fetch_data():
    async with aiohttp.ClientSession() as session:
        return await session.get("https://api.example.com/data")

Parameters

Parameter Type Default Description
max_attempts int 3 Maximum retry attempts
delay float 1.0 Initial delay (seconds)
backoff float 2.0 Delay multiplier
exceptions tuple (Exception,) Exceptions to catch
on_retry callable None Callback on each retry

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyretryit_rj-1.0.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyretryit_rj-1.0.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file pyretryit_rj-1.0.0.tar.gz.

File metadata

  • Download URL: pyretryit_rj-1.0.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pyretryit_rj-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5c5d46c695b7f67d477812fbe744d40e17f06bf165da21dd8ff2dfd2ef2563f5
MD5 a230fd1e7cfd5d32b8408d5c96e08aae
BLAKE2b-256 6ee202c19b2b2054cdb41340a5436209ce557df3b369c60bc4bcce7500cd7762

See more details on using hashes here.

File details

Details for the file pyretryit_rj-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyretryit_rj-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pyretryit_rj-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3becd5b3469b7dfdf1466c25cd101dbad7b4506ea07d7dd783a88b696b0802e
MD5 eed94ba544a7a6ea47fde680561de96c
BLAKE2b-256 9ab3377141587b77926d9a29a1749412b9ce9c9409c1923a51ac0d0999a7096c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page