--- id: python-backoff version: "2.4.0" license: MIT license_treatment: permissive maintenance: active --- # python-backoff — Function decoration for backoff and retry License: permissive · Maintenance: active · Downloads: 4.6M/mo ## 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 above — 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 pip install python-backoff uv add python-backoff 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_current - Install friction: low - Maintenance: active - Downloads: 4.6M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags retry decorator with backoff, exponential backoff for functions, async retry handling, function retry with jitter, network request retry logic, polling with backoff, exception retry decorator, retry-logic, async-support, decorator-pattern [View on SkillFed](https://skillfed.io/packages/python-backoff) · [View on PyPI](https://pypi.org/project/python-backoff/)