tenacity
Retry code until it succeeds
This package has a good security score with no known vulnerabilities.
Community Reviews
Battle-tested retry library with excellent operational characteristics
The wait strategies are well-designed with sensible defaults. Exponential backoff with jitter is trivial to implement and the stop conditions (after_attempt, after_delay) prevent runaway retries. Memory usage is minimal since it doesn't accumulate state between calls. The retry_if_exception_type and retry_if_result predicates give fine-grained control over what triggers retries.
Configuration is straightforward and works well with environment-based settings. We've used it for API calls, database operations, and distributed system coordination. The library handles edge cases gracefully - no leaked connections or hanging threads. The only gotcha is remembering that decorators are applied at import time, so dynamic configuration needs reraise=True with try/except or the Retrying class directly.
Best for: Services making unreliable external API calls, database operations, or any I/O where transient failures need intelligent retry logic with observability.
Avoid if: You need circuit breaker patterns or complex distributed rate limiting across multiple service instances.
Intuitive retry decorator with excellent defaults and debugging experience
The error messages are surprisingly helpful. When a retry fails after all attempts, you get the original exception with clear context about retry attempts made. The `retry_error_callback` parameter lets you customize failure handling easily. I particularly appreciate the `before_sleep` callback for logging - it's simple to add visibility into what's happening during retries without complex instrumentation.
Documentation includes practical examples for common scenarios: API calls with rate limiting, database connections, exponential backoff with jitter. The combination of decorators and programmatic retry objects (`Retrying()`) gives flexibility for both simple and complex use cases. Community support on GitHub is responsive, and most questions are already answered in issues.
Best for: Any project needing retry logic for network calls, external APIs, or flaky operations with minimal code complexity.
Avoid if: You need circuit breaker patterns or complex distributed retry coordination (consider libraries specifically for those patterns).
The gold standard for retry logic with excellent API design
The documentation strikes the perfect balance between quick-start simplicity and deep-dive complexity. Real-world examples cover everything from basic retries to custom callbacks for logging. The `retry_if_exception_type()` and `wait_exponential()` functions handle the most common patterns elegantly, while advanced features like `before_sleep` callbacks integrate seamlessly with logging frameworks.
Migration between versions has been painless in my experience. The library's philosophy of composable, reusable components means you can start simple and add complexity incrementally. AsyncIO support through `@retry_async` works flawlessly, though the async documentation could be slightly more prominent.
Best for: Any project requiring retry logic for network calls, external APIs, or unreliable operations where readability and maintainability matter.
Avoid if: You need only a single, simple retry without configuration (a basic loop might suffice).
Sign in to write a review
Sign In