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, while minimizing 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.
  • Preserve type hints of the decorated callable.
  • Count (Prometheus) and log (structlog) retries with basic metadata, if they're installed.
  • 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. Please refer to our tutorial for more examples.

Release Information

Added

  • Official Python 3.12 support. #9
  • Async support. #10
  • Retries of arbitrary blocks using (async) for loops and context managers. #12
  • Proper documentation. #16
  • A backwards-compatibility policy.

Changed

  • The timeout, wait_initial, wait_max, and wait_jitter arguments can now also be of type datetime.timedelta.

→ Full Changelog

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-23.1.0.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

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

stamina-23.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stamina-23.1.0.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for stamina-23.1.0.tar.gz
Algorithm Hash digest
SHA256 b16ce3d52d658aa75db813fc6a6661b770abfea915f72cda48e325f2a7854786
MD5 b6ac500d7d13cde61881cebd1e5fba27
BLAKE2b-256 a578590d11c8f97f24ef67983d8f931ac86455d71e144eba4433259b058b5a43

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stamina-23.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for stamina-23.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 850de8c2c2469aabf42a4c02e7372eaa12c2eced78f2bfa34162b8676c2846e5
MD5 815a9a7421985d04ce0037da89e09303
BLAKE2b-256 d64af01f48d8d68c66a28119933559fc5b48f4facb110162d754643c1ad9ff5a

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