macOS
On macOS (sys.platform == "darwin"), PlatformDirs is platformdirs.macos.MacOS. It uses the standard ~/Library folders from Apple's File System Programming Guide, honors the XDG environment variables when they are set, and adjusts the site directories when Python comes from Homebrew. This page lists every directory and the macOS-specific rules.
Examples use appname="SuperApp"; appauthor, roaming, opinion and use_site_for_root have no effect on macOS. With version="1.0", app directories gain a trailing /1.0.
User Directories
| Property | Default | XDG override |
|---|---|---|
user_data_dir |
~/Library/Application Support/SuperApp |
$XDG_DATA_HOME/SuperApp |
user_config_dir |
~/Library/Application Support/SuperApp |
$XDG_CONFIG_HOME/SuperApp |
user_state_dir |
~/Library/Application Support/SuperApp |
$XDG_STATE_HOME/SuperApp |
user_preference_dir |
~/Library/Preferences/SuperApp |
none |
user_cache_dir |
~/Library/Caches/SuperApp |
$XDG_CACHE_HOME/SuperApp |
user_log_dir |
~/Library/Logs/SuperApp |
none |
user_runtime_dir |
~/Library/Caches/TemporaryItems/SuperApp |
$XDG_RUNTIME_DIR/SuperApp if valid |
user_documents_dir |
~/Documents |
XDG_DOCUMENTS_DIR |
user_downloads_dir |
~/Downloads |
XDG_DOWNLOAD_DIR |
user_pictures_dir |
~/Pictures |
XDG_PICTURES_DIR |
user_videos_dir |
~/Movies |
XDG_VIDEOS_DIR |
user_music_dir |
~/Music |
XDG_MUSIC_DIR |
user_desktop_dir |
~/Desktop |
XDG_DESKTOP_DIR |
user_projects_dir |
~/Projects |
XDG_PROJECTS_DIR |
user_publicshare_dir |
~/Public |
XDG_PUBLICSHARE_DIR |
user_templates_dir |
~/Templates (macOS has no native templates folder; this is a pragmatic fallback) |
XDG_TEMPLATES_DIR |
user_fonts_dir |
~/Library/Fonts |
$XDG_DATA_HOME/fonts |
user_bin_dir |
~/.local/bin |
none |
user_applications_dir |
~/Applications |
$XDG_DATA_HOME/applications |
Data, Config and State Share a Folder
user_data_dir, user_config_dir and user_state_dir all default to ~/Library/Application Support/SuperApp. If your app writes settings.json as config and as data, the files collide. Use distinct file names or subfolders:
from platformdirs import user_data_path
app_dir = user_data_path("SuperApp")
config_dir = app_dir / "config"
db_dir = app_dir / "databases"
Preferences
user_preference_dir is the one place where macOS differs from every other platform: it returns ~/Library/Preferences/SuperApp, Apple's location for user-adjustable preference files, instead of the config directory. It is not affected by XDG_CONFIG_HOME.
Media Directories
macOS has no user-dirs.dirs; the XDG_*_DIR environment variables are honored when absolute, otherwise the fixed defaults above are returned. Note that videos map to ~/Movies.
Site Directories
| Property | Default | With Homebrew Python |
|---|---|---|
site_data_dir |
/Library/Application Support/SuperApp |
<prefix>/share/SuperApp |
site_config_dir |
/Library/Application Support/SuperApp |
<prefix>/share/SuperApp |
site_cache_dir |
/Library/Caches/SuperApp |
<prefix>/var/cache/SuperApp |
site_state_dir |
/Library/Application Support/SuperApp |
<prefix>/share/SuperApp |
site_log_dir |
/Library/Logs/SuperApp |
unchanged |
site_runtime_dir |
same as user_runtime_dir |
unchanged |
site_bin_dir |
/usr/local/bin |
unchanged |
site_applications_dir |
/Applications |
unchanged |
XDG_DATA_DIRS replaces the site_data_dir list (and turns site_applications_dir into <entry>/applications); XDG_CONFIG_DIRS replaces the site_config_dir list. site_state_dir and site_cache_dir ignore XDG variables.
Homebrew Detection
When sys.base_prefix points into a Homebrew Python framework, for example /opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.13 (or the equivalent Cellar/[email protected]/<version>/... keg path, or a free-threaded PythonT.framework), platformdirs takes the part before /opt/ or /Cellar/ as the Homebrew prefix. The prefix is not hard-coded, so /opt/homebrew, /usr/local and custom prefixes all work. Because sys.base_prefix is used, a virtual environment created from Homebrew Python keeps the Homebrew locations.
With Homebrew detected:
site_data_dir,site_config_dirandsite_state_dirreturn<prefix>/share/SuperApp, for example/opt/homebrew/share/SuperApp.site_cache_dirreturns<prefix>/var/cache/SuperApp.- With
multipath=True,site_data_dir,site_config_dirandsite_cache_dirreturn the Homebrew path followed by the/Librarypath, joined with:.site_state_diralways returns only the first entry.
The Shared /Library/Caches
macOS ships /Library/Caches world-writable with the sticky bit, like /tmp, so any user could create /Library/Caches/SuperApp first. With ensure_exists=True, platformdirs creates (or finds) that entry and then refuses to use it, raising PermissionError: site cache directory /Library/Caches/SuperApp is owned by uid 502, not root or 501 (or ... is a symlink, ... is not a directory) unless it is a real directory owned by root or the current user. Without ensure_exists no check is made.
The Runtime Directory
user_runtime_dir defaults to ~/Library/Caches/TemporaryItems/SuperApp. If XDG_RUNTIME_DIR is set to an absolute path, it is used only if it passes the same checks as on Linux: a real directory (not a symlink), owned by you, mode 0700, and parents (including symlink targets) owned by root or you and not writable by others without the sticky bit. Otherwise a RuntimeDirWarning is emitted once, for example:
RuntimeDirWarning: XDG_RUNTIME_DIR /Users/<user>/run has mode 0755, not 0700, falling back to the platform default
and the macOS default is used. Unlike Linux, an unset XDG_RUNTIME_DIR produces no warning on macOS.
site_runtime_dir always returns the same checked path as user_runtime_dir. place_runtime_file() creates the runtime directory before validating it, and find_runtime_file() skips an unusable override and also searches the native fallback.
Quirks to Know
XDG_DATA_HOMEmoves fonts and applications too: with it set,user_fonts_dirbecomes$XDG_DATA_HOME/fontsanduser_applications_dirbecomes$XDG_DATA_HOME/applications, which macOS itself does not look at.user_log_dirignoresopinionand every XDG variable; it is always under~/Library/Logs.multipath=Truewith anappnamecontaining:raisesValueErrorforsite_data_dir,site_config_dirandsite_cache_dir.