stamina: Production-grade Retries Made Easy#

Release 23.1.0.post1 (What’s new?)

Transient failures are common in distributed systems. To make your systems resilient, you need to retry failed operations. But bad retries can make things much worse.

stamina is an opinionated wrapper around the great-but-unopinionated Tenacity package. Its goal is to be as ergonomic as possible, while doing the right thing by default, while minimizing potential for misuse. It is the result of years of copy-pasting the same configuration over and over again:

  • Retry only on certain exceptions.

  • Exponential backoff with jitter between retries.

  • Limit the number of retries and total time.

  • Automatic async support.

  • Preserve type hints of the decorated callable.

  • Count (Prometheus) and log (structlog) retries with basic metadata, if they’re installed.

  • Easy global deactivation for testing.

User’s Guide#

Project Information#


stamina is written by Hynek Schlawack and distributed under the terms of the MIT license.

The development is kindly supported by my employer Variomedia AG and all my amazing GitHub Sponsors.

This project would not be possible without the years of incredible work that went into Tenacity.