gfw.common.io#

Module that contains simple IO utilities.

Functions

json_load

Opens JSON file.

json_save

Writes JSON file.

yaml_load

Loads a YAML file from the filesystem.

yaml_save

Saves a dictionary to a YAML file.

yaml_load(filename, **kwargs)[source]#

Loads a YAML file from the filesystem.

Parameters:
  • filename (str) – Path to the YAML file to be loaded.

  • **kwargs (Any) – Additional keyword arguments passed to yaml.safe_load().

Returns:

The Python object resulting from parsing the YAML file.

Return type:

Any

yaml_save(path, data, **kwargs)[source]#

Saves a dictionary to a YAML file.

Parameters:
  • path (str) – Path where the YAML file will be written.

  • data (dict[str, Any]) – Dictionary or other serializable Python object to save.

  • **kwargs (Any) – Additional keyword arguments passed to yaml.dump().

json_load(path, lines=False, coder=<class 'dict'>)[source]#

Opens JSON file.

Parameters:
  • path (Path) – The source path.

  • lines (bool) – If True, expects JSON Lines format.

  • coder (Callable[[...], Any]) – Coder to use when reading JSON records.

Return type:

List[dict[str, Any]] | dict[str, Any]

json_save(path, data, indent=4, lines=False)[source]#

Writes JSON file.

Parameters:
  • path (Path) – The destination path.

  • data (list[dict[Any, Any]]) – List of records to write.

  • indent (int) – Amount of indentation.

  • lines (bool) – If True, writes in JSON Lines format.

Return type:

Path