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
loggingsupport 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:
Release Information
Changed
- Passing
timeout=0now raises a warning since it counterintuitively disables all retries. If you explicitly want to disable the timeout, usetimeout=None.
Fixed
_compute_backoff()no longer raisesOverflowErrorwhen the attempt number exceeds 1024 with a float wait_exp_base. The exponential result is now clamped to wait_max on overflow. #137
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)
| File | Size | Uploaded | |
|---|---|---|---|
| stamina-26.1.0.tar.gz | 568.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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 logRelease 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