https://github.com/pyprogrammerblog/python-retry
A simple retry mechanism with some cool functionalities.
https://github.com/pyprogrammerblog/python-retry
Last synced: 7 months ago
JSON representation
A simple retry mechanism with some cool functionalities.
- Host: GitHub
- URL: https://github.com/pyprogrammerblog/python-retry
- Owner: pyprogrammerblog
- License: mit
- Created: 2022-03-09T14:37:45.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-12T07:08:00.000Z (about 2 years ago)
- Last Synced: 2025-09-03T22:41:47.604Z (8 months ago)
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE
Awesome Lists containing this project
README
Python Retry
=============
.. image:: https://img.shields.io/badge/License-MIT-yellow.svg
:target: https://github.com/pyprogrammerblog/python-retry/blob/master/LICENSE
:alt: License-MIT
.. image:: https://readthedocs.org/projects/py-retry/badge/?version=latest
:target: https://py-retry.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://github.com/pyprogrammerblog/python-retry/workflows/Test%20Suite/badge.svg/
:alt: GitHub Actions
.. image:: https://badge.fury.io/py/python-retry.svg/
:target: https://badge.fury.io/py/python-retry/
:alt: 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
--------
.. code:: python
>>> from python_retry import retry
>>> import pytest
>>>
>>> @retry()
... def div(num: int, den: int):
... return num/den
>>>
>>> div(1, 0)
Advanced use
--------------
.. code:: python
>>> 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.