API

The details of classes and methods

class sumo.wrapper.sumo_client.SumoClient(env: str = 'prod', token: str | None = None, interactive: bool = True, devicecode: bool = False, verbosity: str = 'CRITICAL', retry_strategy=<sumo.wrapper._retry_strategy.RetryStrategy object>, timeout=Timeout(timeout=30.0), case_uuid=None, http_client=None, async_http_client=None, client_id: str | None = None)

Bases: object

Authenticate and perform requests to the Sumo API.

authenticate()
property blob_client: BlobClient

Get blob_client

Used for uploading blob using a pre-authorized blob URL.

Examples

Uploading blob:

blob = ...
blob_url = ...
sumo = SumoClient("dev")

sumo.blob_client.upload_blob(blob, blob_url)

Uploading blob async:

await sumo.blob_client.upload_blob_async(blob, blob_url)
client_for_case(case_uuid, interactive=False)

Instantiate and return new SumoClient for accessing the case identified by case_uuid.

create_shared_access_key_for_case(case_uuid)

Creates and stores a shared access key that can be used to access the case identified by case_uuid, in the current Sumo environment.

This shared access key can then be used by instantiating SumoClient with the parameter case_uuid set accordingly.

Parameters:

case_uuid – the uuid for a case.

Side effects:

Creates a new file in ~/.sumo, named {app_id}+{case_uuid}

delete(path: str, params: dict | None = None) Response

Performs a DELETE-request to the Sumo API.

Parameters:
  • path – Path to a Sumo endpoint

  • params – query parameters, as dictionary

Returns:

Sumo JSON response as a dictionary

Examples

Deleting object:

object_id = ...
sumo = SumoClient("dev")

sumo.delete(path=f"/objects('{object_id}')")
async delete_async(path: str, params: dict | None = None) Response

Performs an async DELETE-request to the Sumo API.

Parameters:
  • path – Path to a Sumo endpoint

  • params – query parameters, as dictionary

Returns:

Sumo JSON response as a dictionary

Examples

Deleting object:

object_id = ...
sumo = SumoClient("dev")

await sumo.delete_async(path=f"/objects('{object_id}')")
get(path: str, params: Dict | None = None) Response

Performs a GET-request to the Sumo API.

Parameters:
  • path – Path to a Sumo endpoint

  • params – query parameters, as dictionary

Returns:

Sumo JSON response as a dictionary

Examples

Retrieving user data from Sumo:

sumo = SumoClient("dev")

userdata = sumo.get(path="/userdata")

Searching for cases:

sumo = SuomClient("dev")

cases = sumo.get(
    path="/search",
    query="class:case",
    size=3
)
getLogger(name)

Gets a logger object that sends log objects into the message_log index for the Sumo instance.

Parameters:

name – string naming the logger instance

Returns:

logger instance

See Python documentation for logging.Logger for details.

async get_async(path: str, params: dict | None = None) Response

Performs an async GET-request to the Sumo API.

Parameters:
  • path – Path to a Sumo endpoint

  • params – query parameters, as dictionary

Returns:

Sumo JSON response as a dictionary

Examples

Retrieving user data from Sumo:

sumo = SumoClient("dev")

userdata = await sumo.get_async(path="/userdata")

Searching for cases:

sumo = SuomClient("dev")

cases = await sumo.get_async(
    path="/search",
    query="class:case",
    size=3
)
poll(response_in: Response, timeout=None) Response

Poll a specific endpoint until a result is obtained.

Parameters:

response_in – httpx.Response from a previous request, with ‘location’ and ‘retry-after’ headers.

Returns:

A new httpx.response object.

async poll_async(response_in: Response, timeout=None) Response

Poll a specific endpoint until a result is obtained.

Parameters:

response_in – httpx.Response from a previous request, with ‘location’ and ‘retry-after’ headers.

Returns:

A new httpx.response object.

post(path: str, blob: bytes | None = None, json: dict | None = None, params: dict | None = None) Response

Performs a POST-request to the Sumo API.

Takes either blob or json as a payload, will raise an error if both are provided.

Parameters:
  • path – Path to a Sumo endpoint

  • blob – Blob payload

  • json – Json payload

  • params – query parameters, as dictionary

Returns:

Sumo response object

Raises:

ValueError – If both blob and json parameters have been provided

Examples

Uploading case metadata:

case_metadata = {...}
sumo = SumoClient("dev")

new_case = sumo.post(
    path="/objects",
    json=case_metadata
)

new_case_id = new_case.json()["_id"]

Uploading object metadata:

object_metadata = {...}
sumo = SumoClient("dev")

new_object = sumo.post(
    path=f"/objects('{new_case_id}')",
    json=object_metadata
)
async post_async(path: str, blob: bytes | None = None, json: dict | None = None, params: dict | None = None) Response

Performs an async POST-request to the Sumo API.

Takes either blob or json as a payload, will raise an error if both are provided.

Parameters:
  • path – Path to a Sumo endpoint

  • blob – Blob payload

  • json – Json payload

  • params – query parameters, as dictionary

Returns:

Sumo response object

Raises:

ValueError – If both blob and json parameters have been provided

Examples

Uploading case metadata:

case_metadata = {...}
sumo = SumoClient("dev")

new_case = await sumo.post_async(
    path="/objects",
    json=case_metadata
)

new_case_id = new_case.json()["_id"]

Uploading object metadata:

object_metadata = {...}
sumo = SumoClient("dev")

new_object = await sumo.post_async(
    path=f"/objects('{new_case_id}')",
    json=object_metadata
)
put(path: str, blob: bytes | None = None, json: dict | None = None) Response

Performs a PUT-request to the Sumo API.

Takes either blob or json as a payload, will raise an error if both are provided.

Parameters:
  • path – Path to a Sumo endpoint

  • blob – Blob payload

  • json – Json payload

Returns:

Sumo response object

async put_async(path: str, blob: bytes | None = None, json: dict | None = None) Response

Performs an async PUT-request to the Sumo API.

Takes either blob or json as a payload, will raise an error if both are provided.

Parameters:
  • path – Path to a Sumo endpoint

  • blob – Blob payload

  • json – Json payload

Returns:

Sumo response object