A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir". https://platformdirs.readthedocs.io
Find a file
tox-dev-platformdirs-release[bot] f05a38eef3
🔧 build(deps): refresh project lock (#760)
Relock `pylock.toml` with every dependency group upgraded to releases
past the seven-day cooldown.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-12-02 07:15:30 -08:00
.github Bump the "dependencies" group with 2 updates across multiple ecosystems (#758) 2026-12-01 07:51:01 -08:00
docs release 4.14.9 2026-11-27 20:53:04 +00:00
src/platformdirs 🐛 fix(android): recognize device-protected storage paths (#753) 2026-11-27 12:51:35 -08:00
tests 🐛 fix(android): recognize device-protected storage paths (#753) 2026-11-27 12:51:35 -08:00
.gitattributes 🔧 build(yaml): check out YAML with LF so yamlfmt passes on Windows (#620) 2026-10-15 16:53:25 -07:00
.gitignore 👷 ci(release): move releases to shared workflows (#637) 2026-10-26 22:39:33 -07:00
.pre-commit-config.yaml Bump the "dependencies" group with 2 updates across multiple ecosystems (#758) 2026-12-01 07:51:01 -08:00
.proselintrc.json 📚 docs: split usage guide into tutorial, how-to, and reference (#441) 2026-02-14 17:14:22 +00:00
.readthedocs.yml feat(python): require 3.11 and default to 3.15 (#613) 2026-10-10 01:21:46 -07:00
CONTRIBUTING.md 👷 ci(release): move releases to shared workflows (#637) 2026-10-26 22:39:33 -07:00
LICENSE Fix LICENSE 2022-07-06 00:18:07 -07:00
pylock.toml 🔧 build(deps): refresh project lock (#760) 2026-12-02 07:15:30 -08:00
pyproject.toml ⚡ perf: avoid importing typing at runtime (#714) 2026-11-17 09:57:43 -08:00
README.md 👷 ci(scorecard): publish OpenSSF results (#682) 2026-11-03 03:10:51 +00:00
tox.toml feat(python): require 3.11 and default to 3.15 (#613) 2026-10-10 01:21:46 -07:00

platformdirs

PyPI version Python versions CI Downloads OpenSSF Scorecard OpenSSF Best Practices

A Python package for determining platform-specific directories (e.g. user data, config, cache, logs). Handles the differences between macOS, Windows, Linux/Unix, Android, and iOS 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

Application directories — scoped to your app name and version:

  • Data: Persistent application data (user_data_dir, site_data_dir)
  • Config: Configuration files and settings (user_config_dir, site_config_dir)
  • Preference: User preferences, distinct from config on macOS (user_preference_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)

App dirs have both user_* (per-user, writable) and site_* (system-wide, read-only) variants where applicable.

User media directories — standard user-facing folders, not scoped to app name:

  • Documents (user_documents_dir), Downloads (user_downloads_dir)
  • Pictures (user_pictures_dir), Videos (user_videos_dir), Music (user_music_dir)
  • Desktop (user_desktop_dir), Projects (user_projects_dir)
  • Public share (user_publicshare_dir), Templates (user_templates_dir)
  • Fonts (user_fonts_dir) — user-writable font installation directory
  • Executable (user_bin_dir, site_bin_dir), Applications (user_applications_dir, site_applications_dir)

Documentation

Full documentation is available at platformdirs.readthedocs.io:

Contributions are welcome! See CONTRIBUTING.md for details.