Module Functions

The platformdirs package exposes 54 convenience functions: one *_dir function returning a str and one *_path function returning a pathlib.Path for each of the 27 directories. Each function builds a fresh PlatformDirs object from its arguments and reads one property, so user_data_dir("SuperApp", "Acme") is exactly PlatformDirs(appname="SuperApp", appauthor="Acme").user_data_dir.

This page lists every function with its exact signature. For what each parameter does, see Parameters; for where each directory lands, see the Path Reference Table.

When to Use Functions vs the Class

Use a function for a one-off lookup:

from platformdirs import user_cache_path

cache = user_cache_path("SuperApp", "Acme")

Use the class when you need several directories with the same settings, when you need a parameter that the function does not accept (for example multipath for user_data_dir), or when you need the iterators, place_*_file or find_*_file methods, which have no function equivalent.

from platformdirs import PlatformDirs

dirs = PlatformDirs("SuperApp", "Acme", version="2.0")
config = dirs.user_config_path
cache = dirs.user_cache_path

str and Path Variants

Every function exists twice with identical parameters:

Suffix Returns Example
_dir str user_config_dir("SuperApp")
_path pathlib.Path user_config_path("SuperApp")

One difference: for site_data, site_config, site_cache and site_applications, the _dir function with multipath=True returns all entries joined with os.pathsep, while the _path function always returns only the first entry as a Path.

Signatures

Most positional parameters keep the order inherited from appdirs; parameters added later are keyword-only (after *). In the table, A stands for appname=None, appauthor=None, version=None.

App Data Directories

Function (_dir / _path) Signature
user_data_dir / user_data_path (A, roaming=False, ensure_exists=False, use_site_for_root=False)
site_data_dir / site_data_path (A, multipath=False, ensure_exists=False)
user_config_dir / user_config_path (A, roaming=False, ensure_exists=False, use_site_for_root=False)
site_config_dir / site_config_path (A, multipath=False, ensure_exists=False)
user_cache_dir / user_cache_path (A, opinion=True, ensure_exists=False, use_site_for_root=False)
site_cache_dir / site_cache_path (A, opinion=True, ensure_exists=False, *, multipath=False)
user_state_dir / user_state_path (A, roaming=False, ensure_exists=False, use_site_for_root=False)
site_state_dir / site_state_path (A, ensure_exists=False)
user_log_dir / user_log_path (A, opinion=True, ensure_exists=False, use_site_for_root=False, *, roaming=False)
site_log_dir / site_log_path (A, opinion=True, ensure_exists=False)
user_runtime_dir / user_runtime_path (A, opinion=True, ensure_exists=False, use_site_for_root=False)
site_runtime_dir / site_runtime_path (A, opinion=True, ensure_exists=False)
user_preference_dir / user_preference_path (A, *, roaming=False, ensure_exists=False, use_site_for_root=False)

Media Directories

These take no app name: they return the user's shared folders.

Function (_dir / _path) Signature
user_documents_dir / user_documents_path (*, ensure_exists=False, use_site_for_root=False)
user_downloads_dir / user_downloads_path (*, ensure_exists=False, use_site_for_root=False)
user_pictures_dir / user_pictures_path (*, ensure_exists=False, use_site_for_root=False)
user_videos_dir / user_videos_path (*, ensure_exists=False, use_site_for_root=False)
user_music_dir / user_music_path (*, ensure_exists=False, use_site_for_root=False)
user_desktop_dir / user_desktop_path (*, ensure_exists=False, use_site_for_root=False)
user_projects_dir / user_projects_path (*, ensure_exists=False, use_site_for_root=False)
user_publicshare_dir / user_publicshare_path (*, ensure_exists=False, use_site_for_root=False)
user_templates_dir / user_templates_path (*, ensure_exists=False, use_site_for_root=False)
user_fonts_dir / user_fonts_path (*, use_site_for_root=False)

ensure_exists on a media function only creates a folder that the user configured through an XDG_*_DIR variable or user-dirs.dirs on Linux and macOS; default media folders such as ~/Documents are never created.

Executables and Applications

Function (_dir / _path) Signature
user_bin_dir / user_bin_path (*, use_site_for_root=False)
site_bin_dir / site_bin_path ()
user_applications_dir / user_applications_path (A, *, ensure_exists=False, use_site_for_root=False)
site_applications_dir / site_applications_path (multipath=False, ensure_exists=False, *, appname=None, appauthor=None, version=None)

Note the unusual order of site_applications_dir: multipath is its first positional parameter, so site_applications_dir("SuperApp") sets multipath="SuperApp" (a truthy value), not the app name. Pass names by keyword. The app name only matters on Android, where the applications directory is the app's data directory.

Parameters Not Accepted by Functions

The functions expose only the parameters relevant to each directory. Everything else uses the class default:

Parameter Default used Accepted by
roaming False user data, config, state, log, preference
multipath False site data, config, cache, applications
opinion True user/site cache, log, runtime
ensure_exists False all except fonts and bin
use_site_for_root False all user_* functions

For any other combination, create a PlatformDirs object.

Examples

import platformdirs

# Windows-style author folder, separate per version
platformdirs.user_data_dir("SuperApp", "Acme", version="1.4")

# A Path, created if missing
log_dir = platformdirs.user_log_path("SuperApp", ensure_exists=True)

# All site config directories on Linux, as one os.pathsep-joined string
platformdirs.site_config_dir("SuperApp", multipath=True)

# Disable the Windows "Cache" subfolder
platformdirs.user_cache_dir("SuperApp", "Acme", opinion=False)

# The user's Downloads folder
platformdirs.user_downloads_path()

Other Module Members

Name What it is
PlatformDirs The class for the current platform: Unix, MacOS, Windows, Android or IOS. See The PlatformDirs Class.
AppDirs Alias of PlatformDirs, kept for appdirs compatibility.
PlatformDirsABC The abstract base class all platform classes inherit from (defined in platformdirs.api).
RuntimeDirWarning UserWarning subclass emitted when XDG_RUNTIME_DIR cannot be used. See Linux and Unix.
__version__ The version string, for example "4.14.9".
__version_info__ The version as a tuple.

The platformdirs.testing module and the platformdirs_isolated pytest fixture are documented in Testing Helpers.

See Also