Skip to content

utils

ensembl.io.genomio.utils

Utils module.

get_json(src_path, **kwargs)

Generic data JSON loader.

Parameters:

Name Type Description Default
src_path StrPath

Path to the JSON file to load.

required
Source code in src/python/ensembl/io/genomio/utils/json_utils.py
26
27
28
29
30
31
32
33
34
def get_json(src_path: StrPath, **kwargs: Any) -> Any:
    """Generic data JSON loader.

    Args:
        src_path: Path to the JSON file to load.

    """
    with Path(src_path).open("r", encoding="utf-8") as json_file:
        return json.load(json_file, **kwargs)

print_json(dst_path, data, **kwargs)

Generic data JSON dumper to a file, with keys sorted and pretty-printed with indent 4 by default.

Parameters:

Name Type Description Default
dst_path StrPath

Path to the JSON file to create.

required
data Any

Any data to store into the file.

required
Source code in src/python/ensembl/io/genomio/utils/json_utils.py
37
38
39
40
41
42
43
44
45
46
47
48
def print_json(dst_path: StrPath, data: Any, **kwargs: Any) -> None:
    """Generic data JSON dumper to a file, with keys sorted and pretty-printed with indent 4 by default.

    Args:
        dst_path: Path to the JSON file to create.
        data: Any data to store into the file.

    """
    kwargs.setdefault("sort_keys", True)
    kwargs.setdefault("indent", 4)
    with Path(dst_path).open("w", encoding="utf-8") as json_file:
        json_file.write(json.dumps(data, **kwargs))