Package: backoff-utils
Python Library for Backoff/Retry StrategiesBranchUnit Testslatestv. 1.0developBackoff-Utilsis a Python library that provides Python functions and decorators
that apply various backoff / retry strategies to your Python function and method
calls.The library has a consistent syntax for easy use, and has been tested on
Python 2.7, 3.4, 3.5, 3.6, 3.7 and 3.8.COMPLETE DOCUMENTATION ON READTHEDOCS:http://backoff-utils.readthedocs.io/en/latestInstallationImportingDependenciesHello, World ExampleWhy Backoff-Utils?Library FeaturesSupported StrategiesAdditional FeaturesFeedback, Support, and ContributingInstallationTo installBackoff-Utils, just execute:$pipinstallbackoff-utilsImportingOnce installed, to importBackoff-Utilsinto your project you can use:#: Import the backoff() function.frombackoff_utilsimportbackoff#: Import the @apply_backoff() decorator.frombackoff_utilsimportapply_backoff#: Import backoff strategies.frombackoff_utilsimportstrategiesDependenciesBy design,Backoff-Utilsare designed to rely on minimal dependencies.
The only dependency they have outside of the Python standard library is:validator-collectionwhich provides for robust validation functionality.This library in turn has one external dependency when installed under Python 2.7:regexwhich is a drop-in replacement for
Python’s (buggy) standardremodule.Hello, World Examplefrombackoff_utilsimportstrategies# Using a Function Callfrombackoff_utilsimportbackoffdefsome_function(arg1,arg2,kwarg1=None):# your code goes herepassresult=backoff(some_function,args=['value1','value2'],kwargs={'kwarg1':'value3'},max_tries=3,max_delay=3600,strategy=strategies.Exponential)# Using a Decoratorfrombackoff_utilsimportbackoff@apply_backoff(strategy=strategies.Exponential,max_tries=3,max_delay=3600)defsome_decorated_function(arg1,arg2,kwarg1=None):# your code goes herepassresult=some_decorated_function('value1','value2',kwarg1='value3')Why Backoff-Utils?Because now and again, stuff breaks.Often, when making external API calls to third-party systems, something goes
wrong. The internet might glitch. The API we’re calling might timeout. Gremlins
might eat your packets. Any number of things can go wrong, and Murphy’s law tells
us that they will.Which is why we need backoff strategies. Basically, these are techniques
that we can use to retry function calls after a given delay - and keep retrying
them until either the function call works, or until we’ve tried so many times that
we just give up and handle the error.This library is meant to be an incredibly simple utility that provides a number
of easy-to-use backoff strategies. Its core API is to expose:thebackoff()function, which lets you apply
a given backoff strategy to any Python function call, and;the@apply_backoff()decorator, which lets
you decorate any function or method call so that a given backoff strategy isalwaysapplied when the decorated function/method is called.Library FeaturesSupported StrategiesThe library supports five of the most-common backoff strategies that we’ve come
across:ExponentialFibonacciFixedLinearPolynomialIn addtion, you can also create your own custom strategies as well.For more information about the backoff strategies supported, please see:Strategies ExplainedAdditional FeaturesIn addition to the basic strategies, the library also supports:random jitterargument-adjustment on retryselective exception capturechained backoff strategiesfailure handlerssuccess handlerscut-off after max delaycut-off after max triesscalingminimum delayFor more information about the backoff strategies supported, please see:Using the LibraryFeedback, Support, and ContributingWe’re happy to maintain this library going forward, and would always love to
hear users’ feedback - especially if you’re running into issues.Please report issues or questions on theproject’s Github pageFor more information on contributing to the Backoff-Utils library, please see:Contributor Guide