platformdirs
platformdirs is a Python library for determining platform-specific system directories — user data, config, cache, logs, runtime, and more. It is the actively maintained community fork of the now-deprecated appdirs package, implementing the XDG Base Directory Spec on Linux, ~/Library conventions on macOS, and AppData on Windows, with additional Android support. Current version is 4.9.4 (released 2026-03-05); the project releases frequently, with multiple minor/patch releases per month during active development periods.
Warnings
- breaking macOS user_config_dir path has changed twice across major versions: 2.0.0 moved it to ~/Library/Preferences/<app>, then 3.0.0 moved it back to ~/Library/Application Support/<app>. Any stored config files at the old path will silently go unread after upgrading across these boundaries.
- breaking Linux user_log_dir was corrected in 2.6.0 from XDG_CACHE_HOME to XDG_STATE_HOME (i.e. ~/.cache/<app>/log → ~/.local/state/<app>/log). Existing log files at the old location are silently abandoned.
- breaking Platform detection happens at import time, not at call time. Monkeypatching sys.platform after import has no effect on which platform class is used. This differs from the old appdirs behavior.
- breaking Requires Python >=3.10 as of the current release series. Older Python versions are not supported.
- gotcha Directories are NOT created on disk by default. Accessing dirs.user_data_dir returns a string path but does not mkdir. Code that immediately opens a file in that path will raise FileNotFoundError.
- gotcha site_data_dir and site_config_dir with multipath=True return a colon-separated string on Unix (os.pathsep-joined), not a list. Iterating the string character-by-character is a common mistake.
- gotcha On Unix, running as root (uid 0) does NOT redirect user_*_dir to site_*_dir by default for backward compatibility. Root's XDG dirs point to /root/.local/share etc., not /usr/local/share.
Install
-
pip install platformdirs
Imports
- PlatformDirs
from platformdirs import PlatformDirs
- AppDirs
from platformdirs import AppDirs
- user_data_dir
from platformdirs import user_data_dir
- user_data_path
from platformdirs import user_data_path
- PlatformDirsABC
from platformdirs import PlatformDirsABC
Quickstart
from platformdirs import PlatformDirs, user_data_dir, user_config_path
# OOP API — preferred for repeated access to multiple dirs
dirs = PlatformDirs(appname="MyApp", appauthor="MyCompany", version="1.0", ensure_exists=True)
print(dirs.user_data_dir) # str: ~/.local/share/MyApp/1.0 (Linux)
print(dirs.user_config_dir) # str: ~/.config/MyApp/1.0 (Linux)
print(dirs.user_cache_dir) # str: ~/.cache/MyApp/1.0 (Linux)
print(dirs.user_log_dir) # str: ~/.local/state/MyApp/1.0/log (Linux)
print(dirs.user_state_dir) # str: ~/.local/state/MyApp/1.0 (Linux)
print(dirs.user_runtime_dir) # str: /run/user/<uid>/MyApp/1.0 (Linux)
# _path variants return pathlib.Path objects
print(dirs.user_data_path) # pathlib.Path
print(dirs.user_config_path) # pathlib.Path
# Functional API — one-off lookups
print(user_data_dir("MyApp", "MyCompany")) # str
print(user_config_path("MyApp", "MyCompany")) # pathlib.Path