Skip to content

pyprogrammerblog/python-retry

Repository files navigation

Python Retry

License-MIT Documentation Status

GitHub Actions

Badge PyPi

Features

  1. Generic Decorator
  2. Specify stop condition (i.e. limit by number of attempts)
  3. Specify wait condition (i.e. exponential backoff sleeping between attempts)
  4. Customize retrying on Exceptions

Read the docs for further information.

Installation

Install using pip:

pip install python-retry

Example

>>> from python_retry import retry
>>> import pytest
>>>
>>> @retry()
... def div(num: int, den: int):
...     return num/den
>>>
>>> div(1, 0)

Advanced use

>>> import logging
>>> logger = logging.getLogger("foo")
>>>
>>> @retry(
...     retry_on=(ZeroDivisionError,),
...     max_retries=2,
...     backoff_factor=1,
...     supress_exception=True,
...     retry_logger=logger
... )
... def div(num: int, den: int):
...     return num / den
>>>
>>> div(1, 0)

Documentation

You can find here at Read the docs the complete documentation.

About

A simple retry mechanism with some cool functionalities.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages