tenacity

A general-purpose Python retrying library that adds configurable retry behavior to almost anything

Library
PyPI
v9.2.1
8,811 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
78 /100 Good
Development Activity 84
Maintenance 68
Community 60
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
88 /100 Excellent
Architecture 90
Code Quality 88
Innovation 88
Learning Curve 85

Tenacity is an Apache 2.0 licensed, general-purpose retrying library for Python that makes it trivial to add resilient retry behavior to functions, coroutines, and arbitrary blocks of code. Originating as a maintained fork of the abandoned retrying library, it exposes a simple @retry decorator alongside a rich, composable vocabulary of stop, wait, and retry conditions.

Instead of scattering ad-hoc try/except loops throughout a codebase, developers declare retry policies declaratively: how many attempts to make, how long to wait between them, which exceptions or return values should trigger a retry, and what to do when retries are finally exhausted. This makes it a staple dependency for code that talks to flaky networks, remote APIs, and distributed services.

What You Get

  • A generic @retry decorator that works on plain functions, async coroutines, and Tornado coroutines
  • Composable stop conditions such as stop_after_attempt and stop_after_delay that combine with the | operator
  • A full family of wait strategies including fixed, random, and exponential backoff with jitter
  • Fine-grained retry predicates that react to specific exception types or to the returned result
  • Callbacks and logging hooks (before, after, before_sleep) plus per-call retry statistics

Common Use Cases

  • Retrying HTTP calls to remote APIs and microservices that fail intermittently
  • Adding exponential backoff with jitter when contending for shared or rate-limited resources
  • Waiting for eventually-consistent systems (databases, queues, cloud resources) to become ready
  • Hardening background jobs and data pipelines against transient network and I/O errors

Under The Hood

Architecture - Tenacity centers on a BaseRetrying engine (in tenacity/__init__.py) that drives an attempt loop, delegating three orthogonal decisions to pluggable strategy objects: stop conditions (tenacity/stop.py), wait strategies (tenacity/wait.py), and retry predicates (tenacity/retry.py). Each strategy is a small callable that receives a shared RetryCallState carrying attempt number, outcome future, and timing data; strategies compose via overloaded | and & operators into retry_any/retry_all trees. Synchronous execution flows through Retrying, while tenacity/asyncio/ provides an AsyncRetrying variant that awaits coroutine outcomes and sleeps, and tenacity/tornadoweb.py adapts the loop to Tornado coroutines.

Tech Stack - Pure Python (100% of the codebase) targeting Python 3.10+, with zero required runtime dependencies. It ships type hints and a py.typed marker for full typing support. The build uses Hatchling with hatch-vcs for git-tag-derived versioning. Development tooling includes pytest, mypy, ruff, poethepoet task running, Sphinx with reno for docs, and optional Tornado/trio/typeguard for testing async integrations.

Code Quality - The project is well tested, with an extensive tests/test_tenacity.py (130+ test functions) plus dedicated suites for asyncio, Tornado, utilities, and regression tests for specific issues. Code is fully type-annotated and mypy-checked, uses clear abstract base classes for each strategy family, and follows consistent naming (stop_*, wait_*, retry_if_*). Apache-2.0 license headers are present across source files.

API Design - The public API is a highlight: the bare @retry decorator works with zero configuration, while keyword arguments (stop, wait, retry, reraise, before_sleep) layer in behavior incrementally. Strategy objects read declaratively and combine with intuitive boolean operators, keeping call sites free of imperative loop boilerplate. Extensive ReadTheDocs documentation with doctest-verified examples makes the learning curve gentle for common cases while still exposing RetryCallState for advanced custom callbacks.

Used by 23 apps in this directory

HTML
84%
Apache 2.0

Elementary

Analytics · Data Engineering · Monitoring

2,428

The dbt-native data observability CLI that turns your existing dbt tests and metadata into anomaly detection, lineage graphs, and Slack/Teams alerts — no separate platform required.

View details
88
Repo Health
75
Technical
75
Dependency
Built with
HTML 84%
Python 16%
Updated 1 weeks ago
Python
71%
Apache 2.0

GPT Researcher

AI Assistants · Productivity

30,269

The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.

View details
90
Repo Health
91
Technical
64
Dependency
Built with
Python 71%
TypeScript 18%
Updated 2 weeks ago
Go
87%
MIT

Hatchet

AI Development · Automation · Developer Tools

8,174

A Postgres-backed orchestration engine for background tasks, AI agents, and durable workflows that replaces Redis queues and multi-datastore durable execution platforms with a single self-hostable service.

View details
88
Repo Health
83
Technical
67
Dependency
Built with
Go 87%
Updated 6 days ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,235

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
74
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 5 days ago
Python
51%
AGPL 3.0

Khoj

AI Assistants · Knowledge Management · Productivity

37,802

A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.

View details
62
Repo Health
82
Technical
66
Dependency
Built with
Python 51%
TypeScript 36%
Updated 2 months ago
Python
94%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,755

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
66
Dependency
Built with
Python 94%
Updated 5 days ago
TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,055

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
68
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 2 months ago
Python
64%
Other

Onyx

AI Agents · AI Assistants · Knowledge Management

32,935

Self-hostable AI platform with agentic RAG, 50+ connectors, deep research, code execution, and support for every major LLM provider.

View details
92
Repo Health
83
Technical
68
Dependency
Built with
Python 64%
TypeScript 26%
Updated 5 days ago
TypeScript
92%
Other

OpenHands

AI Code Assistants · AI Development

91,695

The self-hosted developer control center for running AI coding agents — locally, in Docker, on VMs, or across cloud backends — with automation workflows for GitHub, Slack, and more.

View details
91
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 92%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers