platformdirs

4.9.4 · active · verified Sat Mar 28

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

Install

Imports

Quickstart

OOP API with ensure_exists, plus functional API demonstrating both str and Path return types.

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

view raw JSON →