Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ Defaults to ``False``.
dirs = PlatformDirs("SuperApp", "Acme", ensure_exists=True)
dirs.user_cache_dir # directory is created if it does not exist

``use_site_for_root``
~~~~~~~~~~~~~~~~~~~~~

Unix-only. When ``True``, redirects ``user_*_dir`` calls to their ``site_*_dir`` equivalents when
running as root (uid 0). Defaults to ``False`` for backwards compatibility.

When enabled, XDG user environment variables (e.g., ``XDG_DATA_HOME``) are bypassed for the
redirected directories. This is useful for system services running as root that should use
system-wide directories rather than root's home directory.

.. code-block:: python

from platformdirs import PlatformDirs

dirs = PlatformDirs("SuperApp", use_site_for_root=True)
# When running as root, user_data_dir returns the site_data_dir path
dirs.user_data_dir # Returns site directory instead of /root/.local/share/SuperApp

Directories not covered
-----------------------

Expand Down