class documentation

Bearer that provides file-backed Receiver instances.

The bearer accepts either a string path or a pathlib.Path and expands the user's home directory. It does not validate the existence of the file at construction time. Tokens are cached for refresh_period seconds; pass 0 to keep a successfully-read token cached until an authentication failure invalidates it.

Example

Construct a bearer and use it to initialize the SDK:

from nebius.sdk import SDK
from nebius.aio.token.file import Bearer

sdk = SDK(credentials=Bearer("~/nebius.token"))
Parameters
fileFilesystem path (string or pathlib.Path) to the token file. Tilde expansion is performed.
refresh_periodCache freshness window in seconds. Defaults to five minutes.
metricsOptional auth metrics callbacks used to record file reads, cache hits, cache misses, and invalidations.
Method __init__ Create a bearer for the given token file.
Method fetch_token Return a cached file token or read and cache it from disk.
Method receiver Return a Receiver that reads tokens from the file.
Method set_metrics Attach auth metrics callbacks used by subsequently created receivers.
Method should_retry_after_error Invalidate cached token and return whether the file token changed.
Method _invalidate_cache Undocumented
Method _read_token_value Undocumented
Instance Variable _cached_token Undocumented
Instance Variable _file Undocumented
Instance Variable _metrics Undocumented
Instance Variable _refresh_at Undocumented
Instance Variable _refresh_period Undocumented

Inherited from Bearer:

Class Method default_metrics_provider Return this bearer's default fully qualified metric provider label.
Async Method close Close the bearer and any wrapped resources.
Property metrics_provider Provider label used for auth metrics.
Property name Optional human-readable name for the bearer.
Property wrapped Return the wrapped bearer or None if not wrapping.
def __init__(self, file: str | Path, refresh_period: float = 5 * 60, metrics: AuthMetricsLike = None): (source)

Create a bearer for the given token file.

def fetch_token(self) -> Token: (source)

Return a cached file token or read and cache it from disk.

def receiver(self) -> Receiver: (source)

Return a Receiver that reads tokens from the file.

Returns
ReceiverA new Receiver bound to the configured file.
def set_metrics(self, metrics: AuthMetricsLike): (source)

Attach auth metrics callbacks used by subsequently created receivers.

def should_retry_after_error(self, token: Token) -> bool: (source)

Invalidate cached token and return whether the file token changed.

def _invalidate_cache(self): (source)

Undocumented

def _read_token_value(self) -> str: (source)

Undocumented

_cached_token: Token | None = (source)

Undocumented

Undocumented

_metrics = (source)

Undocumented

_refresh_at: float = (source)

Undocumented

_refresh_period = (source)

Undocumented