📜  volvere (1)

📅  最后修改于: 2023-12-03 14:48:21.528000             🧑  作者: Mango

Volvere

Volvere is a lightweight and simple Python library that allows you to add retry logic to your code easily.

Installation

You can install Volvere using pip:

pip install volvere
Usage

To use Volvere, simply import it and decorate the function you want to add retry logic to with the @volvere decorator. You can specify the maximum number of retries and the delay between retries in seconds as arguments to the decorator.

import volvere

@volvere(max_retries=3, delay=1)
def my_function():
    # your code here

When you call my_function, Volvere will automatically retry the code inside the function if an exception is raised, up to the maximum number of retries specified. The delay between retries can also be customized.

Example

Here is an example of how to use Volvere to retry an API request if it fails:

import requests
import volvere

@volvere(max_retries=3, delay=1)
def make_api_request():
    response = requests.get('https://api.example.com')
    response.raise_for_status()
    return response.json()

try:
    result = make_api_request()
    print(result)
except requests.exceptions.RequestException as e:
    print('API request failed:', e)

In this example, make_api_request is decorated with the @volvere decorator, with a maximum of 3 retries and a delay of 1 second between retries. If the API request fails, Volvere will retry up to 3 times before raising an exception. The code inside the try block catches the exception and handles it appropriately.

Conclusion

With Volvere, it's easy to add robust retry logic to your code, allowing it to gracefully handle transient failures and other unexpected errors. Give it a try today!