Production-grade retries made easy.
Project description
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. 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:
- Retry only on certain exceptions.
- 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. - Easy global deactivation for testing.
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!
Release Information
Added
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file stamina-23.3.0.tar.gz
.
File metadata
- Download URL: stamina-23.3.0.tar.gz
- Upload date:
- Size: 550.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48f1b3c39ea7e03775fdc0653f9f6ad183b401c84e0eeada12ff18accc712a61 |
|
MD5 | b5bf3b874e3048f2f2bf14a8a9c3dd3c |
|
BLAKE2b-256 | fcac5b32581b731b719daa8ef309c309eeea727fec49b29302dc4200a6c7c81f |
File details
Details for the file stamina-23.3.0-py3-none-any.whl
.
File metadata
- Download URL: stamina-23.3.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | efd0a6918bbb2adc9268768f7f9009d04f41c4fb5888e0aca82590d757988923 |
|
MD5 | 5a20ed4cda73b2b40781b113d58c7570 |
|
BLAKE2b-256 | 438932b3202a2890c2f98dc30f589d25ae1400cd8b9f805f2657c957aea21113 |