Tenacity: Robust Retry Logic for Python in 2026 — The best library for adding retry logic to flaky operations (APIs, databases, networks).
Installation & Usage
uv add tenacity
from tenacity import retry, stop_after_attempt, wait_exponential
@retry(stop=stop_after_attempt(5), wait=wait_exponential(multiplier=1, min=2, max=10))
async def call_api():
# Your flaky API call here
return await httpx.get("https://api.example.com")
Conclusion
Tenacity makes your applications much more resilient. Highly recommended for production systems in 2026.
Also read: HTTPX Modern HTTP Client