Skip to content

sok.config.session_manager

Session Manager - Centralized management of sessions and API keys.

This module provides utilities for retrieving sessions and API keys from configuration.

Functions

get_api_key

def get_api_key(config: ConfigManager, service_id: str) -> str:

Retrieve the API key for a service from config or environment.

Parameters

NameTypeDescription
configConfigManagerConfigManager instance.
service_idstrService identifier.

Returns

  • strAPI key string or empty string if not found.
Source

get_igdb_token

def get_igdb_token(config: ConfigManager, renew: bool = False) -> Optional[str]:

The Twitch token that IGDB asks for, made from the client ID and secret.

The token is asked from Twitch (client credentials) the first time, kept in memory until an hour before it expires (about 60 days), and asked again when renew is set (IGDB refused it). Nothing is saved: the server and the desktop app each ask for their own.

Parameters

NameTypeDefaultDescription
configConfigManagerConfigManager instance.
renewboolFalseAsk for a new token even if the one kept is still valid.

Returns

  • Optional[str]IGDB access token string, or None without the client ID and secret
  • Optional[str]or when Twitch does not answer.
Source

get_session_data

def get_session_data(
config: ConfigManager,
service_id: str,
) -> Optional[Dict[str, Any]]:

Extract session data for a service from the config.

Works for all services (tmdb, lastfm, tvdb, etc.).

Parameters

NameTypeDescription
configConfigManagerConfigManager instance.
service_idstrService identifier (tmdb, tvdb, lastfm, etc.).

Returns

  • Optional[Dict[str, Any]]Dictionary containing session data or None if not found.
Source

get_spotify_token

def get_spotify_token(config: ConfigManager) -> Optional[str]:

Extract the Spotify token from the config.

Parameters

NameTypeDescription
configConfigManagerConfigManager instance.

Returns

  • Optional[str]Spotify access token string or None if not found.
Source

get_tmdb_session_id

def get_tmdb_session_id(config: ConfigManager) -> Optional[str]:

Extract the TMDB session_id from the config.

Parameters

NameTypeDescription
configConfigManagerConfigManager instance.

Returns

  • Optional[str]TMDB session ID string or None if not found.
Source

get_tvdb_token

def get_tvdb_token(config: ConfigManager) -> Optional[str]:

Extract the TVDB token from the config.

Parameters

NameTypeDescription
configConfigManagerConfigManager instance.

Returns

  • Optional[str]TVDB token string or None if not found.
Source

Attributes

NameValue
TOKEN_MARGIN_SECONDS3600
TWITCH_TOKEN_URL'https://id.twitch.tv/oauth2/token'
loggerlogging.getLogger(__name__)
Built with Kiln