※下の方に日本語の説明があります。
📖 iter-backoff Documentation
English Version
Overview
iter-backoff is a simple Python library that allows you to implement exponential backoff in loops with minimal effort. Instead of manually handling retry logic with sleep intervals, this library provides an elegant iterable interface to automate the process.
Installation
To install iter-backoff, use pip:
pip install iter-backoff
Usage
This library generates an iterable that yields exponential backoff times, allowing for simple loop-based retry logic.
Example:
import random
import iter_backoff
# Loop with exponential backoff
for _ in iter_backoff(s0=0.5, r=2, n=4):
if random.random() < 1/4:
print("Success!")
break
else:
print("Failure!")
Explanation
- The
forloop automatically waits while repeating, with an exponentially increasing wait time. - If the process succeeds, simply breaking out of the loop is sufficient.
- When
n=1is specified, it attempts only once without any waiting time.
Function Signature
iter_backoff(
s0, # Initial wait time (seconds)
r, # Growth rate (multiplier)
n # Maximum number of retries
)
Parameters
s0: The initial wait time (in seconds).r: The exponential growth factor (e.g.,2doubles the wait time each iteration).n: The maximum number of retries.
日本語版
概要
iter-backoff は、指数バックオフをループで簡単に実装できる Python ライブラリです。
インストール
iter-backoff をインストールするには、以下のコマンドを実行してください:
pip install iter-backoff
使い方
このライブラリは、指数的に増加する待機時間を生成するイテレータを提供します。
このイテレータを for ループで利用することで、簡単にバックオフ付きのリトライ処理が書けます。
例:
import random
import iter_backoff
# ループによる指数バックオフ
for _ in iter_backoff(s0=0.5, r=2, n=4):
if random.random() < 1/4:
print("成功!")
break
else:
print("失敗!")
説明
- for文は、指数的に長くなる待機時間を自動的に待機しながら繰り返します。
- 処理が成功した場合は単にbreakするだけでOKです。
- n=1指定の場合、待ち時間なしで1回のみ試行されます。
関数の仕様
iter_backoff(
s0, # 初回待機時間 (秒)
r, # 待機時間の増加率 (倍率)
n # 最大試行回数
)
引数
s0: 初回の待機時間 (秒)。r: 指数的な増加率 (例:2にすると毎回待機時間が 2 倍)。n: 最大試行回数。
Metadata
Release files for iter-backoff 0.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| iter-backoff-0.0.0.tar.gz | 3.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| iter_backoff-0.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.8 kB
Release files / iter-backoff-0.0.0.tar.gz
| Download URL | iter-backoff-0.0.0.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6de72772855d81ee17ca01dfe3d9d0f743ca1ecfa65da8c8152fed9d6ab4421d
|
|
BLAKE2b-256 checksum How to use checksums |
fe7ca487465ec13cf02ffe17cd0d36b1bec962b235812619f8f34f1487640027
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.3
|
Release files / iter_backoff-0.0.0-py3-none-any.whl
| Download URL | iter_backoff-0.0.0-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e82e06c18c7fad1f13f523d7841f5210e0b3f192d81c185a53b3e490da8f0cd
|
|
BLAKE2b-256 checksum How to use checksums |
13e0f6ccd48a477e1abd566962a7c829c06e0c7cc0fa38717717513da30c90e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.3
|
Security for iter-backoff 0.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.