4.7.1.1. API models

API model base classes and mixins.

class axonius_api_client.api.mixins.Model[source]

Bases: object

API model base class.

abstract property router

REST API routes definition for this API model.

Return type

axonius_api_client.api.routers.Router

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

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

Mixins for API Models.

Parameters

auth (axonius_api_client.auth.models.Model) –

__init__(auth, **kwargs)[source]

Mixins for API Models.

Parameters
LOG: logging.Logger

Logger for this object.

auth

axonius_api_client.auth.models.Mixins authentication object.

http

axonius_api_client.http.Http client to use to send requests,

_init(**kwargs)[source]

Post init method for subclasses to use for extra setup.

__str__()[source]

Show info for this model object.

Return type

str

__repr__()[source]

Show info for this model object.

Return type

str

_build_err_msg(response, error=None, exc=None)[source]

Build an error message from a response.

Parameters
Return type

str

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

Send a REST API request.

Parameters
  • path (str) – path to use in request

  • method (str) – method to use in request

  • raw (bool) – return the raw response object

  • is_json (bool) – return the response as deserialized json or just return the text body

  • error_status (bool) – throw error if response has a bad status code

  • error_json_bad_status (bool) – throw error if json response has non-empty error key

  • error_json_invalid (bool) – throw error if response can not be deserialized into json

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

  • empty_ok (bool) –

Return type

typing.Any

Returns

requests.Response or str or dict or int or list

_check_response_code(response, error_status=True)[source]

Check the status code of a response.

Parameters
  • responserequests.Response object to check

  • error_status (bool) – throw exc if response status code is bad

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

Check the text body of a response is JSON.

Parameters
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

Return type

typing.Any

abstract property router

REST API routes definition for this API model.

Return type

axonius_api_client.api.routers.Router

class axonius_api_client.api.mixins.PagingMixinsObject[source]

Bases: axonius_api_client.api.mixins.PageSizeMixin

Mixins for API models that support object paging.

get_by_uuid(value, **kwargs)[source]

Get an object by UUID.

Parameters
  • value (str) – uuid of object to get

  • **kwargs – passed to get()

Return type

dict

get_by_name(value, **kwargs)[source]

Get an object by name.

Parameters
  • value (str) – name of object ot get

  • **kwargs – passed to get()

Return type

dict

get(generator=False, **kwargs)[source]

Get objects for a given query using paging.

Parameters
  • generator (bool) – return an iterator for objects that will yield rows as they are fetched

  • **kwargs – passed to get_generator()

Return type

typing.Union[typing.Generator[dict, None, None], typing.List[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 (typing.Optional[str]) – mongo query to filter objects to return

  • max_rows (typing.Optional[int]) – only return N objects

  • max_pages (typing.Optional[int]) – only return N pages

  • page_size (int) – fetch N objects per page

  • page_start (int) – start at page N

  • page_sleep (int) – sleep for N seconds between each page fetch

Return type

typing.Generator[dict, None, None]

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

Bases: object

Mixins model for API child objects.

Parameters

parent (axonius_api_client.api.mixins.Model) –

__init__(parent)[source]

Mixins model for API child objects.

Parameters

parent (axonius_api_client.api.mixins.Model) – parent API model of this child

_init(parent)[source]

Post init method for subclasses to use for extra setup.

Parameters

parent (axonius_api_client.api.mixins.Model) – parent API model of this child

__str__()[source]

Show info for this model object.

Return type

str

__repr__()[source]

Show info for this model object.

Return type

str