XDG Base Directories

6.0.2 · active · verified Sun Apr 12

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.

Warnings

Install

Imports

Quickstart

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.

from xdg_base_dirs import xdg_config_home, xdg_data_home, xdg_cache_home, xdg_runtime_dir

# Get the path to the user's XDG config directory
config_dir = xdg_config_home()
print(f"XDG Config Home: {config_dir}")

# Get the path to the user's XDG data directory
data_dir = xdg_data_home()
print(f"XDG Data Home: {data_dir}")

# Paths are returned as pathlib.Path objects
assert isinstance(config_dir, type(xdg_config_home()))

view raw JSON →