Token Manager

Token management for pykada.

VerkadaTokenManager fetches and caches a short-lived Verkada API token, automatically refreshing it before expiry (25-minute buffer on a 30-minute token lifetime).

Module-level helpers get_default_token_manager() and get_default_api_token() provide a shared manager bootstrapped from the VERKADA_API_KEY environment variable (or a .env file).

class pykada.api_tokens.VerkadaTokenManager(api_key, token_url='https://api.verkada.com/token', response_json_key='token', token_lifetime_minutes=30)[source]

Bases: object

Manages a specific type of Verkada API token, caching it and refreshing it only when needed.

Initializes the token manager for a specific token type.

Parameters:
  • api_key (str) – Your Verkada API key.

  • token_url (str) – The URL endpoint to fetch this specific token (e.g., “https://api.verkada.com/token”).

  • response_json_key (str) – The key in the JSON response that holds the token value (e.g., “token” or “jwt”).

  • token_lifetime_minutes (int) – The expected lifetime of the token in minutes. Defaults to 30.

get_token()[source]

Retrieves the current valid API token. If the token is missing or about to expire, a new one is fetched.

Returns:

The valid Verkada API token.

Return type:

str

Module-level helpers

pykada.api_tokens.get_default_token_manager()[source]

Returns the default token manager instance for API tokens. This is useful for cases where you want to use the default token manager without explicitly importing it.

pykada.api_tokens.get_default_api_token()[source]

Retrieves the temporary Verkada API token using the cached manager.

Return type:

str