rotapool
Async resource pool with inline health feedback, automatic cooldown, and retry -- for API keys, proxies, GPU workers, or anything that can rate-limit you or go down.
rotapool is designed for resources where every call is also useful health evidence. Instead of relying on a separate prober, callers signal whether the selected resource should stay healthy, cool down temporarily, or be disabled.
| Signal | Meaning |
|---|---|
| normal return / any other exception | Resource is healthy |
CooldownResource |
Temporarily overloaded, e.g. HTTP 429 |
DisableResource |
Permanently unusable, e.g. revoked key |
Designed for AI coding agents.
rotapoolexposes machine-readable usage notes via agent-readable, including operation contracts, do/don't rules, anti-patterns, and failure modes.npx skills add zydo/skills --skill agent-readable
Install
pip install rotapool
# or
uv add rotapool
Requires Python 3.10+. Zero runtime dependencies; pip install "rotapool[agent]" adds the optional agent-readable integration.
Quick Start
import httpx
from rotapool import CooldownResource, DisableResource, Pool, Resource
pool = Pool(
resources=[
Resource(resource_id="key-1", value="sk-aaa"),
Resource(resource_id="key-2", value="sk-bbb"),
Resource(resource_id="key-3", value="sk-ccc"),
],
max_attempts=3,
cooldown_table=(30.0, 120.0, 300.0, 600.0),
)
@pool.use()
async def call_upstream(resource, url, payload):
async with httpx.AsyncClient() as client:
resp = await client.post(
url,
headers={"Authorization": f"Bearer {resource.value}"},
json=payload,
)
if resp.status_code == 429:
raise CooldownResource(reason="rate limited")
if resp.status_code == 401:
raise DisableResource(reason="invalid key")
return resp.json()
result = await call_upstream("https://api.example.com/v1/chat", {"prompt": "hi"})
Documentation
- Usage guide covers pool initialization,
@pool.use(), directpool.run(), resource types, and accepted operation shapes. - Behavior guide explains selection strategies, cooldown escalation, retry behavior, in-flight cancellation, cancellation discrimination, and admin control.
- API reference documents
Pool,Resource,snapshot(), admin methods, and exceptions. - Pitfalls and testing lists common anti-patterns, cancellation gotchas, test commands, and license information.
Core Concepts
- Each
Poolowns a set ofResource[T]objects.Tcan be a bearer token, proxy URL, browser session, GPU worker, client object, or any other value. - Each
run()attempt receives one selectedResource. - Raising
CooldownResourcemarks that resource temporarily unavailable and retries elsewhere when possible. - Raising
DisableResourceremoves that resource from selection untilenable()is called. - Any other exception is treated as caller or business failure, not resource failure, and propagates.
@pool.use()is a decorator convenience overpool.run().
Testing
uv sync --all-extras
uv run pytest --cov
See pitfalls and testing for pip-based setup and additional notes.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rotapool-0.2.2.tar.gz.
File metadata
- Download URL: rotapool-0.2.2.tar.gz
- Upload date:
- Size: 56.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7677361882a4b6c99ba56c616473f95107536bbfdd2a0cf965d079dd9c3089e
|
|
| MD5 |
25b36050805cc1da3d2c11d0aed98ce5
|
|
| BLAKE2b-256 |
a51e3d03ed9054ef49b7b8ed35e64cd3c0137eaa1b69699f19eb47fd760eac25
|
Provenance
The following attestation bundles were made for rotapool-0.2.2.tar.gz:
Publisher:
publish.yml on zydo/rotapool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rotapool-0.2.2.tar.gz -
Subject digest:
a7677361882a4b6c99ba56c616473f95107536bbfdd2a0cf965d079dd9c3089e - Sigstore transparency entry: 2071657379
- Sigstore integration time:
-
Permalink:
zydo/rotapool@c8e6cc22eb5aee1cbd71bc4807e56e85394b3210 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/zydo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c8e6cc22eb5aee1cbd71bc4807e56e85394b3210 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rotapool-0.2.2-py3-none-any.whl.
File metadata
- Download URL: rotapool-0.2.2-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcdb3fb75513713eaafa0e83dbcb2c9d60c94c74584e7abbb13d8ebdad15c4f6
|
|
| MD5 |
fcbf61adc94f21f7f9f76fe60b768660
|
|
| BLAKE2b-256 |
4cb0112a7ddd94cc98c1e20ce039adb20f8276ac5ca60ffbe601161e8df024e6
|
Provenance
The following attestation bundles were made for rotapool-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on zydo/rotapool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rotapool-0.2.2-py3-none-any.whl -
Subject digest:
fcdb3fb75513713eaafa0e83dbcb2c9d60c94c74584e7abbb13d8ebdad15c4f6 - Sigstore transparency entry: 2071657388
- Sigstore integration time:
-
Permalink:
zydo/rotapool@c8e6cc22eb5aee1cbd71bc4807e56e85394b3210 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/zydo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c8e6cc22eb5aee1cbd71bc4807e56e85394b3210 -
Trigger Event:
push
-
Statement type: