Tenacity is a retrying library for Python that simplifies adding retry behavior to functions and code blocks through decorators and context managers.
The library addresses the need to handle transient failures in unreliable operations. It provides a decorator-based API that lets you specify stop conditions (such as maximum attempt count or time limit), wait conditions (including exponential backoff), and customize retry behavior based on exception types or return values. You can apply retries to regular functions, coroutines, or arbitrary code blocks using a context manager.
Tenacity suits any Python project where operations may fail transiently and need automatic recovery. It works well for network calls, flaky I/O operations, or any scenario where exponential backoff and bounded retry logic would improve reliability. The library originated as a maintained fork of an unmaintained predecessor, adding significant new functionality and fixing longstanding bugs while not maintaining API compatibility with that earlier project.
The project maintains active continuous integration with automated testing across supported Python versions. Development follows a structured workflow with pull request review processes and automated status checks before merging.