Metadata-Version: 2.5
Name: cmdp
Version: 0.0.2
Summary: Retry a callable with exponential backoff and clear logging.
Project-URL: Homepage, https://github.com/lqxnjk/cmdp
Author: lqxnjk
License: MIT
License-File: LICENSE
Keywords: backoff,decorator,fault-tolerance,resilience,retry
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# cmdp

Retry a flaky call with exponential backoff, without hand-rolling another
`while` loop.

## Install

```console
pip install cmdp
```

## Usage

```python
from cmdp import retry

@retry(n_attempts=5, n_delay=0.2, n_factor=2.0)
def fetch(url):
    return http_get(url)

@retry
def quick():
    ...

retry(lambda: do_thing(), n_attempts=2)
```

## Behaviour

| Option | Default | Meaning |
| --- | --- | --- |
| `n_attempts` | 3 | total calls, including the first |
| `n_delay` | 0.5 | initial wait, seconds |
| `n_max_delay` | 30.0 | ceiling for the wait |
| `n_factor` | 2.0 | multiplier per attempt |
| `n_exceptions` | `(Exception,)` | which errors are retried |

Every retry logs a warning with the attempt number and the next delay, and the
final failure logs at `error` before re-raising the original exception.

Narrow `n_exceptions` in production: retrying a `ValueError` just wastes time.

## License

MIT
