Skip to main content

xdg-base-dirs

xdg-base-dirs is a Python module that provides functions to return paths to the directories defined by the XDG Base Directory Specification, to save you from duplicating the same snippet of logic in every Python utility you write that deals with user cache, configuration, or data files. It has no external dependencies and consists of a single file, making it easy to integrate.

xdg-base-dirs currently implements version 0.8 of the specification, released on 8th May 2021.

Installation

xdg-base-dirs requires Python 3.10 or later. To add xdg-base-dirs as a dependency to a project managed with uv, use:

uv add xdg-base-dirs

Alternatively, since xdg-base-dirs is only a single file you may prefer to just copy src/xdg_base_dirs/__init__.py from the source distribution into your project.

Usage

from xdg_base_dirs import (
    xdg_cache_home,
    xdg_config_dirs,
    xdg_config_home,
    xdg_data_dirs,
    xdg_data_home,
    xdg_runtime_dir,
    xdg_state_home,
)

xdg_cache_home(), xdg_config_home(), xdg_data_home(), and xdg_state_home() return pathlib.Path objects containing the value of the environment variable named XDG_CACHE_HOME, XDG_CONFIG_HOME, XDG_DATA_HOME, and XDG_STATE_HOME respectively, or the default defined in the specification if the environment variable is unset, empty, or contains a relative path. Only absolute paths are considered valid; any relative path causes the function to return the specification's default value.

xdg_config_dirs() and xdg_data_dirs() return a list of pathlib.Path objects containing the values from the colon-separated environment variables XDG_CONFIG_DIRS and XDG_DATA_DIRS respectively. These variables define search paths where multiple directories can be specified. When parsing the colon-separated values, relative paths are filtered out entirely. If the environment variable is unset, empty, or contains only relative paths, the specification's default list is returned instead.

xdg_runtime_dir() returns a pathlib.Path object containing the value of the XDG_RUNTIME_DIR environment variable, or None if the environment variable is not set or contains a relative path. Unlike the other functions, this returns None rather than a default path because the XDG specification requires this directory to be provided by the system runtime environment.

All returned paths are used exactly as specified in the environment variables or defaults, without additional normalisation or resolution of symbolic links. This preserves the original paths as intended by the system configuration.

Copyright © Scott Stevenson.

xdg-base-dirs is distributed under the terms of the ISC license.

Metadata

Release files for xdg-base-dirs 6.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xdg-base-dirs 6.0.3
File Size Uploaded
xdg_base_dirs-6.0.3.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xdg-base-dirs 6.0.3
File Interpreter ABI Platform
xdg_base_dirs-6.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / xdg_base_dirs-6.0.3.tar.gz

Download URL xdg_base_dirs-6.0.3.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9e8274f6d2514b587d257bda21d7fcf758180343c4ad5a47be0b202548211ec2
BLAKE2b-256 checksum
How to use checksums
ae3b4dc3f77ec9c5073467d95b9c9ded466cfba9a8b71a889096a01ac94b9b4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / xdg_base_dirs-6.0.3-py3-none-any.whl

Download URL xdg_base_dirs-6.0.3-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c80886a8f4e369d6148fdebd7abf182bf053ce6c744f7b7eec5853fec835ff44
BLAKE2b-256 checksum
How to use checksums
3c7be1376eb2e5c3c0c7feca70687ba1def829d848b607a7e8d1811ea9a2c155
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

6.0.3 This release

2 release files

6.0.2

2 release files

6.0.1

2 release files

6.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page