Utilities API

The utils module provides utility functions for the 1WorldSync API client.

Timestamp Functions

oneworldsync.utils.format_timestamp(dt=None)[source]

Format a datetime object as a timestamp for the 1WorldSync API

Parameters:

dt (datetime, optional) – Datetime object to format. Defaults to current UTC time.

Returns:

Formatted timestamp

Return type:

str

oneworldsync.utils.parse_timestamp(timestamp_str)[source]

Parse a timestamp string from the 1WorldSync API

Parameters:

timestamp_str (str) – Timestamp string in ISO 8601 format

Returns:

Parsed datetime object

Return type:

datetime

Data Handling Functions

oneworldsync.utils.pretty_print_json(data)[source]

Pretty print JSON data

Parameters:

data (dict) – JSON data to print

oneworldsync.utils.extract_nested_value(data, path, default=None)[source]

Extract a value from a nested dictionary using a path

Parameters:
  • data (dict) – Dictionary to extract from

  • path (list) – List of keys to traverse

  • default – Value to return if path doesn’t exist

Returns:

The value at the path or the default value