class documentation
class Token: (source)
Constructors: Token.empty(), Token.from_dict(data), Token(token, expiration)
Representation of a bearer token with optional expiration.
Behaviour notes
- str(Token) returns a sanitized representation using
nebius.base.token_sanitizer.TokenSanitizerto avoid logging secrets in plaintext. When expiration is present, the ISO timestamp and a relative expires_in delta are included in the representation. - to_dict serializes the token into a mapping with token and expires_at keys, where expires_at is an integer POSIX timestamp (or None when no expiration was set).
| Parameters | |
| token | The raw token string. May be empty for an "empty" token. |
| expiration | Optional UTC-aware expiration datetime. If provided,
is_expired checks against this value. |
| Class Method | empty |
Create an empty token. |
| Class Method | from |
Create a Token from a mapping produced by to_dict. |
| Method | __eq__ |
Equality comparison. |
| Method | __init__ |
Initialize a token with these token string and expiration |
| Method | __str__ |
Return a short, sanitized string representation. |
| Method | is |
Return True when the token string is empty. |
| Method | is |
Return True when the token is expired. |
| Method | to |
Serialize the token to a mapping. |
| Property | expiration |
The UTC-aware expiration datetime, or None if not set. |
| Property | token |
The raw token string. |
| Instance Variable | _exp |
Undocumented |
| Instance Variable | _tok |
Undocumented |
Create a Token from a mapping produced by to_dict.
| Parameters | |
data:typing.Any | Mapping with at least the token key and optional expires_at integer timestamp. |
| Returns | |
Token | A Token instance parsed from the mapping. |
| Raises | |
ValueError | When the input type is invalid or contains incompatible types. |
Return a short, sanitized string representation.
| Returns | |
str | A one-line safe representation of the token for debugging. |
Serialize the token to a mapping.
The mapping contains token and expires_at. expires_at is an integer POSIX timestamp when an expiration is set, otherwise None.
| Returns | |
dict | A dictionary serializable to JSON. |