module documentation
Renewable token bearer and receiver.
This module wraps an asynchronous Bearer. It refreshes tokens in the background. Its per-request Receiver delegates token retrieval to the wrapped bearer and counts retries.
The primary public types provided here are:
Receiver-- per-request receiver that calls the parent- bearer to obtain a token and tracks retry attempts.
Bearer-- a bearer that wraps another bearer and keeps a- cached token refreshed in the background. It provides synchronous and asynchronous renewal request modes and controlled shutdown.
Notes
The first token retrieval starts a background task. The task refreshes the cached token after a configurable fraction of its lifetime. Synchronous mode waits for renewal. Asynchronous mode starts background renewal and waits for a fresh cached token.
Examples
Basic usage (asynchronous renewal):
from nebius.aio.token.static import Bearer as StaticBearer
from nebius.aio.token.renewable import Bearer as RenewableBearer
import asyncio
async def demo():
src = StaticBearer("my-static-token")
bearer = RenewableBearer(src)
receiver = bearer.receiver()
tok = await receiver.fetch(timeout=5)
print(tok)
asyncio.run(demo())
Synchronous renewal request (waits for a fresh token, raising on timeout):
from nebius.aio.token.static import Bearer as StaticBearer
from nebius.aio.token.renewable import Bearer as RenewableBearer
from nebius.aio.token.renewable import (
OPTION_RENEW_SYNCHRONOUS,
OPTION_RENEW_REQUEST_TIMEOUT,
)
import asyncio
async def sync_demo():
src = StaticBearer("my-static-token")
bearer = RenewableBearer(src)
receiver = bearer.receiver()
options = {
OPTION_RENEW_SYNCHRONOUS: "1",
OPTION_RENEW_REQUEST_TIMEOUT: "2.0",
}
tok = await receiver.fetch(timeout=5, options=options)
print(tok)
asyncio.run(sync_demo())
| Class | |
Bearer that keeps a shared cached token refreshed in the background. |
| Class | |
Per-request receiver that delegates fetching to the renewable bearer. |
| Exception | |
Raised when a renewal operation is requested but the bearer is already stopped. |
| Exception | |
Base exception raised for renewal-related failures. |
| Constant | VERY |
If the timeout is not specified, this value will be used as the default. |
| Type Variable | T |
Undocumented |
| Variable | log |
Undocumented |