Skip to main content

A tiny retry helper for synchronous Python code.

Project description

tiny-retry v0.2.1

tiny-retry is a tiny package for retrying (synchronous) Python functions when they raise exceptions, designed to keep things light and simple.

Installation

pip install tiny-retry-gw

Usage

from tiny_retry import retry, retry_infinite

def foo():
    # Replace this code with something that can raise the exception(s) you want to retry on.
    ...

# This will try foo() 6 times, with a delay of 3.1 seconds between retries, and it will only retry when ConnectionError is raised.
result = retry(foo, tries=6, delay=3.10, exceptions=(ConnectionError,))

# This will try foo() infinitely, with a delay of 3.1 seconds between retries, and it will only retry when ConnectionError is raised.
result = retry_infinite(foo, delay=3.10, exceptions=(ConnectionError,))

Parameters

  • func: function to call.
  • tries: how many times to attempt the function (must be >= 1).
  • delay: delay in seconds between retries.
  • exceptions: a tuple of exceptions that should trigger another attempt.
  • *args, **kwargs: optional positional and keyword arguments to be passed into func.

If all attempts fail, retry reraises the last exception so the caller can handle or log it.

Notes

  • retry_infinite does not take tries as a parameter.

Development

Run the simple tests from the repo root:

python -m pytest

License

Apache 2.0 © Gatoware

6310

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

tiny_retry_gw-0.2.1.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

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

tiny_retry_gw-0.2.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file tiny_retry_gw-0.2.1.tar.gz.

File metadata

  • Download URL: tiny_retry_gw-0.2.1.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for tiny_retry_gw-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7bbae6aa808ad347aa257a5983fe4731af43d320d4d0dfe6775e989f5a919529
MD5 156dc083e2cbc232e949eca1f89ffcd5
BLAKE2b-256 2e89fc03255ae6751e9a85302fa9bce8018135d2fc38e2c5bf398d580f2cf5a0

See more details on using hashes here.

File details

Details for the file tiny_retry_gw-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: tiny_retry_gw-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for tiny_retry_gw-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d4823911491b182eab3c1b25d95c3deaf0c9856ca62f4e43bf1355fa9c8410e
MD5 177adfd81a3e85b5ba362db159d7ceac
BLAKE2b-256 7a3e798cb91f9f4e531656a81d79a0bfee4d082a2e1c7ac18075755d9e85fa31

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