devo_ml.modelmanager.api#

Low-level HTTP API Rest access in a Requests library wrapper.

decode_response(response)[source]#

Decodes a requests response to json.

Parameters:

response (Response) – The requests response

Return type:

Any

Returns:

A decoded response or None if any decode error.

validate_or_raise_error(status_code, response)[source]#

Checks whether a decoded response is valid.

Depend on the status code value will raise an exception. Only 2xx status code are considered valid.

Parameters:
  • status_code (int) – The http status code of a response. Depend on its value will raise an exception. Only 2xx status code are considered valid.

  • response (Any) – A decoded response. Just for give more information about the error when possible.

Raises:

ModelManagerError – If is not a valid status code.

Return type:

None

Returns:

Nothing

class Api(auth=None, **kwargs)[source]#

Low level api calls based on Requests lib.

__init__(auth=None, **kwargs)[source]#

Creates a Api.

Parameters:
__getattr__(attr)[source]#

Saves method to call if attr is a valid method. Otherwise, built-in followed.

Parameters:

attr – The attribute name to get

Returns:

The object itself or the attribute value

__call__(endpoint, **kwargs)[source]#

Call to an endpoint.

Parameters:
  • endpoint (str) – The endpoint to call

  • kwargs – Custom options to the underlying requests for this call

Return type:

Any

Returns:

The decoded response

request(endpoint, **kwargs)[source]#

Wraps a requests call to catch any error in ModelManagerError.

Parameters:
  • endpoint (str) – The endpoint to request

  • kwargs – Custom options to the underlying requests for this request. Will be merged with the options of the Api object.

Raises:

ModelManagerError – if any RequestException.

Return type:

Response

Returns:

Request response

build_request_options(**kwargs)[source]#

Builds the options for a request by merging the Api object request options with the options provided.

The options provided take precedence over the options in the Api object.

Parameters:

kwargs – Custom request options

Return type:

dict

Returns:

Merged request options