class documentation
Simple bearer wrapper that attaches a static name to another 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 underlying bearer.
Example
Wrap a custom bearer with a name and file cache:
from nebius.sdk import SDK
from nebius.aio.token.token import NamedBearer, Bearer, Receiver, Token
from nebius.aio.token.file_cache.async_renewable_bearer import (
AsynchronousRenewableFileCacheBearer
)
class SomeCustomHeavyLoadBearer(Bearer):
def receiver(self) -> Receiver:
return SomeReceiver()
class SomeReceiver(Receiver):
async def _fetch(self, timeout=None, options=None) -> Token:
# Simulate heavy load token fetch
return Token("heavy-token")
def can_retry(self, err, options=None) -> bool:
return False
custom_bearer = SomeCustomHeavyLoadBearer()
named_bearer = NamedBearer(custom_bearer, "heavy-load-bearer")
cached_bearer = AsynchronousRenewableFileCacheBearer(named_bearer)
sdk = SDK(credentials=cached_bearer)
| Parameters | |
| wrapped | The inner bearer to delegate to. |
| name | The name that reflects the configuration of the underlying
bearer. |
| Method | __init__ |
Wrap the passed-in bearer, attaching a name to it. |
| Method | receiver |
Delegate to the wrapped bearer to obtain a receiver. |
| Property | name |
Return the configured name for this bearer. |
| Property | wrapped |
Return the wrapped bearer. |
| Instance Variable | _name |
Undocumented |
| Instance Variable | _wrapped |
Undocumented |
Inherited from Bearer:
| Async Method | close |
Close the bearer and any wrapped resources. |
Wrap the passed-in bearer, attaching a name to it.
This name should reflect the unique configuration of the underlying bearer.
overrides
nebius.aio.token.token.Bearer.nameReturn the configured name for this bearer.
| Returns | |
| Always returns a name. |