python-backoff
Function decoration for backoff and retry
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-backoffuv
uv add python-backoffpoetry
poetry add python-backoffInstalling 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
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
backoffProvides function decorators to automatically…
permissive · top 1,000 on PyPI
backoff-utilsProvides functions and decorators to apply…
permissive · top 15,000 on PyPI
reretryA decorator and function wrapper for retrying…
permissive · top 15,000 on PyPI
retry2Provides a decorator and function wrapper to…
permissive · top 5,000 on PyPI
retryProvides a decorator and function wrapper for…
permissive · top 1,000 on PyPI
justbackoffImplements exponential backoff with optional…
permissive · top 15,000 on PyPI
waiterWaiter provides iteration-based retry and…
permissive · top 15,000 on PyPI
python-retryProvides a decorator to automatically retry…
permissive · top 15,000 on PyPI
staminaStamina wraps Tenacity to provide a…
permissive · top 5,000 on PyPI
redoRedo provides decorators, functions, and a…
copyleft · top 5,000 on PyPI