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 Extraction Functions

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

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

Extract a value from a nested dictionary using a dot-separated path

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

  • path (str) – Dot-separated path (e.g., “item.tradeItemInformation.0.tradeItemDescriptionModule”)

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

Returns:

The value at the path or the default value

Return type:

Any

oneworldsync.utils.extract_product_data(product_data)[source]

Extract relevant product data from a 1WorldSync product object based on the Swagger Search schema.

Parameters:

product_data (dict) – A product data dictionary from the 1WorldSync Search REST API

Returns:

A dictionary with structured product data

Return type:

dict

oneworldsync.utils.extract_search_results(search_results)[source]

Extract structured data from search results

Parameters:

search_results (dict) – Search results from the API

Returns:

Structured search results with metadata and products

Return type:

dict

oneworldsync.utils.get_primary_image(product_data)[source]

Get the primary image URL from product data

Parameters:

product_data (dict) – Product data

Returns:

Primary image URL or empty string if not found

Return type:

str

oneworldsync.utils.format_dimensions(dimensions)[source]

Format dimensions as a string

Parameters:

dimensions (dict) – Dimensions dictionary

Returns:

Formatted dimensions string

Return type:

str

Data Handling Functions

oneworldsync.utils.pretty_print_json(data)[source]

Pretty print JSON data

Parameters:

data (dict) – JSON data to print