def save_pyl(
    python_literal,
    filepath,
    *,
    indent=2,
    width=80,
    compact=False,
):
    """Save pretty-formatted python literal in filepath."""

    with open(str(filepath), mode="w", encoding="utf-8") as f:

        try:

            f.write(
                pformat(
                    python_literal,
                    indent=indent,
                    width=width,
                    compact=compact,
                )
            )

        except Exception as err:

            message = f"Error while trying to save {filepath}."

            raise Exception(message) from err
Save pretty-formatted python literal in filepath.
nodezator/ourstdlibs/pyl.py