Retries library
Project description
Library to make your services reliable
Retry on specific exception
import yretry
@yretry.decorators.retry(attempts_number=3,
retry_on=(MyException,))
def reliable_function():
raise MyException()
Specific function to make decision about retries
import yretry
def is_my_mistake(error):
return isinstance(error, MyMistake)
@yretry.decorators.retry(attempts_number=3,
retry_on=is_my_mistake)
def reliable_function():
raise MyMistake()
Retry on network errors
You can use following code to add retries for your custom network function:
import requests
import yretry
@yretry.network.retry()
def reliable_function():
response = requests.get('http://localhost:5002')
response.raise_for_status()
return response
print reliable_function()
Logging
Global logger
You can pass specific logger to decorator:
import logging
import logging.config
LOGGING = {
'version': 1,
'formatters': {
'precise': {
'datefmt': '%Y-%m-%d,%H:%M:%S',
'format': '%(levelname)-7s %(asctime)15s '
'%(name)s:%(lineno)d %(message)s'
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'precise',
'stream': 'ext://sys.stderr'
},
},
'root': {
'level': 'INFO',
'handlers': ['console']
}
}
logging.config.dictConfig(LOGGING)
LOGGER = logging.getLogger(__name__)
@yretry.network.retry(logger=LOGGER)
def reliable_function():
response = requests.get('http://localhost:5002')
response.raise_for_status()
return response
Object-specific logger
You can use object-specific logger, just add ‘get_logger’ method:
class MyClass(object):
def __init__(self):
self._logger = logging.getLogger(__name__)
def get_logger(self):
return self._logger
@yretry.network.retry()
def reliable_method(self):
pass
obj = MyClass()
obj.reliable_method()
# obj._logger will be used to write warnings about retries
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yretry-1.0.1.tar.gz.
File metadata
- Download URL: yretry-1.0.1.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28b31207fdad031cb7230df8f554bfc892a525c33a3c99977944d9317efb0b1b
|
|
| MD5 |
a7c50f3c08531fc77d8240f884dbdc79
|
|
| BLAKE2b-256 |
b8b433506d3dd8c71a91a6201ebc6045aba53ae4e7f7d05ab1bc77ece1f734fb
|
Provenance
The following attestation bundles were made for yretry-1.0.1.tar.gz:
Publisher:
publish-to-pypi.yml on infraguys/yretry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yretry-1.0.1.tar.gz -
Subject digest:
28b31207fdad031cb7230df8f554bfc892a525c33a3c99977944d9317efb0b1b - Sigstore transparency entry: 564512939
- Sigstore integration time:
-
Permalink:
infraguys/yretry@576be4f083b14fcb954cf96e205fd1b57d313777 -
Branch / Tag:
refs/tags/1.0.1 - Owner: https://github.com/infraguys
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@576be4f083b14fcb954cf96e205fd1b57d313777 -
Trigger Event:
push
-
Statement type:
File details
Details for the file yretry-1.0.1-py2.py3-none-any.whl.
File metadata
- Download URL: yretry-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4668535e5ee2afba90c4f49dda5f376bd9c7485b3764bd34c761b1475da8bf0
|
|
| MD5 |
e68ecd5559eda836035b725e901298dc
|
|
| BLAKE2b-256 |
59ccd91ec945948aef1ad533b7fd62ffb9c7fb220b670f451b43c43d7ff2e254
|
Provenance
The following attestation bundles were made for yretry-1.0.1-py2.py3-none-any.whl:
Publisher:
publish-to-pypi.yml on infraguys/yretry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yretry-1.0.1-py2.py3-none-any.whl -
Subject digest:
f4668535e5ee2afba90c4f49dda5f376bd9c7485b3764bd34c761b1475da8bf0 - Sigstore transparency entry: 564512947
- Sigstore integration time:
-
Permalink:
infraguys/yretry@576be4f083b14fcb954cf96e205fd1b57d313777 -
Branch / Tag:
refs/tags/1.0.1 - Owner: https://github.com/infraguys
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@576be4f083b14fcb954cf96e205fd1b57d313777 -
Trigger Event:
push
-
Statement type: