[](https://github.com/MazrimT/yet-another-retry/actions/workflows/build-and-publish.yml)
[](https://pepy.tech/projects/yet-another-retry)
# yet-another-retry
This package is inspired by other retry-packages.
It takes a slightly different approach to certain things however to allow the decorated function to know it is being retried and take action based on a retry_config.
The package uses only python standard library and has no external dependencies.
It allows for custom handlers to be created for retry and exception handling.
Handlers can log or do anything user wants them to do and will also recieve any input parameters to the retry decorator.
# Install
```bash
python -m pip install yet-another-retry
```
then import with:
```python
from yet-another-retry import retry
```
# Usage
### Basic usage
This is not much different from other retry packages.
Uses the decorator with all default values
tries=3
base_delay_seconds=0
```python
from yet_another_retry import retry
@retry()
def my_function():
...
```
### Changing number of tries
Since we have to know in advance how many tries to do, this is a parameter directly to the decorator
```python
from yet_another_retry import retry
@retry(tries=5)
def my_function():
...
```
### Changing number of seconds to sleep in default retry handler
The default retry handler has a parameter "retry_delay_seconds" that can be modified as an extra_kwarg.
```python
from yet_another_retry import retry
@retry(base_delay_seconds=10)
def my_function():
...
```
# Handlers
The decorator uses a concept of handlers for retries and exceptions.
A handler is just a function with some requirements.
The handler will be called on retries and final exception.
Both types of handlers must have the following parameters:
- e: Exception - must be first parameter
- *args - must be second to last parameter
- **kwargs - must be last parameter
Any extra kwargs added to the retry decorator will be passed on to both the retry and exception handlers.
## Retry handlers
A retry handler is expected to return a float or integer that the retry function will sleep for before the next attempt.
The default retry_handler has a parameter `base_delay_seconds` that can be sent as a parameter to the decorator to modify the number of seconds it sleeps for.
See examples in the examples folder
To use a custom retry handler:
```python
from yet_another_retry import retry
def custom_retry_handler(e: Exception, **kwargs):
sleep_time = 1
return sleeptime
@retry(retry_handler=custom_retry_handler)
def my_function():
...
```
## Exception handlers
A exception handler triggers on raising exception on the last retry.
Works the same way as retry_handler except it is not expected to return anything.
The default raise_exception handler just raises the exception.
By default if a custom decorator has not raised the exception the retry decorator will raise it after the exception_handler is done.
To stop the decorator from raising the exception, if using a custom exception_handler, you can pass `raise_final_exception=False` to the decorator.
See examples in the examples folder
To use a custom exception handler:
```python
from yet_another_retry import retry
def custom_exception_handler(e: Exception, **kwargs):
... do things
raise e
@retry(exception_handler=custom_exception_handler)
def my_function():
...
```
Raw data
{
"_id": null,
"home_page": null,
"name": "yet-another-retry",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "decorator, retry, retry decorator",
"author": "MazrimT",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/ad/5c/24cdbeec69e5c5e42b7e9cd82f49a0faca248ed8b9f7966872c70d343140/yet_another_retry-0.3.1.tar.gz",
"platform": null,
"description": "[](https://github.com/MazrimT/yet-another-retry/actions/workflows/build-and-publish.yml) \n[](https://pepy.tech/projects/yet-another-retry)\n# yet-another-retry\nThis package is inspired by other retry-packages. \nIt takes a slightly different approach to certain things however to allow the decorated function to know it is being retried and take action based on a retry_config. \nThe package uses only python standard library and has no external dependencies. \n \nIt allows for custom handlers to be created for retry and exception handling. \nHandlers can log or do anything user wants them to do and will also recieve any input parameters to the retry decorator.\n\n# Install\n```bash\npython -m pip install yet-another-retry\n```\nthen import with:\n```python\nfrom yet-another-retry import retry\n```\n\n# Usage\n### Basic usage\nThis is not much different from other retry packages. \nUses the decorator with all default values \ntries=3 \nbase_delay_seconds=0 \n\n```python\nfrom yet_another_retry import retry\n\n@retry()\ndef my_function():\n ...\n\n```\n### Changing number of tries\nSince we have to know in advance how many tries to do, this is a parameter directly to the decorator\n```python\nfrom yet_another_retry import retry\n\n@retry(tries=5)\ndef my_function():\n ...\n```\n\n### Changing number of seconds to sleep in default retry handler \nThe default retry handler has a parameter \"retry_delay_seconds\" that can be modified as an extra_kwarg.\n\n```python\nfrom yet_another_retry import retry\n\n@retry(base_delay_seconds=10)\ndef my_function():\n ...\n\n```\n\n# Handlers\nThe decorator uses a concept of handlers for retries and exceptions. \nA handler is just a function with some requirements. \nThe handler will be called on retries and final exception. \nBoth types of handlers must have the following parameters:\n- e: Exception - must be first parameter\n- *args - must be second to last parameter\n- **kwargs - must be last parameter\n\nAny extra kwargs added to the retry decorator will be passed on to both the retry and exception handlers.\n\n\n## Retry handlers\nA retry handler is expected to return a float or integer that the retry function will sleep for before the next attempt. \nThe default retry_handler has a parameter `base_delay_seconds` that can be sent as a parameter to the decorator to modify the number of seconds it sleeps for.\n\nSee examples in the examples folder\n\nTo use a custom retry handler:\n```python\nfrom yet_another_retry import retry\n\ndef custom_retry_handler(e: Exception, **kwargs):\n sleep_time = 1\n return sleeptime\n \n \n@retry(retry_handler=custom_retry_handler)\ndef my_function():\n ...\n\n```\n\n## Exception handlers\nA exception handler triggers on raising exception on the last retry.\nWorks the same way as retry_handler except it is not expected to return anything.\nThe default raise_exception handler just raises the exception.\nBy default if a custom decorator has not raised the exception the retry decorator will raise it after the exception_handler is done.\nTo stop the decorator from raising the exception, if using a custom exception_handler, you can pass `raise_final_exception=False` to the decorator.\n\nSee examples in the examples folder\n\nTo use a custom exception handler:\n```python\nfrom yet_another_retry import retry\n\ndef custom_exception_handler(e: Exception, **kwargs):\n ... do things \n raise e\n \n \n@retry(exception_handler=custom_exception_handler)\ndef my_function():\n ...\n\n```\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Yet another retry decorator for Python",
"version": "0.3.1",
"project_urls": {
"Homepage": "https://github.com/MazrimT/yet-another-retry",
"Issues": "https://github.com/MazrimT/yet-another-retry/issues",
"Repository": "https://github.com/MazrimT/yet-another-retry.git"
},
"split_keywords": [
"decorator",
" retry",
" retry decorator"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "d3e52b10b577be614cc73b000657a5d05c20646eea62993532ab8264a39926cd",
"md5": "27790d72a338e064c481a75d5404b040",
"sha256": "fd95eadc6b9f3acb833827b76c08019d5f0bb9706f46eeebacb96537d0256b76"
},
"downloads": -1,
"filename": "yet_another_retry-0.3.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "27790d72a338e064c481a75d5404b040",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 8854,
"upload_time": "2025-10-27T06:28:15",
"upload_time_iso_8601": "2025-10-27T06:28:15.559644Z",
"url": "https://files.pythonhosted.org/packages/d3/e5/2b10b577be614cc73b000657a5d05c20646eea62993532ab8264a39926cd/yet_another_retry-0.3.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "ad5c24cdbeec69e5c5e42b7e9cd82f49a0faca248ed8b9f7966872c70d343140",
"md5": "f9279527ec48f8863582c2a78d133602",
"sha256": "6f439dc51b130a1da2aa40e5e308a7b7b1f3178d081b6454c843a66b8c7eb50e"
},
"downloads": -1,
"filename": "yet_another_retry-0.3.1.tar.gz",
"has_sig": false,
"md5_digest": "f9279527ec48f8863582c2a78d133602",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 7762,
"upload_time": "2025-10-27T06:28:16",
"upload_time_iso_8601": "2025-10-27T06:28:16.575194Z",
"url": "https://files.pythonhosted.org/packages/ad/5c/24cdbeec69e5c5e42b7e9cd82f49a0faca248ed8b9f7966872c70d343140/yet_another_retry-0.3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-27 06:28:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "MazrimT",
"github_project": "yet-another-retry",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "yet-another-retry"
}