tokens#
- class analytix.tokens.Tokens(access_token: str, expires_in: int, refresh_token: str, scope: str, token_type: str)#
A dataclass representing a set of tokens for a Google Developers project. This should generally be created using one of the available classmethods.
- Parameters
access_token – The token used to access services.
expires_in – The number of seconds until the token expires. This is not live updated by analytix, and so should not be used to track a token’s expiration.
refresh_token – The token used to refresh the access token.
scope – The scopes the token is authorised for. This is provided as a single string, where separate scopes are separated by a space.
token_type – The type of token. Will probably be “Bearer”.
- classmethod from_data(data: dict[str, TokenT]) Tokens #
Create an instance of this class from a dictionary.
- Parameters
data – The tokens as a dictionary.
- Returns
The created instance.
- classmethod from_file(path: pathlib.Path | str) Tokens #
Load a set of tokens from a file generated by analytix.
- Parameters
path – The path to the tokens file.
- Returns
The loaded tokens.
- async classmethod afrom_file(path: pathlib.Path | str) Tokens #
Asynchronously load a set of tokens from a file generated by analytix.
- Parameters
path – The path to the tokens file.
- Returns
The loaded tokens.
- update(data: dict[str, TokenT]) None #
Update token attributes.
Warning
This does not update the tokens on disk.
- Parameters
data – A dictionary of attributes to be updated.
- to_dict() dict[str, TokenT] #
Convert tokens to a dictionary.
- Returns
A dictionary of tokens, where the keys are strings, and the values are either strings or integers.
- write(path: pathlib.Path | str) None #
Write tokens to a file.
- Parameters
path – The path to the tokens file.
- async awrite(path: pathlib.Path | str) None #
Asynchronously write tokens to a file.
- Parameters
path – The path to the tokens file.