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.11 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
Copyright © Scott Stevenson.
xdg-base-dirs is distributed under the terms of the ISC license.
Metadata
Release files for xdg-base-dirs 6.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xdg_base_dirs-6.1.0.tar.gz | 4.4 kB | With provenance | Details for xdg_base_dirs-6.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xdg_base_dirs-6.1.0-py3-none-any.whl | Python 3 | none | any | Details for xdg_base_dirs-6.1.0-py3-none-any.whl |
Total release size: 9.8 kB
Release files / xdg_base_dirs-6.1.0.tar.gz
| Download URL | xdg_base_dirs-6.1.0.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
552729eabe55170f285954374f29bb03ba6b6dea10910f48785e69cb95215a06
|
|
BLAKE2b-256 checksum How to use checksums |
0cd7e4723658e5a6e36de07c6b11428a83ad6d7cceaa5f28a77ac6dd46bc1565
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logRelease files / xdg_base_dirs-6.1.0-py3-none-any.whl
| Download URL | xdg_base_dirs-6.1.0-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
487d2f388037b310ca50fe322f706c41937db107215dccd060374e94fa16be6a
|
|
BLAKE2b-256 checksum How to use checksums |
0d7b57c565c9ffa1f0e6e4ae73f54fa760e92dc46ae343d5ad5a3f646ae8c891
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logSecurity for xdg-base-dirs 6.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for xdg_base_dirs-6.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.