5.2.4. mixins

API model base classes and mixins.

class axonius_api_client.api.mixins.Model[source]

Bases: object

API model base class.

router

REST API routes definition for this API model.

class axonius_api_client.api.mixins.PageSizeMixin[source]

Bases: object

Mixins for models that utilize paging in their endpoints.

class axonius_api_client.api.mixins.ModelMixins(auth: axonius_api_client.auth.Model, **kwargs)[source]

Bases: axonius_api_client.api.mixins.Model, axonius_api_client.api.mixins.PageSizeMixin

Mixins for Model objects.

__init__(auth: axonius_api_client.auth.Model, **kwargs)[source]

Mixins for Model objects.

Parameters:
  • auth – object to use for auth and sending API requests
  • **kwargs – passed to _init()
_init(**kwargs)[source]

Post init method for subclasses to use for extra setup.

_build_err_msg(response: requests.models.Response, error: Optional[str] = None, exc: Optional[Exception] = None) → str[source]

Pass.

request(path: str, method: Optional[str] = 'get', raw: Optional[bool] = False, is_json: Optional[bool] = True, error_status: Optional[bool] = True, error_json_bad_status: Optional[bool] = True, error_json_invalid: Optional[bool] = True, **kwargs) → Union[requests.models.Response, Any][source]

Send a REST API request using auth.Mixins.http.

Parameters:
  • path – path to use in request
  • method – default get - method to use in request
  • raw

    default False -

    • if True return the raw requests.Response object
    • if False return the text or json of the response based on is_json
  • is_json

    default True - if raw is False:

    • if True return the decoded json of the response text body
    • if False return the text body of the response
  • error_status

    default True -

  • **kwargs – Passed to http.Http.__call__()
Returns:

Return type:

requests.Response or object or str

_check_response_code(response: requests.models.Response, error_status: bool = True)[source]

Check the status code of a response.

Parameters:
  • response – response object to check
  • error_status

    default True -

    • if True throw exc if response status code is bad
    • if False silently ignore bad response status codes
Raises:

ResponseNotOk – if response has a status code that is an error and error_status is True

_check_response_json(response: requests.models.Response, error_json_bad_status: Optional[bool] = True, error_json_invalid: Optional[bool] = True, uses_api_response: Optional[bool] = False) → Union[Any, str][source]

Check the text body of a response is JSON.

Parameters:
  • response (requests.Response) – response object to check
  • error_json_bad_status

    default True -

    • if True throw an exc if response is a json dict that has a non-empty error key or a status key that == error
    • if False ignore error and status keys in response json dicts
  • error_json_invalid

    default True -

    • if True throw an exc if response is invalid json
    • if False return the text of response if response is invalid json
Raises:
  • JsonInvalid – if error_json_invalid is True and response has invalid json
  • JsonError – if error_json_bad_status is True and response is a json dict that has a non-empty error key or a status key that == error
Returns:

  • object if response has json data
  • str if response has invalid json data

Return type:

object or str

class axonius_api_client.api.mixins.PagingMixinsObject[source]

Bases: axonius_api_client.api.mixins.PageSizeMixin

Pass.

get_by_uuid(value: str, **kwargs) → dict[source]

Get a single saved query by name.

Parameters:
  • name (str) – name of saved query to get
  • **kwargs – passed to get()
Returns:

saved query

Return type:

dict

get_by_name(value: str, **kwargs) → dict[source]

Get a single saved query by name.

Parameters:
  • name (str) – name of saved query to get
  • **kwargs – passed to get()
Returns:

saved query

Return type:

dict

get(generator: bool = False, **kwargs) → Union[Generator[dict, None, None], List[dict]][source]

Get objects for a given query using paging.

Parameters:
  • generator

    default False -

    • True: return an iterator for assets that will yield rows as they are fetched
    • False: return a list of rows after all have been fetched
  • **kwargs – passed to get_generator()
Yields:

dict – row if generator is True

Returns:

rows if generator is False

Return type:

list of dict

get_generator(query: Optional[str] = None, max_rows: Optional[int] = None, max_pages: Optional[int] = None, page_size: int = 2000, page_start: int = 0, page_sleep: int = 0, **kwargs) → Generator[dict, None, None][source]

Get saved queries using paging.

Parameters:
  • query (str, optional) –

    default None - filter rows to return

    This is NOT a query built by the query wizard!

  • page_size (int, optional) – default 0 - for paging, return N rows
  • max_rows (int, optional) – default None - return N assets
Returns:

list of saved query metadata

Return type:

list of dict

class axonius_api_client.api.mixins.ChildMixins(parent: axonius_api_client.api.mixins.Model)[source]

Bases: object

Mixins model for children of Mixins.

__init__(parent: axonius_api_client.api.mixins.Model)[source]

Mixins model for children of Model.

Parameters:parent (Model) – parent API model of this child
_init(parent: axonius_api_client.api.mixins.Model)[source]

Post init method for subclasses to use for extra setup.

Parameters:parent (Model) – parent API model of this child