I can get the home with os.path.expanduser("~")
but is there a standard way to get the config directory? Like ~/.config
in most unices, or the value of $XDG_CONFIG_HOME
in (recent?) Linux and C:\Users\<user>\AppData\Local\Roaming
in Windows), etc
Asked
Active
Viewed 8,156 times
25

user3557327
- 1,109
- 13
- 22
-
1Does this answer your question? [Cross-platform method to obtain the user's configuration home directory in Python?](https://stackoverflow.com/questions/26722607/cross-platform-method-to-obtain-the-users-configuration-home-directory-in-pytho) – Cyril Waechter Oct 01 '20 at 19:35
-
Does this answer your question? [Loading a config file from operation system independent place in python](https://stackoverflow.com/questions/3250164/loading-a-config-file-from-operation-system-independent-place-in-python) – zezollo Feb 15 '21 at 14:00
-
As of now, the best answer to this question is there: http://stackoverflow.com/a/63699709/3926735; though the next ones are good ones too. – zezollo Feb 15 '21 at 14:16
1 Answers
25
You can take advantage of python third party library appdirs platformdirs
which does all the heavy lifting for you across multiple platforms ( Windows, Linux & Mac )

Alex Peters
- 2,601
- 1
- 22
- 29

Phaneendra
- 421
- 4
- 7
-
The latest `appdirs` release as of the time of this comment is 7 Mar 2017. The link in the answer currently goes to an older 2014 release. I've submitted an edit so that the link always goes to the latest release. – Alex Peters May 29 '19 at 16:00
-
1P.S. The source code repository has [an active commit history](https://github.com/ActiveState/appdirs/commits/master) with commits from this year, so perhaps not abandoned as suggested in a comment above. – Alex Peters May 29 '19 at 16:02
-
1There seems to be a more active fork called platformdirs: https://github.com/platformdirs/platformdirs – Pascal Rosin Dec 27 '22 at 16:18
-
1