Skip to main content

A Python library providing retry decorators.

Project description

retry_ops

retry_ops is a Python library designed to simplify the creation of retry decorators. With retry_ops, you can effortlessly add retry logic to your functions, helping them handle transient errors more gracefully.

Features

  • Easy to use: Apply retry logic with minimal code changes.
  • Configurable: Customize the number of retries, delay between retries, and more.
  • Flexible: Use with any Python function.
pip install retry_ops

Usage

To use retry_ops, you simply need to import it and apply the retry decorator to the function you want to wrap. Here is an example:

from retry_ops import retry, silent_retry_with_default

# Simple usage with default settings
@retry
def my_function():
    # Function logic that may fail
    print("Attempting the operation...")
    raise ValueError("An error occurred!")

# Customizing the retry logic
@retry(retries=5, retry_delay=2, exceptions=(IOError, ), error_message="Custom error message")
def my_other_function():
    # Function logic that may fail
    print("Attempting another operation...")
    raise IOError("Another error occurred!")

# Using the silent retry decorator
@silent_retry_with_default(default_return_value=-1, retries=5, retry_delay=3, exceptions=(RuntimeError,), error_message="Operation failed after retries")
def my_silent_function():
    # Function logic that may fail
    print("Attempting the silent operation...")
    raise RuntimeError("A runtime error occurred!")

Parameters

The @retry decorator accepts the following parameters:

  • retries (int): The maximum number of retry attempts. Default is 3.
  • retry_delay (int or float): The delay (in seconds) between retry attempts. Default is 2.
  • exceptions (tuple): A tuple of exception classes that will trigger a retry. Default is (Exception,).
  • error_message (str): The error message to be raised when the retry attempts are exceeded. Default is "Max retries exceeded".

The @silent_retry_with_default decorator accepts the following parameters:

  • default_return_value (any): The value to return if the retries are exceeded. Default is None.
  • retries (int): The maximum number of retry attempts. Default is 3.
  • retry_delay (int or float): The delay (in seconds) between retry attempts. Default is 2.
  • exceptions (tuple): A tuple of exception classes that will trigger a retry. Default is (Exception,).
  • error_message (str): The error message to be logged when the retry attempts are exceeded. Default is "Max retries exceeded".

Contributing

We welcome contributions! Please submit a pull request or open an issue to help improve retry_ops.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgements

This library was inspired by the need for simple and configurable retry logic in Python functions.

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

retry_ops-0.1.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

retry_ops-0.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file retry_ops-0.1.1.tar.gz.

File metadata

  • Download URL: retry_ops-0.1.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for retry_ops-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f251674c39ef70bbc615ff92a4690a89f5278ba35b5f6dd92060cf5a8164f0db
MD5 0ac553e853fa8822d037476328acd7d0
BLAKE2b-256 f0b48c8ca7a8deed845dc70bdf897ee83b2281cc370615616708f5dbeae9465f

See more details on using hashes here.

File details

Details for the file retry_ops-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: retry_ops-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for retry_ops-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a07a324334e5fbe709a43bc9633227a8ffb1b5839c50dbd1b7a1ded9525dcb8f
MD5 0e0b08108fe785a7d45f8bcc7b269226
BLAKE2b-256 b42d50a56b237ec7c98523b73a02f3b9add72a7a3e27e1fce431708daa9373c5

See more details on using hashes here.

Supported by

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