Python libraries to consider – Tenacity

P

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.

Tenacity Documentation

By Glen Pennington

Glen Pennington

I have over 30 years of IT experience in the application of computer technology to many fields of business. I have deep experience in developing ETL/ELT pipelines to populate data warehouses, data lakes, and data products built on traditional relational database and cloud based platforms such as Snowflake and the Spark ecosystem.

As a data architect I can design and implement data products with consistent naming standards and rigorous data quality standards. These solutions are built on insights gained through data profiling and enforced through embedded data quality checks.

I have extensive experience using many languages and platforms and I have experience in several software development methodologies.

Where to find me on the socials