def _get_data_by_key(
    data: dict,
    key_dotted_path: str,
    default: Any = None,
    sep="__",
) -> Any:
    """
    Returns value found in data[key] using dot-path str (e.g, "path.to.key").
    Raises KeyError if not found
    """
    if not isinstance(data, DynaBox):
        data = DynaBox(data)  # DynaBox can handle insensitive keys

    if sep in key_dotted_path:
        key_dotted_path = key_dotted_path.replace(sep, ".")

    def handle_repr(value):
        # lazy values shouldnt be evaluated for inspecting
        if isinstance(value, Lazy):
            return value._dynaconf_encode()
        return value

    def traverse_data(data, path):
        # transform `a.b.c` in successive calls to `data['a']['b']['c']`
        path = path.split(".")
        root_key, nested_keys = path[0], path[1:]
        result = data._safe_get(root_key)
        for key in nested_keys:
            result = handle_repr(result._safe_get(key))
        return result

    try:
        return traverse_data(data, key_dotted_path)
    except KeyError:
        if not default:
            raise KeyError(f"Path not found in data: {key_dotted_path!r}")
        return default

    Returns value found in data[key] using dot-path str (e.g, "path.to.key").
    Raises KeyError if not found
    
dynaconf/utils/inspect.py