dirs is a small python library in the spirit of appdirs1 and other XDG
focused directory libraries. However, there are several that I've
identified with these other libraries:
- Overengineered solutions to get a few simple paths
- When Windows support is available, it reads from the registry, rather than
using the recommended approach of using
KnownFolderID. - No memoization of results. This can be costly when repeatedly working with filesystem paths
- None of these libraries return a
pathlib.Pathobject - None of these libraries use the
typingmodule for better static analysis tooling - None of these libraries use
dataclassesorattrsto prevent overwriting internals or "changing" state on the fly.
dirs tries to solve all of this by using ctypes under Windows for initial
calls, functools.lru_cache for an alternative API, lazy generation of
config_dirs and data_dirs on all platforms, and many others. Proper
documentation will be uploaded at some point, but the code is fairly readable
and easy to understand.
from dirs import User, Site # Using `*` is also permitted
app = User('app-name')
print(app.config) # prints a joined path with User.config_home() and 'app-name'
print(User.config_home()) # This returns the Path as-is
for path in Site.config_dirs(): # This is a generator, so it's iterable
print(f'{path} exists: {path.exists()}')