Skip to main content

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

Fixed

  • stamina doesn't retry successful blocks when it's deactivated anymore (yes, you read it right). #54

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stamina-24.1.0.tar.gz (550.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stamina-24.1.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file stamina-24.1.0.tar.gz.

File metadata

  • Download URL: stamina-24.1.0.tar.gz
  • Upload date:
  • Size: 550.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for stamina-24.1.0.tar.gz
Algorithm Hash digest
SHA256 de14695610e4ea8da0624fc368607e95d923b25bfe45f4eaa10e226360bc9e02
MD5 0b06b2b368da59c7414d0f13f245a27a
BLAKE2b-256 8bc85a622f6cd586b042ec0701f8b5ce1b1be714d216f9cdbb4b436dfc0d3162

See more details on using hashes here.

File details

Details for the file stamina-24.1.0-py3-none-any.whl.

File metadata

  • Download URL: stamina-24.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for stamina-24.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0382013a3072c9db02f18240d36d6212e590643a45a8662cabc4584c5d1a8919
MD5 17c7538ae521b58f2f44abf08239beb6
BLAKE2b-256 2a5e3177fc2abd9ac9f3cf68756e15e8147e0f3d32549233024c8e0f0d45f838

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page