xdg
Variables defined by the XDG Base Directory Specification
What it is and what it does
xdg is a lightweight utility that implements version 0.8 of the XDG Base Directory Specification, a standard for where user applications should store configuration, cache, data, and runtime files on Unix-like systems. It exports functions that return pathlib.Path objects for each directory type, respecting environment variables like XDG_CONFIG_HOME and XDG_DATA_HOME when set to absolute paths, and falling back to specification defaults otherwise. The module has no external dependencies and is small enough to copy into a project if you prefer not to add a package dependency.
The package handles the common pattern of checking environment variables, validating paths (rejecting relative paths), and providing sensible defaults—logic that would otherwise be duplicated across many utilities. It returns Path objects rather than strings, making it natural to use with modern Python filesystem code. The implementation is stable and straightforward, suitable for any application that needs to follow XDG conventions on Linux and other Unix systems.
Use it for:
- Store application configuration files in the user's XDG config directory instead of hardcoding paths.
- Retrieve cache and temporary data directories for a CLI tool or daemon that respects system standards.
- Build a utility that uses XDG paths on Unix and falls back gracefully on Windows.
- Ensure a Python application respects user environment overrides for where data should be stored.
- Implement multi-directory search paths for config files using xdg_config_dirs() to check system-wide and user directories.
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 user cache, configuration, data, and runtime directories, returning pathlib.Path objects with sensible defaults.
Yes. The package is lightweight, has no dependencies, solves a real problem (avoiding duplicated XDG logic), and is actively maintained despite infrequent releases. The ISC license is permissive. Install it if your application needs to follow XDG standards on Unix systems; if you only target Windows or have trivial directory needs, it may be overkill.
Install
xdg on PyPI
pip
pip install xdguv
uv add xdgpoetry
poetry add xdgInstalling xdg
Before you install
Low friction: pure Python, single-file module with zero runtime dependencies. Last release was 2023-02-27, but repo shows active maintenance with a commit on 2026-08-02, so the long gap between releases does not indicate abandonment.
License in practice
ISC license is permissive and poses no restrictions on commercial or proprietary use. You can use, modify, and distribute this package freely with minimal obligations.
Quickstart
pip install xdg-base-dirs
from xdg import xdg_cache_home, xdg_config_home, xdg_data_home
cache_dir = xdg_cache_home()
config_dir = xdg_config_home()
data_dir = xdg_data_home()
Requires Python >=3.7,<4.0 according to metadata; description notes 3.10 as minimum for current versions.
Verify before relying
- Whether Python 3.7-3.9 support listed in classifiers is actively maintained or outdated.
- Current test coverage and whether all XDG specification edge cases (relative paths, empty vars) are well-handled.
- Whether the single-file design means copying src/xdg_base_dirs/__init__.py into a project is a practical alternative to package installation.
Package facts
| License | ISC (permissive) |
| Python support | supports the current Python release (>=3.7,<4.0) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 1,264 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 674,715/month — #5,389 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: xdg-6.0.0-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
xdg-base-dirsProvides functions to retrieve XDG Base…
permissive · top 15,000 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
pytest-envA pytest plugin that loads environment…
permissive · top 1,000 on PyPI
path.pyProvides Path objects that wrap filesystem…
permissive · top 15,000 on PyPI
pystowPyStow provides a standardized way to store and…
permissive · top 15,000 on PyPI
emportEmport provides a single function to import…
permissive · top 15,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