The `xdg-base-dirs` library provides Python functions to retrieve paths adhering to the XDG Base Directory Specification, which defines standard locations for user-specific data, configuration, and cache files. As of version 6.0.2, it is actively maintained with frequent minor updates and fixes, and a major release approximately once a year.
pip install xdg-base-dirsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and use the XDG functions to retrieve standard directory paths. The functions return `pathlib.Path` objects, which are the recommended way to handle file system paths in modern Python.
Change `pip install xdg` to `pip install xdg-base-dirs` and `import xdg` to `from xdg_base_dirs import ...`.
Ensure your project is running on Python 3.10 or newer.
Replace `xdg.XDG_CONFIG_HOME` with `xdg_config_home()` and similar for other paths.
If string paths are required, wrap the `pathlib.Path` object in `os.fspath()`. Example: `import os; config_path_str = os.fspath(xdg_config_home())`.
Ensure that any custom XDG environment variables are set to absolute paths.
pip install xdg-base-dirs
import xdg_base_dirs path = xdg_base_dirs.xdg_cache_home()
import xdg_base_dirs
No dependency data recorded yet.