Util

py42.util.convert_datetime_to_timestamp_str(date)

Converts the given datetime to a formatted date str. The format matches strftime directives %Y-%m-%dT%H:%M:%S.%f.

Parameters

date (datetime) – The datetime object to convert.

Returns

A str representing the given date. Example output looks like ‘2020-03-25T15:29:04.465Z’.

Return type

(str)

py42.util.convert_timestamp_to_str(timestamp)

Converts the given POSIX timestamp to a date str. The format matches strftime directives %Y-%m-%dT%H:%M:%S.%f.

Parameters

timestamp (float) – A POSIX timestamp.

Returns

A str representing the given timestamp. Example output looks like ‘2020-03-25T15:29:04.465Z’.

Return type

(str)

py42.util.format_json(json_string)

Converts a minified JSON str to a prettified JSON str.

Parameters

json_string (str) – A str representing minified JSON.

Returns

A str representing prettified JSON.

Return type

(str)

py42.util.print_response(response, label=None)

Prints a py42.response.Py42Response as prettified JSON. If unable to load, it prints the given response.

Parameters
  • response (py42.response.Py42Response) – The response to print.

  • label (str, optional) – A label at the beginning of the printed text. Defaults to None.