xdg-base-dirs
Variables defined by the XDG Base Directory Specification
What it is and what it does
xdg-base-dirs is a lightweight utility that implements the XDG Base Directory Specification, a freedesktop.org standard that defines where Unix/Linux applications should store user-specific files like configuration, cache, and data. It returns pathlib.Path objects for each directory type, reading from the corresponding XDG environment variables (XDG_CONFIG_HOME, XDG_CACHE_HOME, etc.) and falling back to specification-defined defaults when those variables are unset, empty, or contain relative paths.
The package eliminates the need to duplicate XDG path logic across multiple utilities. It has zero runtime dependencies and is small enough to copy directly into a project if preferred. It supports Python 3.10 through 3.13 and is actively maintained.
Use it for:
- Store application configuration files in the user's XDG config directory instead of hardcoding ~/.config paths.
- Manage application cache files in XDG cache directories that respect user environment variable overrides.
- Build command-line tools that follow the XDG specification for multiplatform Unix/Linux compatibility.
- Retrieve runtime directories for temporary sockets or IPC files via xdg_runtime_dir().
- Access XDG data and state directories as lists to search multiple locations for application files.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides functions to retrieve XDG Base Directory Specification paths for cache, config, data, runtime, and state directories, returning pathlib.Path objects with sensible defaults when environment variables are unset.
Yes. This is a stable, dependency-free utility that solves a real problem for any Python tool dealing with user files on Unix/Linux systems. Low install friction, permissive license, active maintenance, and no known vulnerabilities make it a straightforward addition to projects that need XDG compliance.
Install
xdg-base-dirs on PyPI
pip
pip install xdg-base-dirsuv
uv add xdg-base-dirspoetry
poetry add xdg-base-dirsInstalling xdg-base-dirs
Before you install
Low friction: pure Python, no runtime dependencies, single-file distribution. Active maintenance with recent commits and stable release history since 2023.
License in practice
ISC license is permissive, allowing commercial and private use with minimal restrictions—suitable for most projects.
Quickstart
from xdg_base_dirs import xdg_config_home, xdg_cache_home
config_dir = xdg_config_home()
cache_dir = xdg_cache_home()
Requires Python 3.10 or later.
Verify before relying
- Whether the package handles Windows XDG paths correctly given the OS classifier includes Windows but XDG is primarily a Unix/Linux standard.
Package facts
| License | ISC (permissive) |
| Python support | supports the current Python release (<4.0,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 664 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 496,994/month — #6,333 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: xdg_base_dirs-6.0.2-py3-none-any.whl
Keywords: xdg, base, directory, specification
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
appdirsDetermines the correct platform-specific…
permissive · top 1,000 on PyPI
platformdirsDetermines platform-specific directories for…
permissive · top 100 on PyPI
pyprojrootFinds your project's root directory and…
permissive · top 15,000 on PyPI
scantreeRecursively scans directories with flexible…
permissive · top 5,000 on PyPI
findlibsLocates shared libraries on the system by…
permissive · top 5,000 on PyPI
pathlib-abcProvides abstract base classes for implementing…
permissive · top 1,000 on PyPI
pyrootutilsFinds your project root directory and…
permissive · top 5,000 on PyPI
pystowPyStow provides a standardized way to store and…
permissive · top 15,000 on PyPI
path.pyProvides Path objects that wrap filesystem…
permissive · top 15,000 on PyPI