Delayed iteration for polling and retries.
Maintained. Last release 4 months ago, commits in 4 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install waiterDoes Python need yet another retry / poll library? It needs at least one that isn't coupled to decorators and functions. Decorators prevent the caller from customizing delay options, and organizing the code around functions hinders any custom handling of failures.
Waiter is built around iteration instead, because the foundation of retrying / polling is a slowly executing loop. The resulting interface is both easier to use and more flexible, decoupling the delay algorithms from the application logic.
Usage
creation
Supply a number of seconds to repeat endlessly, or any iterable of seconds.
from waiter import wait
wait(1) # 1, 1, 1, 1, ...
wait([1] * 3) # 1, 1, 1
wait([0.5, 0.5, 60]) # circuit breaker
Iterable delays can express any waiting strategy, and constructors for common algorithms are also provided.
wait.count(1) # incremental backoff 1, 2, 3, 4, 5, ...
wait(1) + 1 # alternate syntax 1, 2, 3, 4, 5, ...
wait.fibonacci(1) # 1, 1, 2, 3, 5, ...
wait.polynomial(2) # 0, 1, 4, 9, 16, ...
wait.exponential(2) # exponential backoff 1, 2, 4, 8, ...
backoff = wait(1) * 2 # alternate syntax 1, 2, 4, 8, ...
backoff[:3] # limit attempt count 1, 2, 4
backoff <= 5 # set maximum delay 1, 2, 4, 5, 5, 5, ...
backoff.random(-1, 1) # add random jitter