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

Router for this API model.

Returns:REST API route defs
Return type:routers.Router
class axonius_api_client.api.mixins.PageSizeMixin[source]

Bases: object

Pass.

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

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

Mixins for Model objects.

__init__(auth, **kwargs)[source]

Mixins for Model objects.

Parameters:
  • auth (auth.Model) – object to use for auth and sending API requests
  • **kwargs – passed to Mixins._init()
LOG = None

Logger for this object.

Type:logging.Logger
auth = None

object to use for auth and sending API requests.

Type:auth.Model
_init(auth, **kwargs)[source]

Post init method for subclasses to use for extra setup.

Parameters:auth (auth.Model) – object to use for auth and sending API requests
_build_err_msg(response, error=None, exc=None)[source]

Pass.

request(path, method='get', raw=False, is_json=True, error_status=True, error_json_bad_status=True, error_json_invalid=True, **kwargs)[source]

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

Parameters:
  • path (str) – path to use in request
  • method (str, optional) – default get - method to use in request
  • raw (bool, optional) –

    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 (bool, optional) –

    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 (bool, optional) –

    default True -

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

Return type:

requests.Response or object or str

_check_response_code(response, error_status=True)[source]

Check the status code of a response.

Parameters:
  • response (requests.Response) – response object to check
  • error_status (bool, optional) –

    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, error_json_bad_status=True, error_json_invalid=True)[source]

Check the text body of a response is JSON.

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

    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 (bool, optional) –

    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, **kwargs)[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, **kwargs)[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=False, **kwargs)[source]

Get objects for a given query using paging.

Parameters:
  • generator (bool, optional) –

    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=None, max_rows=None, max_pages=None, page_size=2000, page_start=0, page_sleep=0, **kwargs)[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)[source]

Bases: object

Mixins model for children of Mixins.

__init__(parent)[source]

Mixins model for children of Model.

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

Post init method for subclasses to use for extra setup.

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