Windows

On Windows (sys.platform == "win32"), PlatformDirs is platformdirs.windows.Windows. It asks Windows for its Known Folders (AppData\Local, AppData\Roaming, ProgramData, Documents, ...) and builds app directories as <folder>\<appauthor>\<appname>\<version>. This page lists every directory, explains how folders are resolved, the Cache/Logs subfolders, overrides, and Microsoft Store Python.

Examples use appname="SuperApp", appauthor="Acme", and user <User>. multipath and use_site_for_root have no effect on Windows.

User Directories

Property Default (roaming=False) With roaming=True
user_data_dir C:\Users\<User>\AppData\Local\Acme\SuperApp C:\Users\<User>\AppData\Roaming\Acme\SuperApp
user_config_dir same as user_data_dir same as user_data_dir
user_state_dir same as user_data_dir same as user_data_dir
user_preference_dir same as user_data_dir same as user_data_dir
user_log_dir ...\AppData\Local\Acme\SuperApp\Logs ...\AppData\Roaming\Acme\SuperApp\Logs
user_cache_dir ...\AppData\Local\Acme\SuperApp\Cache unchanged (always Local)
user_runtime_dir ...\AppData\Local\Temp\Acme\SuperApp unchanged
user_documents_dir C:\Users\<User>\Documents
user_downloads_dir C:\Users\<User>\Downloads
user_pictures_dir C:\Users\<User>\Pictures
user_videos_dir C:\Users\<User>\Videos
user_music_dir C:\Users\<User>\Music
user_desktop_dir C:\Users\<User>\Desktop
user_projects_dir C:\Users\<User>\Projects
user_publicshare_dir C:\Users\Public (machine-wide, shared by all accounts)
user_templates_dir C:\Users\<User>\AppData\Roaming\Microsoft\Windows\Templates
user_fonts_dir C:\Users\<User>\AppData\Local\Microsoft\Windows\Fonts
user_bin_dir C:\Users\<User>\AppData\Local\Programs
user_applications_dir C:\Users\<User>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs

Media folders come from the Known Folder API, so a Documents folder that the user moved to another drive (or that OneDrive redirects) is reported at its real location.

Site Directories

Property Default
site_data_dir C:\ProgramData\Acme\SuperApp
site_config_dir same as site_data_dir
site_state_dir same as site_data_dir
site_cache_dir C:\ProgramData\Acme\SuperApp\Cache
site_log_dir C:\ProgramData\Acme\SuperApp\Logs
site_runtime_dir same as user_runtime_dir
site_bin_dir C:\ProgramData\bin
site_applications_dir C:\ProgramData\Microsoft\Windows\Start Menu\Programs

site_bin_dir mirrors the site_data_dir pattern under %ProgramData%, following the precedent of Chocolatey.

Note: Every user can create folders in C:\ProgramData. platformdirs does not check who created an existing site directory there, so do not trust its content for security decisions.

The Author Folder

Windows groups applications by publisher. appauthor controls that level:

Call Result
user_data_dir("SuperApp", "Acme") ...\AppData\Local\Acme\SuperApp
user_data_dir("SuperApp") (author None) ...\AppData\Local\SuperApp\SuperApp
user_data_dir("SuperApp", False) ...\AppData\Local\SuperApp
user_data_dir() (no app name) ...\AppData\Local

The doubled folder in the second row surprises many users; pass appauthor=False when you do not want a publisher level.

The Opinion Subfolders

With the default opinion=True, two kinds of directories get an extra folder so they do not coincide with the data directory. The position of that folder relative to version differs:

Property version="1.0", opinion=True opinion=False
user_cache_dir ...\Acme\SuperApp\Cache\1.0 ...\Acme\SuperApp\1.0
user_log_dir ...\Acme\SuperApp\1.0\Logs ...\Acme\SuperApp\1.0
site_cache_dir C:\ProgramData\Acme\SuperApp\Cache\1.0 C:\ProgramData\Acme\SuperApp\1.0
site_log_dir C:\ProgramData\Acme\SuperApp\1.0\Logs C:\ProgramData\Acme\SuperApp\1.0

The cache subfolder is inserted inside the app name (and only when appname is set), whereas the log subfolder is appended to the finished data directory (even without an app name). This was verified with python -m platformdirs on Windows:

