stamina
Production-grade retry library for Python by Hynek Schlawack (attrs, structlog author). Wraps tenacity with opinionated defaults suitable for production use: exponential backoff with jitter, structured logging of retry attempts, async support, and Prometheus metrics integration. @stamina.retry decorator and stamina.retry_context() context manager. Designed with the lesson that naive retry implementations cause cascading failures in production.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Retry library — no direct security surface. Retrying auth failures can expose timing information; exclude auth errors from retry scope. Maintained by trusted Python community member.
⚡ Reliability
Best When
You want production-ready retry behavior with sensible defaults, structured logging, and async support without tuning tenacity internals.
Avoid When
You need fine-grained retry conditions that stamina's opinionated wrapper doesn't expose — use tenacity directly for complex retry logic.
Use Cases
- • Retry agent LLM API calls on transient failures (rate limits, timeouts) with production-safe exponential backoff and jitter
- • Add structured retry logging to agent HTTP clients — stamina logs each retry attempt with attempt number, wait time, and exception details
- • Use stamina with async agent code — @stamina.retry works on both sync and async functions natively
- • Integrate stamina's Prometheus metrics to monitor agent retry rates and identify flaky external dependencies
- • Use stamina.retry_context() for more control in agent code that needs to handle retry state mid-loop
Not For
- • Circuit breaker patterns — stamina handles retry but not circuit breaking; use pybreaker or resilience4j for circuit breaker
- • Complex conditional retry logic — tenacity directly offers more configuration options when stamina's opinionated defaults don't fit
- • Python 2 or Python <3.8 — stamina requires Python 3.8+
Interface
Authentication
Retry library — no authentication.
Pricing
MIT license. Maintained by Hynek Schlawack.
Agent Metadata
Known Gotchas
- ⚠ stamina retries on ANY exception by default — non-retryable exceptions (authentication errors, validation errors) should be excluded via on= parameter to avoid unnecessary retries
- ⚠ stamina is testing-aware: set STAMINA_TESTING=true environment variable to disable waiting in tests — forgetting this makes test suites with retry code very slow
- ⚠ Async functions decorated with @stamina.retry must be awaited — the decorator returns a coroutine for async functions; sync usage of an async-stamina-decorated function doesn't work
- ⚠ stamina's default max_attempts=10 with exponential backoff can result in very long total retry time — configure max_wait and timeout to bound total retry duration for agent SLAs
- ⚠ Prometheus metrics require prometheus_client installed — stamina checks for it at import time and silently disables metrics if not available without warning
- ⚠ stamina.retry_context() is a generator — it must be used in a for loop pattern, not as a regular context manager; incorrect usage causes StopIteration immediately
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for stamina.
Scores are editorial opinions as of 2026-03-06.