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. Its 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:
logging
support out-of-the-box.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!
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.