Skip to main content

larzretry

Resilience for flaky operations — retry with backoff, and a circuit breaker.

Real apps call things that fail intermittently: networks blip, services hiccup, databases briefly stall. larzretry makes those operations resilient — retry a failing call a few times (with optional exponential backoff), or wrap a troublesome dependency in a circuit breaker that stops hammering it once it's clearly down. Sleep and clock are injectable, so it's fully testable. Zero dependencies.

Install

pip install larzretry

Use

from larzretry import retry, call, CircuitBreaker

@retry(times=3, backoff=0.1)
def fetch():
    return risky_network_call()

call(fetch, times=5, exceptions=(ConnectionError,))

breaker = CircuitBreaker(threshold=3, reset_after=30)
breaker.call(fetch)     # fails fast once the dependency is clearly down

Learn to code with Larz

Part of the learn-to-code toolkit in the Larz stack — see the Learn to Code platform. A building block for reliable production apps.

Tests

python -m unittest discover -s tests -v   # 7 tests

License

MIT (c) larz-scripter

Download files

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

Source Distribution

larzretry-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

larzretry-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file larzretry-0.1.0.tar.gz.

File metadata

  • Download URL: larzretry-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzretry-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ff111861b85f3e7bf5249dc51c75ad3eef06903ce775827510a97319bf690e22
MD5 48cd977d2770ec4cf37710ad112756ed
BLAKE2b-256 d35cc28cbfe9fc99966104ad01181a2b448ee994aeecee7c7774b4ef488a677b

See more details on using hashes here.

File details

Details for the file larzretry-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: larzretry-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzretry-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd53203a1cb02a22ab70b24bd9ccc51237c85add0309dd8eb6a1a09efb1a43c2
MD5 7c16eec7a44495f4bd32f02125482163
BLAKE2b-256 b5a491b5291aa577e6f4d2395ba296b2c110e81d23b2447fbf685f6f44ef84f5

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page