def get_debug_info(
    settings: Settings | LazySettings,
    verbosity: int = 0,
    key: str | None = None,
) -> dict:
    """Returns a dict with debug info about the settings object"""

    if key:
        verbosity = 2

    def filter_by_key(data: dict) -> dict:
        """If key is not None, filter dict keeping only the key"""
        if key and data:
            try:
                return {key: _get_data_by_key(data, key)}
            except KeyError:
                return {}
        return data

    def build_loading_history() -> list[dict]:
        _data = []
        for (
            source_metadata,
            source_data,
        ) in settings._loaded_by_loaders.items():
            _real_data = filter_by_key(source_data)
            if verbosity == 0:
                _data.append(
                    {
                        "loader": source_metadata.loader,
                        "identifier": source_metadata.identifier,
                        "data": len(_real_data),
                    }
                )
            elif verbosity == 1:
                _data.append(
                    {
                        "loader": source_metadata.loader,
                        "identifier": source_metadata.identifier,
                        "data": list(_real_data.keys()),
                    }
                )
            else:
                _data.append(
                    {
                        "loader": source_metadata.loader,
                        "identifier": source_metadata.identifier,
                        "data": _real_data,
                    }
                )
        return _data

    def build_loaded_hooks():
        _data = []
        for hook, hook_data in settings._loaded_hooks.items():
            _real_data = filter_by_key(hook_data.get("post", {})) or {}
            if verbosity == 0:
                _data.append(
                    {
                        "hook": str(hook),
                        "data": len(_real_data),
                    }
                )
            elif verbosity == 1:
                _data.append(
                    {
                        "hook": str(hook),
                        "data": list(_real_data.keys()),
                    }
                )
            else:
                _data.append(
                    {
                        "hook": str(hook),
                        "data": _real_data,
                    }
                )
        return _data

    data = {
        "versions": {
            "dynaconf": version("dynaconf"),
        },
        "root_path": settings._root_path,
        "validators": [str(v) for v in settings.validators],
        "core_loaders": settings._loaders,
        "loaded_files": settings._loaded_files,
        "history": build_loading_history(),
        "post_hooks": [str(h) for h in settings._post_hooks],
        "loaded_hooks": build_loaded_hooks(),
    }
    for name in ["django", "flask", "fastapi", "starlette"]:
        with suppress(PackageNotFoundError):
            data["versions"][name] = version(name)

    if settings.get("ENVIRONMENTS_FOR_DYNACONF"):
        environments = settings.get("ENVIRONMENTS_FOR_DYNACONF")
        if isinstance(environments, (list, tuple)):
            data["environments"] = list(environments)
        else:
            data["environments"] = environments
        data["loaded_envs"] = settings._loaded_envs

    if key:
        data["current"] = {key: settings.get(key)}
    return data
Returns a dict with debug info about the settings object
dynaconf/utils/inspect.py