class documentation

Bearer that creates receivers performing token exchange.

The bearer accepts either a concrete gRPC channel or an awaitable resolving to one. The channel is wrapped in a TokenExchangeServiceClient and used by receivers to perform the exchange RPC.

Example

Construct a bearer and use it to initialize the SDK:

from asyncio import Future
from nebius.sdk import SDK
from nebius.aio.token.exchangeable import Bearer
from nebius.base.service_account.pk_file import Reader as PKReader

# Create requester from private key
requester = PKReader(
    service_account_private_key_file_name="path/to/private_key.pem",
    service_account_id="your-service-account-id",
    service_account_public_key_id="your-public-key-id",
)

# Create a future for the channel that will be resolved with the SDK
channel_future = Future()

sdk = SDK(credentials=Bearer(requester=requester, channel=channel_future))

# Resolve the future with the newly created SDK
channel_future.set_result(sdk)
Parameters
requesterObject that knows how to build an exchange request for the current service account.
channelgRPC channel or awaitable resolving to one. If omitted, callers must call set_channel before obtaining a receiver.
max_retriesDefault retry attempts for receivers created by this bearer.
Method __init__ Create an exchangeable bearer.
Method receiver Return a Receiver that performs exchanges.
Method set_channel Set the gRPC channel or awaitable channel used for exchanges.
Instance Variable _max_retries Undocumented
Instance Variable _requester Undocumented
Instance Variable _svc Undocumented

Inherited from Bearer:

Async Method close Close the bearer and any wrapped resources.
Property name Optional human-readable name for the bearer.
Property wrapped Return the wrapped bearer or None if not wrapping.
def __init__(self, requester: TokenRequester, channel: ClientChannelInterface | DeferredChannel | None = None, max_retries: int = 2): (source)

Create an exchangeable bearer.

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

Return a Receiver that performs exchanges.

Returns
ReceiverA Receiver instance.
Raises
ValueErrorif no channel has been configured on the bearer.
def set_channel(self, channel: ClientChannelInterface | DeferredChannel | None): (source)

Set the gRPC channel or awaitable channel used for exchanges.

The function accepts either a concrete ClientChannelInterface or an awaitable resolving to one. When an awaitable is supplied, the bearer lazily constructs a stub coroutine that awaits the channel and then constructs the TokenExchangeServiceClient.

Parameters
channel:ClientChannelInterface | DeferredChannel | NoneThe channel or awaitable resolving to a channel.
_max_retries = (source)

Undocumented

_requester = (source)

Undocumented