Getting Started


To install Backoff-Utils, just execute:

$ pip install backoff-utils


Once installed, to import Backoff-Utils into your project you can use:

#: Import the backoff() function.
from backoff_utils import backoff

#: Import the @apply_backoff() decorator.
from backoff_utils import apply_backoff

#: Import backoff strategies.
from backoff_utils import strategies


By design, Backoff-Utils are designed to rely on minimal dependencies. The only dependency they have outside of the Python standard library is:

  • validator-collection which provides for robust validation functionality.

    This library in turn has two external dependencies: * jsonschema, and * (when installed under Python 2.7) regex

    which is a drop-in replacement for Python 2.7’s (buggy) standard re module.

Hello, World

As a quick reference, here are some examples. Each of the examples below performs up to three attempts, applying an exponential backoff strategy with default configuration:

from backoff_utils import strategies

# Using a Function Call
from backoff_utils import backoff

def some_function(arg1, arg2, kwarg1 = None):
    # your code goes here

result = backoff(some_function,
                 args = ['value1', 'value2'],
                 kwargs = { 'kwarg1': 'value3' },
                 max_tries = 3,
                 max_delay = 3600,
                 strategy = strategies.Exponential)

# Using a Decorator
from backoff_utils import backoff

@apply_backoff(strategy = strategies.Exponential, max_tries = 3, max_delay = 3600)
def some_decorated_function(arg1, arg2, kwarg1 = None):
    # your code goes here

result = some_decorated_function('value1', 'value2', kwarg1 = 'value3')

Library Capabilities

There are two ways in which you can apply a backoff/retry strategy using the Backoff-Utils. Which approach you want to use will probably depend on your code and your code conventions:

Both of these approaches support the following backoff strategies:

While the library’s defaults are usable out-of-the-box, your backoff strategy can be further tailored to your needs. The library also supports:

See also

While the Backoff-Utils are very straightforward to use, we recommend you review Using the Library to learn more about what it can do, and for a deep dive please see the API Reference .