Per the README, “Tenacity is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simplify the task of adding retry behavior to just about anything.” I find this library particularly useful in ETL pipelines with REST API and/or database integrations. Modern distributed cloud architectures are great, but I see transient service interruptions more often than I’d like. Tenacity helps smooth over these events by providing a retry decorator that adds resiliency to any python function. Isolate your REST API / database integration calls (Single Responsibility Principle) and decorate them with Tenacity. It won’t protect you from an extended outage but it’ll smooth over any momentary interruptions with very little effort required.
Example
import random
from tenacity import retry
@retry
def do_something_unreliable():
if random.randint(0, 10) > 1:
raise IOError("Oh no!")
else:
return "Awesome sauce!"
print(do_something_unreliable())
There are many options for limiting retry counts and timing those recounts. I have found exponential back off settings to work well.