AppDirs
AppDirs is a small Python module (version 1.4.4) designed to determine appropriate platform-specific directories for storing user data, configuration, cache, and log files across Linux, macOS, and Windows. This project has been officially deprecated, and `platformdirs` is recommended as a more actively maintained alternative.
Warnings
- deprecated This project has been officially deprecated. It is recommended to use `platformdirs` (https://pypi.org/project/platformdirs/) which is an actively maintained fork with similar functionality.
- gotcha AppDirs is 'slightly opinionated' on directory names. The exact paths generated can sometimes differ from strict system conventions or other tools' interpretations, potentially leading to unexpected locations. For instance, specific suffixes might be added to directory names.
- gotcha While version 1.4.4 is generally compatible with Python 3, earlier 1.x releases (e.g., 1.4.1) had specific issues with Python 3, particularly concerning Windows registry access (`winreg`) and string handling, which were addressed in subsequent minor releases. If working with older Python 3 environments or `appdirs` versions, verify generated paths carefully.
Install
-
pip install appdirs
Imports
- user_data_dir
from appdirs import user_data_dir
Quickstart
from appdirs import user_data_dir, user_cache_dir, user_log_dir
import os
appname = "MyApplication"
appauthor = "MyCompany"
appversion = "1.0.0"
# Get platform-specific directories
data_dir = user_data_dir(appname, appauthor, appversion=appversion)
cache_dir = user_cache_dir(appname, appauthor)
log_dir = user_log_dir(appname, appauthor)
print(f"Data directory: {data_dir}")
print(f"Cache directory: {cache_dir}")
print(f"Log directory: {log_dir}")
# Example: Ensure the data directory exists
os.makedirs(data_dir, exist_ok=True)
print(f"Ensured data directory exists: {os.path.exists(data_dir)}")