Package: app-paths
Get and create paths for your appapp_pathsbuilds uponappdirsand automatically creates canonical file system paths for storing app and user data on Windows, macOS, Linux and *BSD.Instead of just strings,app_pathsgives developersPathobjects frompathliboraiopath, and it handles path creation efficiently. It also addsasync support.This project uses📁 aiopathas an asyncpathlibreplacement.Use caseFirst, let's take a look atappdirs:frompathlibimportPathfromappdirsimportAppDirsdirs=AppDirs('app','My Name','0.1.0')# appdirs will return uncreated paths as stringsuser_data:str=dirs.user_data_dirassertisinstance(user_data,str)print(user_data)# '/home/user/.cache/app/0.1.0'appdirscan generate paths as strings for an app. It does one thing, and it does that one thing well on multiple platforms.user_data_path=Path(user_data)# appdirs does not create pathsassertnotuser_data_path.exists()However, it's up to app developers to handle creating paths on users' file systems. It's also up to developers to decide how they want to manipulate those paths, using abstractions likeos.path,pathliboraiopath. Developers also have to think about how to efficiently perform path creation.app_pathstakes care of all of that for you.app_pathsautomatically gives youpathlib.Pathhandles for your paths in synchronous apps, andaiopath.AsyncPathhandles for async apps.fromapp_pathsimportAppPathspaths=AppPaths.get_paths('app','My Name','0.1.0')# app_paths can return pathsuser_data:Path=paths.user_data_pathassertisinstance(user_data,Path)print(user_data)# '/home/user/.cache/app/0.1.0'app_pathscan create paths on the file system dynamically, and it will cache results so excess I/O isn't performed.# app_paths can return uncreated pathsassertnotuser_data.exists()# but it can also dynamically create paths on the flyuser_data:Path=paths.user_dataassertuser_data.exists()It can do batch creation of app paths, and it will use efficient concurrent I/O in both synchronous and async Python programs.# create user app paths concurrentlyawaitpaths.create_user()# to run the following you must have write access to all paths# create site app paths concurrentlyawaitpaths.create_site()# create user and site paths concurrentlyawaitpaths.create_all()Here's how you can do the above asynchronously:fromapp_pathsimportAsyncAppPathsfromaiopathimportAsyncPathpaths=awaitAsyncAppPaths.get_paths('app','My Name','0.1.0')# app_paths can return AsyncPathsuser_data:AsyncPath=paths.user_data_pathassertisinstance(user_data,AsyncPath)print(user_data)# '/home/user/.cache/app/0.1.0'# app_paths can return uncreated pathsassertnotawaituser_data.exists()# but it can also dynamically create paths on the flyuser_data:AsyncPath=awaitpaths.user_dataassertawaituser_data.exists()# create user app paths concurrentlyawaitpaths.create_user()# to run the following you must have write access to all paths# create site app paths concurrentlyawaitpaths.create_site()# create user and site paths concurrentlyawaitpaths.create_all()InstallationRequirementsWindows, macOS or a POSIX compatible operating systemPython 3.8+PyPI$python3-mpipinstallapp_pathsSupportWant to support this project andother open-source projectslike it?LicenseSeeLICENSE. If you'd like to use this project with a different license, please get in touch.