user_cache_dir: C:\Users\<User>\AppData\Local\MyCompany\MyApp\Cache\1.0
user_log_dir: C:\Users\<User>\AppData\Local\MyCompany\MyApp\1.0\Logs

How Folders Are Resolved

For each Known Folder (named internally by its legacy CSIDL_* name), platformdirs tries, in order:

  1. The WIN_PD_OVERRIDE_<NAME> environment variable, if it holds a fully qualified path. See Environment Variables.
  2. The Shell API SHGetKnownFolderPath, called through ctypes with the KF_FLAG_DONT_VERIFY flag (so the folder does not have to exist). This is the normal path.
  3. If ctypes is not importable: the Shell Folders registry key (HKEY_CURRENT_USER, or HKEY_LOCAL_MACHINE for ProgramData and the All Users Start Menu).
  4. If winreg is not importable either: environment variables (APPDATA, LOCALAPPDATA, ALLUSERSPROFILE, USERPROFILE, PUBLIC, PROGRAMDATA).

The resolver is chosen once at import time. The ctypes resolver is built once and reused, which avoids a memory leak of ctypes types on repeated calls.

Internal name Known folder Used by
CSIDL_LOCAL_APPDATA AppData\Local data (non-roaming), cache, runtime (\Temp), fonts (\Microsoft\Windows\Fonts)
CSIDL_APPDATA AppData\Roaming data with roaming=True
CSIDL_COMMON_APPDATA ProgramData all site_* app directories, site_bin_dir (\bin)
CSIDL_PERSONAL Documents user_documents_dir
CSIDL_DOWNLOADS Downloads user_downloads_dir
CSIDL_MYPICTURES Pictures user_pictures_dir
CSIDL_MYVIDEO Videos user_videos_dir
CSIDL_MYMUSIC Music user_music_dir
CSIDL_DESKTOPDIRECTORY Desktop user_desktop_dir
CSIDL_PROGRAMS Start Menu Programs user_applications_dir
CSIDL_COMMON_PROGRAMS All Users Start Menu Programs site_applications_dir
CSIDL_TEMPLATES Templates user_templates_dir
CSIDL_PUBLIC C:\Users\Public user_publicshare_dir
CSIDL_USER_PROGRAM_FILES AppData\Local\Programs user_bin_dir

user_projects_dir is the only directory not resolved through a Known Folder: Windows has none for projects, so platformdirs returns <home>\Projects, where <home> comes from USERPROFILE, else HOMEDRIVE + HOMEPATH. If neither is set, it raises RuntimeError: could not determine the home directory for '~/Projects' ....

Overriding Locations

Because changing LOCALAPPDATA would affect every program, platformdirs reads its own override variables. For example, to keep large caches on drive D::

$env:WIN_PD_OVERRIDE_LOCAL_APPDATA = "D:\appdata"
python -c "from platformdirs import user_cache_dir; print(user_cache_dir('MyApp', 'Acme'))"
D:\appdata\Acme\MyApp\Cache

Overriding LOCAL_APPDATA also moves the data, config, state, log, runtime and fonts directories. The full list of variables is in Environment Variables.

Microsoft Store Python (MSIX)

Python installed from the Microsoft Store runs as an MSIX package. Windows redirects new files and folders that it creates under AppData to a per-package location such as AppData\Local\Packages\PythonSoftwareFoundation.Python.3.X_<hash>\LocalCache\Local\.... Files written into a folder that already exists at the real location stay there.

platformdirs returns the logical AppData path. That is correct for code running inside the same package, but other programs will not see redirected files at that path. To get the real on-disk location (for example to pass it to an external tool), create the directory first and then resolve it:

import os

import platformdirs

data_dir = platformdirs.user_data_dir("MyApp", "Acme", ensure_exists=True)
real_dir = os.path.realpath(data_dir)

This is how Windows file system virtualization works, not a platformdirs bug.

Creating Directories

With ensure_exists=True, directories are created with os.mkdir-style calls including missing parents. Windows has no equivalent of the POSIX ownership checks that platformdirs performs on Unix, so none are done. A missing drive or network share raises the underlying OSError.

See Also