Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yretry-1.0.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

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

yretry-1.0.1-py2.py3-none-any.whl (14.0 kB view details)

Uploaded Python 2Python 3

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

Hashes for yretry-1.0.1.tar.gz
Algorithm Hash digest
SHA256 28b31207fdad031cb7230df8f554bfc892a525c33a3c99977944d9317efb0b1b
MD5 a7c50f3c08531fc77d8240f884dbdc79
BLAKE2b-256 b8b433506d3dd8c71a91a6201ebc6045aba53ae4e7f7d05ab1bc77ece1f734fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for yretry-1.0.1.tar.gz:

Publisher: publish-to-pypi.yml on infraguys/yretry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for yretry-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f4668535e5ee2afba90c4f49dda5f376bd9c7485b3764bd34c761b1475da8bf0
MD5 e68ecd5559eda836035b725e901298dc
BLAKE2b-256 59ccd91ec945948aef1ad533b7fd62ffb9c7fb220b670f451b43c43d7ff2e254

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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