A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir". https://platformdirs.readthedocs.io
Find a file
2026-03-05 19:05:08 +00:00
.github 🐛 fix(release): generate docstrfmt-compatible changelog entries (#463) 2026-03-05 19:05:08 +00:00
docs 🐛 fix(release): generate docstrfmt-compatible changelog entries (#463) 2026-03-05 19:05:08 +00:00
src/platformdirs Add missing _optionally_create_directory in Android user_log_dir and user_runtime_dir (#452) 2026-02-23 13:43:49 +00:00
tasks 🐛 fix(release): generate docstrfmt-compatible changelog entries (#463) 2026-03-05 19:05:08 +00:00
tests Add missing _optionally_create_directory in Android user_log_dir and user_runtime_dir (#452) 2026-02-23 13:43:49 +00:00
.gitignore Use hatch over tox (#262) 2024-02-02 17:00:13 -08:00
.pre-commit-config.yaml [pre-commit.ci] pre-commit autoupdate (#461) 2026-03-02 17:42:52 +00:00
.proselintrc.json 📚 docs: split usage guide into tutorial, how-to, and reference (#441) 2026-02-14 17:14:22 +00:00
.readthedocs.yml 🔧 build: migrate from hatch to tox with ty (#415) 2026-02-11 21:04:02 -08:00
CONTRIBUTING.md 📝 docs: enhance README, fix issues, and reorganize platforms.rst (#445) 2026-02-14 21:00:36 +00:00
LICENSE Fix LICENSE 2022-07-06 00:18:07 -07:00
pyproject.toml 📝 docs: add project logo to documentation (#459) 2026-03-01 08:33:30 -08:00
README.md Update README.md 2026-03-02 06:21:20 -08:00
tox.toml 📝 docs: add project logo to documentation (#459) 2026-03-01 08:33:30 -08:00

platformdirs

PyPI version Python versions CI Downloads

A Python package for determining platform-specific directories (e.g. user data, config, cache, logs). Handles the differences between macOS, Windows, Linux/Unix, and Android so you don't have to.

Quick start

from platformdirs import PlatformDirs

dirs = PlatformDirs("MyApp", "MyCompany")
dirs.user_data_dir  # ~/.local/share/MyApp (Linux)
dirs.user_config_dir  # ~/.config/MyApp (Linux)
dirs.user_cache_dir  # ~/.cache/MyApp (Linux)
dirs.user_state_dir  # ~/.local/state/MyApp (Linux)
dirs.user_log_dir  # ~/.local/state/MyApp/log (Linux)
dirs.user_documents_dir  # ~/Documents
dirs.user_downloads_dir  # ~/Downloads
dirs.user_runtime_dir  # /run/user/<uid>/MyApp (Linux)

For Path objects instead of strings:

from platformdirs import PlatformDirs

dirs = PlatformDirs("MyApp", "MyCompany")
dirs.user_data_path  # pathlib.Path('~/.local/share/MyApp')
dirs.user_config_path  # pathlib.Path('~/.config/MyApp')

Convenience functions for quick access:

from platformdirs import user_data_dir, user_config_path

user_data_dir("MyApp", "MyCompany")  # returns str
user_config_path("MyApp", "MyCompany")  # returns pathlib.Path

Directory types

  • Data: Persistent application data (user_data_dir, site_data_dir)
  • Config: Configuration files and settings (user_config_dir, site_config_dir)
  • Cache: Cached data that can be regenerated (user_cache_dir, site_cache_dir)
  • State: Non-essential runtime state like window positions (user_state_dir, site_state_dir)
  • Logs: Log files (user_log_dir, site_log_dir)
  • Runtime: Runtime files like sockets and PIDs (user_runtime_dir, site_runtime_dir)

Each type has both user_* (per-user, writable) and site_* (system-wide, read-only for users) variants.

Documentation

Full documentation is available at platformdirs.readthedocs.io:

Contributions are welcome! See CONTRIBUTING.md for details.