sams_client.utils – Client side utils

load_config(config: Dict[str, Any])Dict[str, str]

Load host, port from config

Parameters

config (dict) – Dictionary of configuration provided

Return type

dict

Returns

A dictionary containing base_url, auth_type and auth_key

schema_relation(resource: str, embeddable: bool = True, required: bool = False, data_type: str = 'objectid', nullable: bool = False, readonly: bool = False)Dict[str, Any]

Creates an Eve/Cerberus relation attribute

This is copied from superdesk.resource.rel so that we don’t have to import Superdesk-Core for the sams_client library

Parameters
  • resource (str) – The name of the resource

  • embeddable (bool) – If the relation can be embedded when fetching

  • required (bool) – If this relation is required, for validation purposes

  • data_type (str) – The data type to apply to the schema, defaults to ‘objectid’

  • nullable (bool) – If this relation can have a null value

  • readonly (bool) – If this relation is read-only

Returns

A dictionary to apply to a Resource schema

Return type

dict

bytes_to_human_readable(size: int)str

Converts size in bytes to a human readable string

Converts the integer provided into one of the following:
  • 'x bytes'

  • 'x.yy KB' (to 2 decimal places)

  • 'x.yy MB' (to 2 decimal places)

Parameters

size (int) – Size in bytes to convert

Returns

A human readable string

Return type

int

get_aggregation_buckets(response: requests.models.Response, bucket_name: str)List[Dict[str, Any]]

Utility function to get aggregation buckets

Parameters
  • response (requests.Response) – The response object from the API call

  • bucket_name (str) – The name of the bucket to retrieve

Returns

The list of buckets from the aggregation query

Return type

list