skillfed

python-backoff

Function decoration for backoff and retry

python-backoff v2.4.0 4.6M downloads/30d#2,272 on PyPI25
Permissive license MIT Active released

What it is and what it does

backoff is a decorator library for adding retry logic to Python functions. It wraps functions to automatically re-execute them when they fail, using configurable wait strategies (exponential, fibonacci, constant, or custom) between attempts. The library supports both exception-based retries (when a specific exception is raised) and predicate-based retries (when a function's return value meets a condition), making it useful for handling transient failures in network calls, API requests, or resource polling.

The package is designed for unreliable resources and intermittent failures—typical scenarios include HTTP requests, database connections, and external API calls. It supports both synchronous functions and asyncio coroutines, offers fine-grained control over retry limits (by attempt count or elapsed time), and includes jitter algorithms to prevent thundering herd problems. You can combine multiple decorators, inspect exceptions before deciding whether to retry, and configure behavior at runtime via callables.

Use it for:

  • Retry HTTP requests with exponential backoff when network timeouts or transient errors occur.
  • Poll an external API or queue at regular intervals until a non-empty result is returned.
  • Automatically retry database operations that fail due to temporary connection issues.
  • Handle rate-limiting by respecting Retry-After headers via the runtime backoff generator.
  • Wrap asyncio coroutines to retry async I/O operations with configurable backoff strategies.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides function decorators for retrying operations with configurable backoff strategies when exceptions occur or predicates are met, supporting both synchronous and asynchronous code.

Yes. backoff is a lightweight, actively maintained library with zero dependencies, permissive MIT licensing, and broad Python version support. It solves a common problem (retry logic) cleanly and flexibly, with no security vulnerabilities. Install it if you need to add resilience to functions that interact with unreliable external resources.

Install

python-backoff on PyPI

pip

pip install python-backoff

uv

uv add python-backoff

poetry

poetry add python-backoff

Installing python-backoff

Before you install

Low friction installation with no runtime dependencies. Actively maintained with a recent release 6 days ago and support for current Python versions (3.9 through 3.15).

License in practice

MIT license permits unrestricted use, modification, and distribution with minimal legal obligations—suitable for both open-source and commercial projects.

Quickstart

pip install python-backoff

import backoff

@backoff.on_exception(backoff.expo, Exception, max_tries=5)
def my_function():
    # function body
    pass

my_function()

Requires Python 3.9 or later.

Verify before relying

  • Whether the package handles connection pooling or maintains state across retries beyond what the decorator itself manages.
  • Performance characteristics when used with high-frequency polling or many concurrent decorated functions.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 6 days since the last release
Last repo commit
First released
Downloads 4,621,238/month — #2,272 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: python_backoff-2.4.0-py3-none-any.whl

Keywords: backoff, decorators, retry

Development Status :: 5 - Production/StableIntended Audience :: DevelopersNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.15Programming Language :: Python :: 3.9Topic :: Internet :: WWW/HTTPTopic :: Software Development :: Libraries :: Python ModulesTopic :: Utilities

Tags

retry decorator with backoffexponential backoff for functionsasync retry handlingfunction retry with jitternetwork request retry logicpolling with backoffexception retry decorator
retry-logicasync-supportdecorator-pattern

More Python Modules packages