Skip to main content

stamina: Production-grade Retries Made Easy

Transient failures are common in distributed systems. To make your systems resilient, you need to retry failed operations. But bad retries can make things much worse.

stamina is an opinionated wrapper around the great-but-unopinionated Tenacity package. Our goal is to be as ergonomic as possible, while doing the right thing by default, and minimizing the potential for misuse. It is the result of years of copy-pasting the same configuration over and over again:

  • Retry only on certain exceptions – or even a subset of them by introspecting them first using a backoff hook.
  • Exponential backoff with jitter between retries.
  • Limit the number of retries and total time.
  • Automatic async support – including Trio.
  • Preserve type hints of the decorated callable.
  • Flexible instrumentation with Prometheus, structlog, and standard library's logging support out-of-the-box.
  • Dedicated support for testing that allows to globally deactivate retries, or to limit the number of retries and to remove backoffs.

For example:

import httpx

import stamina


@stamina.retry(on=httpx.HTTPError, attempts=3)
def do_it(code: int) -> httpx.Response:
    resp = httpx.get(f"https://httpbin.org/status/{code}")
    resp.raise_for_status()

    return resp

Async callables work use the same API and it's possible to retry arbitrary blocks, too. Check out our tutorial for more examples!

Or, if you prefer video, here's a brief introduction into retries and stamina: Watch the video

Release Information

Changed

  • Passing timeout=0 now raises a warning since it counterintuitively disables all retries. If you explicitly want to disable the timeout, use timeout=None.

Fixed

  • _compute_backoff() no longer raises OverflowError when the attempt number exceeds 1024 with a float wait_exp_base. The exponential result is now clamped to wait_max on overflow. #137

Full Changelog →

Credits

stamina is written by Hynek Schlawack and distributed under the terms of the MIT license.

The development is kindly supported by my employer Variomedia AG and all my amazing GitHub Sponsors.

This project would not be possible without the years of incredible work that went into Tenacity.

stamina for Enterprise

Available as part of the Tidelift Subscription.

The maintainers of stamina and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open-source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.

Release files for stamina 26.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stamina 26.1.0
File Size Uploaded
stamina-26.1.0.tar.gz 568.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stamina 26.1.0
File Interpreter ABI Platform
stamina-26.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 586.7 kB

Release files / stamina-26.1.0.tar.gz

Download URL stamina-26.1.0.tar.gz
Size 568.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0214d05fdf5102c518194a4aac7520ce53cf660550ae3b940701aad88cf50c17
BLAKE2b-256 checksum
How to use checksums
80bdb2f71ae14368a066f103d182f25bbc6c3bf4aa695889f3ed3cba026d6f36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 13, 2026.

Transparency log

Release files / stamina-26.1.0-py3-none-any.whl

Download URL stamina-26.1.0-py3-none-any.whl
Size 18.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62e06829bec87c06d4cafde520b32a6097d1017c378a9eb63253c5bf5ebbbb88
BLAKE2b-256 checksum
How to use checksums
1df01ff90a1d1dd02de23feafdf9dffaecef3958348be5c192df56670ccb4f86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

26.1.0 This release

2 release files

25.2.0

2 release files

25.1.0

2 release files

24.3.0

2 release files

24.2.0

2 release files

23.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page