from typing import Any


def py_to_yang(val: Any) -> str:
    """
    Convert a python value to a string following how it would be stored in a libyang
    data tree. Also suitable for comparison with YANG list keys (which are always
    strings).
    """
    if isinstance(val, str):
        return val
    if val is True:
        return "true"
    if val is False:
        return "false"
    return str(val)