Request Manager¶
HTTP request management for pykada.
VerkadaRequestManager is the single HTTP layer used by all product
clients. It handles token injection, configurable retry/backoff, and maps
HTTP error status codes to typed pykada.exceptions.
iterate_paginated_results() is a static generator that transparently
walks all pages of any paginated Verkada endpoint.
- class pykada.verkada_requests.VerkadaRequestManager(timeout_seconds=30, max_retries=3, backoff_factor=0.5, retry_delay_seconds=0.1, token_manager=None, api_key=None)[source]¶
Bases:
objectManages HTTP requests to the Verkada API with support for retries, exponential backoff, and token-based authentication.
Initialize the RequestManager with customizable parameters.
- Parameters:
timeout_seconds (
int) – Default timeout for requests.max_retries (
int) – Maximum number of retries for failed requests.backoff_factor (
float) – Backoff multiplier for exponential backoff.token_manager (
Optional[VerkadaTokenManager]) – Optional token manager for authentication.retry_delay_seconds (float)
api_key (str | None)
- get_default_headers()[source]¶
Build default headers to be merged with any customer headers later on.
- Return type:
- get_token()[source]¶
Retrieve a Verkada API Token from the token manager and return it.
- Returns:
A valid Verkada API token
- Return type:
- static iterate_paginated_results(paginated_func, items_key=None, initial_params=None, next_token_key=None, default_page_size=100, request_delay_seconds=0)[source]¶
Iterates through all pages of results from a paginated function.
- Parameters:
paginated_func (
Callable[...,dict]) – The function that fetches a single page of results. It must accept ‘page_size’ and ‘page_token’ in its parameters and return a dict containing a list of items under ‘items_key’ and the next page token under ‘next_token_key’.initial_params (
Optional[dict]) – A dictionary of parameters for the first API call, excluding ‘page_size’ and ‘page_token’. This dict will be deep copied before use.items_key (
Optional[str]) – The key in the response dictionary that contains the list of items for the current page (e.g., ‘alerts’, ‘items’, ‘data’).next_token_key (
Optional[str]) – The key in the response dictionary that contains the token for the next page (e.g., ‘next_page_token’, ‘page_token’). Should be None when there are no more pages.default_page_size (
Optional[int]) – The page size to use if not specified in initial_params.request_delay_seconds (
Optional[float]) – Optional delay in seconds between fetching pages.
- Yields:
Each individual item from the paginated results across all pages.
- Return type: