Utils

Some helpful functions that are used throughout the API packages.

gwdc_python.utils.utils.remove_path_anchor(path)

Removes the path anchor, making it a relative path

Parameters

path (Path) – Path from which to strip anchor

Returns

Relative path

Return type

Path

gwdc_python.utils.utils.rename_dict_keys(input_obj, key_map)

Renames the keys in a dictionary

Parameters
  • input_obj (dict or list) – Object within which to recursively substitute dictionary keys

  • key_map (dict) – Dictionary which specifies old keys to be swapped with new keys in the input_obj, e.g {‘old_key’: ‘new_key’}

Returns

Copy of input_obj with old keys subbed for new keys

Return type

dict or list

gwdc_python.utils.utils.split_variables_dict(variables)

Recursively travel through a dict, replacing any instances of a file-like object with None and moving the file-like objects to a separate dict

Parameters

variables (dict) – Dictionary of variables for a graphql query

Returns

  • dict – Variables dictionary with all file-like objects replaced with None

  • dict – Dictionary containing the file-like objects with keys based on the paths in the variables dict

  • dict – Dictionary with keys and values corresponding to the paths of the file-like objects in the variables dict.