Python retry libraries

Updated Nov 2026

Python retry libraries run a failed operation again after a delay until it succeeds or reaches a stop condition. A retry policy pairs conditions such as an exception type, a returned value, or an attempt limit with a wait between attempts. These libraries let apps and AI agents recover from network errors and brief outages in the services they call.

Popularity

Tenacity has the most monthly downloads in this comparison, at 429.7M.

LibraryMonthly downloadsStarsLast releaseLicense
Tenacity
429.7M
8.8KOct 2026Apache-2.0
backoff
152.5M
2.7KOct 2022MIT
retry
26.0M
Not on GitHubMay 2016Apache-2.0
retrying
25.3M
Not on GitHubAug 2025Apache-2.0
stamina
5.8M
1.5KNov 2026MIT
retry2
2.1M
Not on GitHubJan 2023Apache-2.0
Downloads: pypi, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Provides configurable retry decorators and code-block retry loops.

Downloads / mo
429.7M
Stars
8.8K
Last release
9.2.1
License
Apache-2.0

Strengths

  • Combines retry conditions. Retry selected exceptions or returned results with configurable stop and wait policies.
  • Retries individual code blocks. Use a retry iterator and context manager around the failing block.

Limitations

  • Defaults retry forever without waiting. Set both a stop condition and a wait policy.
  • Exhaustion wraps the last error. Set reraise to expose the original exception directly.

Quickstart

From index.rst
$ python -m pip install tenacity==9.2.1
from tenacity import retry, stop_after_attempt

@retry(stop=stop_after_attempt(3))
def greet():
    return "Hello"

print(greet())

Tenacity examples

From open-source projects on GitHub

Decorates synchronous functions and asyncio coroutines with exception or return-value retries.

Downloads / mo
152.5M
Stars
2.7K
Last release
2.2.1
License
MIT

Strengths

  • Retries exceptions or returned values. Choose on_exception or on_predicate for the operation’s failure signal.
  • Offers retry event handlers. Attach handlers for successful calls, retries, and give-up events.

Limitations

  • Repository is archived. Account for the archived upstream when choosing a new dependency.
  • Suppressed errors return None. Disabling raise_on_giveup returns None when retries are exhausted.

Quickstart

From README.rst
$ python -m pip install backoff==2.2.1
import backoff

@backoff.on_exception(backoff.expo, OSError, max_tries=3)
def greet():
    return "Hello"

print(greet())

backoff examples

From open-source projects on GitHub

Retries a function through a decorator.

Downloads / mo
26.0M
Last release
0.9.2
License
Apache-2.0

Quickstart

From README.rst
$ python -m pip install retry==0.9.2
from retry import retry

@retry(OSError, tries=3, delay=1)
def greet():
    return "Hello"

print(greet())

retry examples

From open-source projects on GitHub

Retries function calls.

Downloads / mo
25.3M
Last release
1.4.2
License
Apache-2.0

Quickstart

From README.md
$ python -m pip install retrying==1.4.2
from retrying import retry

@retry(stop_max_attempt_number=3, wait_fixed=100)
def greet():
    return "Hello"

print(greet())

retrying examples

From open-source projects on GitHub

Wraps Tenacity with bounded retry defaults, jitter, and instrumentation.

Downloads / mo
5.8M
Stars
1.5K
Last release
26.2.0
License
MIT

Strengths

  • Bounds retries by default. Configure attempt and total-time limits alongside exponential backoff and jitter.
  • Supports asyncio and Trio. Use the same retry functions with synchronous and asynchronous operations.

Limitations

  • Generator retries restart from beginning. Make repeated yielded work safe before retrying a generator.
  • Custom delays override backoff settings. An on-hook delay replaces the normal exponential backoff calculation.

Quickstart

From tutorial.md
$ python -m pip install stamina==26.2.0
import stamina

@stamina.retry(on=OSError, attempts=3)
def greet():
    return "Hello"

print(greet())

stamina examples

From open-source projects on GitHub

Retries a function through a decorator.

Downloads / mo
2.1M
Last release
0.9.5
License
Apache-2.0

Quickstart

From README.rst
$ python -m pip install retry2==0.9.5
from retry import retry

@retry(OSError, tries=3, delay=1)
def greet():
    return "Hello"

print(greet())

retry2 examples

From open-source projects on GitHub

FAQ

Tenacity suits code that combines retry conditions or retries individual code blocks. stamina suits services that want bounded retries with jitter by default. backoff suits existing code built on its decorators, although its repository is archived.

Tenacity is a retry library with configurable decorators and code-block retry loops. By default it retries exceptions forever without waiting. A stop policy bounds the number of attempts.

Tenacity and backoff both retry asyncio coroutines. stamina supports asyncio and Trio with the same API.

stamina wraps Tenacity with bounded retry defaults, jitter, and instrumentation.

No. A retried generator restarts from the beginning.

For coding agents

Found your retry library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official