Retrying in Python using tenacity

tenacity - (noun) the quality or fact of continuing to exist; persistence.

If you ever need to retry something that might fail in Python, take a look at a specialized package like tenacity.

It helps you properly cover common scenarios like retrying only a particular type of exception, exponential back-off or even jitter (adding random variance in the retrying cadence so clients don't all retry at the same time).

Otherwise it's important to leverage great packages like these in our workflows and not reinvent the wheel when faced with problems many other people face day to day.

Check out a quick example of it in action below.

No alt text provided for this image

Found it useful? Subscribe to my Analytics newsletter at notjustsql.com.