class documentation

Abstract provider of Receiver instances.

A Bearer supplies receivers for per-request authenticators. Bearers may be composed (wrapping other Bearers) to add behaviour such as caching, refreshing, or naming.

Treat a stateful bearer as owned by one SDK. The built-in channel calls it on that SDK's internal event loop and closes it with the SDK. Do not attach one bearer instance to SDKs with different loops unless the implementation is thread-safe, loop-neutral, and explicitly supports concurrent use and independent close calls.

Example

Implement a custom bearer:

from nebius.sdk import SDK
from nebius.aio.token.token import Bearer, Receiver, Token

class MyBearer(Bearer):
    def receiver(self) -> Receiver:
        return MyReceiver()

class MyReceiver(Receiver):
    async def _fetch(self, timeout=None, options=None) -> Token:
        return Token("my-token")

    def can_retry(self, err, options=None) -> bool:
        return False

sdk = SDK(
    credentials=MyBearer(),
    user_agent_prefix="example-application/1.0",
)
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.
Method receiver Return a Receiver to be used for a single request.
Property acquisition_budget Return how long one fetch through this bearer can take, or None.
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.
@classmethod
def default_metrics_provider(cls) -> str: (source)

Return this bearer's default fully qualified metric provider label.

async def close(self, grace: float | None = None): (source)

Close the bearer and any wrapped resources.

Parameters
grace:optional floatOptional graceful shutdown timeout in seconds.

Return how long one fetch through this bearer can take, or None.

A cache that bounds a shared fetch asks only its immediate bearer for the budget. A bearer that owns an operation timeout returns it. A bearer that adds an operation to a wrapped bearer returns the composed budget. A transparent wrapper returns the budget of the wrapped bearer. The default is None: the bearer declares no budget, and a cache uses its own default. A non-positive budget means that the fetch fails at once.

@property
metrics_provider: str = (source)

Provider label used for auth metrics.

Custom bearers may override this property to control their metric provider label. By default the label is the fully qualified class name, or the wrapped bearer's provider label for wrapper bearers.

Optional human-readable name for the bearer.

This may be used in some wrapper providers to cache the results of the shared receiver, or to report diagnostics.

This name should reflect the unique configuration of the bearer.

If the bearer wraps another bearer, the default behaviour is to forward the name lookup to the wrapped instance.