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.
pip install platformdirsVerified import paths — ran on the pinned version, not inferred.
OOP API with ensure_exists, plus functional API demonstrating both str and Path return types.
After upgrading from <2.x or <3.x, migrate existing config files from the old path (~/Library/Preferences/<app>) to the new path (~/Library/Application Support/<app>) on first launch. Pin your platformdirs version in production if you cannot migrate users automatically.
If upgrading from <2.6.0, migrate or symlink ~/.cache/<app>/log to ~/.local/state/<app>/log, or pin to <2.6.0 until migration is complete.
To test platform-specific paths in tests, reload the platformdirs module after patching sys.platform, or use unittest.mock.patch combined with importlib.reload(platformdirs).
Use platformdirs <4 for Python 3.8 or 3.9 support, or upgrade your Python runtime.
Pass ensure_exists=True to PlatformDirs() or the functional API call, or manually call Path(dirs.user_data_dir).mkdir(parents=True, exist_ok=True) before writing.
Split with dirs.site_data_dir.split(os.pathsep) or use the iter_data_dirs() / iter_config_dirs() iterator methods on the PlatformDirs instance to get individual Path objects.
Pass use_site_for_root=True to PlatformDirs() when you want system-wide paths when running as root on Unix.
pip install platformdirs
Add 'platformdirs' as a hidden import to your PyInstaller command or .spec file: `pyinstaller --hidden-import platformdirs your_script.py`
Explicitly include the platform-specific submodule as a hidden import in your PyInstaller command or .spec file: `pyinstaller --hidden-import platformdirs.macos your_script.py` (adjust 'macos' for other platforms like 'windows' or 'unix' if applicable).
Upgrade the 'platformdirs' package to the latest version or a version compatible with your dependent library: `pip install --upgrade platformdirs`
No dependency data recorded yet.