Package: faster-os
Faster OS - up to 6800% faster OS module replacement!Faster OS is a drop-in replacement for Python's standard 'OS' module. Faster OS offers32fully-rewritten, optimized, and speeded-up functions, that replace ones in theos.pathmodule.Thanks to Faster OS, you can process1,400,000 paths in just a minute, while it would takemore than an hour with an OS module.# Use Faster OS to save hours of processing time!# The only thing you need to do is write...importfaster_osasosSave your time - use Faster OS to process millions of paths inseconds.At ABTco, we use Faster OS in our own projects:MyQuickMac Neo- A revolutionary program for AI-powered care of your Mac -www.myquickmac.comMyQuickMac Lite- An innovative program for AI file management -www.myquickmac.com/lite4-Organizer- A powerful program to automatically unclutter your Windows PC, powered by AI -www.4organizer.comWiper AI- under development, available soonIt means that Faster OS is a stable, production-ready tool.In our case, just by changingimport ostoimport faster_os as os, Faster OS brought35-40% speed improvementsto our programs' inner processes.Benchmarks and speedOn average, a Faster OS function is1504% fasterthan an original function from the OS module.The most-used functions (split,join,splitext) are on average1215% faster:NameTimes FasterFaster OS: process 1,000,000 pathsOS: process 1,000,000 pathsjoin1530%14 seconds3 minutes 20 secondssplitext1059%8 seconds1 minute 33 secondssplit1190%18 seconds4 minutes 43 secondsFull benchmark results:FunctionPaths amountTimes FasterFaster OS timeOS timesplit55001105%0.81090.0733splitdrive5500445%0.38490.0864normcase5500313%0.16080.0513splitext5500938%0.50170.0535join50001442%1.43880.0997relpath55003653%12.14180.3323ismount55003620%71.59311.9776normpath6500326%1.96210.6026expanduser5500493%0.15390.0312abspath5500180%3.50751.9471isabs5500760%0.69110.0909basename55001217%0.84030.0690dirname55001236%0.84730.0685commonpath5000738%4.42960.5998commonprefix5000356%0.94800.2661Multi-functions benchmark results:FunctionChunks amount (each 50-100 paths)Times FasterFaster OS timeOS timemulti_commonpath1000761%0.11670.8886multi_commonprefix1000435%0.04910.2137multi_abspath4500195%1.31052.5564multi_ismount45006853%1.287888.2588multi_expanduser4500448%0.06800.3050multi_relpath11003772%0.06462.4374multi_split45001475%0.04420.6528multi_splitdrive4500628%0.04760.2989multi_normcase4500451%0.02980.1348multi_normpath1300362%0.11940.4324multi_basename45001599%0.04230.6770multi_dirname45001644%0.04180.6888multi_isabs45001023%0.05390.5514multi_splitext45001282%0.03180.4077multi_join10001418%0.02040.2902We recommend usingmulti-functionswhen the given iterable has more than 250 elements. For smaller lists, usingmulti-functionsis ineffective.Introduction / How to use# Faster OS - a drop-in replacement for the 'OS' module# Up to 6800% faster!importfaster_os# All 'OS' functions you need, and even more!# 32 rewritten functions, optimized for speed and performance.faster_os.path.join('/','some','path')>>>'/some/path'faster_os.path.split('/some/test/path')>>>('/some/test','path')faster_os.path.join('C:\\','Windows\\System32','LogFiles')>>>'C:\\Windows\\System32\\LogFiles'faster_os.path.split('C:\\Users\\User\\Desktop')>>>('C:\\Users\\User','Desktop')# Works both for UNIX and for Windows!# Everything works exactly the same as in 'OS':# -- splitext --faster_os.path.splitext('hello world\\123.ext')>>>('hello world\\123','.ext')faster_os.path.splitext('C:\\sample_photo.jpg')>>>('C:\\sample_photo','.jpg')# -- splitdrive --faster_os.path.splitdrive('C:\\HELLO WORLD\\SOME PATH')>>>('C:','\\HELLO WORLD\\SOME PATH')faster_os.path.splitdrive('\\\\machine\\mountpoint\\directory\\etc\\')>>>('\\\\machine\\mountpoint','\\directory\\etc\\')# -- normpath --faster_os.path.normpath('C:\\\\hello\\\\\\world\\\\\\')>>>'C:\\hello\\world'faster_os.path.normpath('An invalid\\\\\\path\\\\with many slashes\\\\\\\\\\\\')>>>'An invalid\\path\\with many slashes'# -- abspath --faster_os.path.abspath('Desktop')>>>'D:\\Libraries\\Desktop\\Pys\\Big\\FasterOS\\Desktop'faster_os.path.abspath('Appdata\\Local')>>>'D:\\Libraries\\Desktop\\Pys\\Big\\FasterOS\\Appdata\\Local'# -- expanduser --faster_os.path.expanduser('~\\Downloads\\file.exe')>>>'C:\\Users\\Dsibe\\Downloads\\file.exe'faster_os.path.expanduser('~\\Appdata')>>>'C:\\Users\\Dsibe\\Appdata'# -- normcase --faster_os.path.normcase('C:/HELLO WORLD/SOME/PATH/')>>>'c:\\hello world\\some\\path\\'faster_os.path.normcase('C:/faster-os/a-unix-path/to-windows/path')>>>'c:\\faster-os\\a-unix-path\\to-windows\\path'# -- isabs --faster_os.path.isabs('C:\\Users\\User')>>>Truefaster_os.path.isabs('~\\user')>>>Falsefaster_os.path.isabs('%USERPROFILE%\\hi')>>>False# -- basename --faster_os.path.basename('C:\\HELLO WORLD\\SOME PATH')>>>'SOME PATH'faster_os.path.basename('C:\\faster-os')>>>'faster-os'# -- dirname --faster_os.path.dirname('C:\\HELLO WORLD\\SOME PATH')>>>'C:\\HELLO WORLD'faster_os.path.dirname('C:\\faster-os')>>>'C:\\'# -- commonpath --faster_os.path.commonpath(['C:\\\\Common','C:\\\\Common\\\\','C:\\\\Common\\\\123','C:\\\\Common\\\\Common','C:\\\\Common\\\\abtco\\\\faster_os'])>>>'C:\\Common'# -- commonprefix--faster_os.path.commonprefix(['C:\\\\','C:\\\\1\\\\123/123/123\\\\123','C:\\\\hello world\\\\some path','C:\\\\hello world\\\\some path\\\\'])>>>'C:\\'# And 21 more functions...# Also, Faster OS also offers special 'multi-functions'.# Use them to process extra large lists, containing hundreds of thousands of elements!multi_abspath,multi_basename,multi_commonpath,multi_commonprefix,multi_dirname,multi_expanduser,multi_isabs,multi_ismount,multi_join,multi_normcase,multi_normpath,multi_relpath,multi_split,multi_splitdrive,multi_splitext# For example:faster_os.multi_join([('path/to/join','some path'),('path/to/join','other path'),('path/to/join','other path 2'),('path/to/join','other path 3'),...])# We recommend using multi-functions over lists with more than 250 elements.# Even further, Faster OS re-implements removedirs and adds remove_multiple_dirsfaster_os.removedirs('C:\\This\\Path\\Will\\Be\\Deleted')InstallationVia PyPi:pip install faster_os --upgradeOr, build from the source:Clone the repository:git clone https://github.com/American-Best-Technologies-Company/faster-os.gitRunpython3 setup.py build_extDone! Verify installation:import faster_osDifferences from the OS moduleExceptions and invalid pathsIf the given arguments are valid then Faster OS works absolutely the same way as the OS module. It means that if you use Faster OS on any valid path,it will work exactly like the OS module.If you will pass some invalid path as an argument to Faster OS' functions, then most of the exceptions raised by itwill not matchthe ones raised by the OS module.For example, in this case, the exceptions raised by OS and Faster OSare the same:importosos.path.join('some path',None)>>>TypeError:join()argumentmustbestr,bytes,oros.PathLikeobject,not'NoneType'importfaster_osfaster_os.path.join('some path',None)>>>TypeError:sequenceitem0:expectedstrinstance,NoneTypefoundBut sometimes, exceptions raisedcan be different:importosos.path.normcase(None)>>>TypeError:expectedstr,bytesoros.PathLikeobject,notNoneTypeimportfaster_osfaster_os.path.normcase(None)>>>AttributeError:'NoneType'objecthasnoattribute'replace'The main reason for this is the main goal of Faster OS: speed.Adding type and paths validity checks will significantly slow down Faster OS. Right now,we do not plan to add any type checks or some validationto the Faster OS functions. Because of this, the exceptions might be not that human-readable or easy to understand.Bytes supportCurrently, Faster OS supports onlystr.bytessupport will be added in the next updates. Maybe, evenos.PathLikeobject will be supported in the next releases.Platforms✅ Windows✅ Linux/UNIX✅ macOS✅ Android, Raspberry Pi, BSD, *NIXRequisitesPython 3C build tools:For Windows: Have Visual Studio installedFor UNIX: GCC (probably already installed)For macOS: Have XCode CMD tools installed (typegccin the Terminal to check if it's installed)LicenseFaster OS is licensed under Mozilla Public License 2.0. It means that you can use it in commercial/proprietary projects, with closed source code. Youdon't need to disclose the source code.DocumentationWe recommend reading theofficial OS module documentation, as all Faster OS functions' behavior is 'mirrored' from the OS functions. Below, you can find short documentation on all Faster OS functions.normpathfaster_os.path.normpath(path: str) -> strNormalizes the path: replaces '/' to '' on Windows (or the opposite on UNIX), and does other changes related to '.' and '..'.normcasefaster_os.path.normcase(path: str) -> strLowers the path (str.lower) and replaces '/' to '' on Windows (or the opposite on UNIX).splitfaster_os.path.split(path: str) -> tupleReturns a tuple with the path splitted into directory name and base name:Example: 'some/example/path' -> ('some/example', 'path')splitdrivefaster_os.path.splitdrive(path: str) -> tupleOnly makes sense on Windows: splits the path into the drive and the path.Example:'C:\\Windows' -> ('C:', '\\Windows')isabsfaster_os.path.isabs(path: str) -> cython.bintChecks if a path is absolute.Example:'C:\\some absolute\\path' -> True'some\\relative\\path\\' -> Falsejoinfaster_os.path.join(path: str, *paths) -> strJoins all the given paths using platform delimiter ('/' or '').Example:faster_os.path.('C:\\', 'some', 'path') -> 'C:\\some\\path'splitextfaster_os.path.splitext(path: str) -> tupleSplits the path into the path and extension.Example:'a photo.jpg' -> ('a photo', '.jpg')basenamefaster_os.path.basename(path: str) -> strReturns the base name of a path.'C:\\some absolute\\path' -> 'path'dirnamefaster_os.path.dirname(path: str) -> strReturns the directory name of a path.'C:\\some absolute\\path' -> 'C:\\some absolute\\'ismountfaster_os.path.ismount(path: str) -> cython.bintChecks if a path is a mounting point.expanduserfaster_os.path.expanduser(path: str) -> strExpands the '~' into the user profile or home path.Example:'~Desktop'->'C:\\Users\\Desktop'~\\Desktop'->'C:\\Users\\User\\Desktop^^noticethisslashrelpathfaster_os.path.relpath(tail: str, root=None) -> strComputes the relative path of thetaildepending on theroot.Ifrootis None, then it's assigned to the current working directoryos.getcwd().commonprefixfaster_os.path.commonprefix(paths) -> strFinds the common prefix of given paths.Example:['faster_os/abc', 'faster_os/abcde', 'faster_os/abc123'] -> 'faster_os/abc'commonpathfaster_os.path.commonpath(paths) -> strFinds the common path of given paths.Contraty to commonprefix, finds the full path.Example:['faster_os/abc', 'faster_os/abcde', 'faster_os/abc123'] -> 'faster_os'abspathfaster_os.path.abspath(path: str) -> strTries to get the absolute path using the operating system's API, or falls back to joining the path with CWD.multi_splitfaster_os.path.multi_split(paths) -> listTakes any iterable (list, tuple, etc) and applies split to each element.Returns a list.multi_normpathfaster_os.path.multi_normpath(paths) -> listTakes any iterable (list, tuple, etc) and applies normpath to each element.Returns a list.multi_normcasefaster_os.path.multi_normcase(paths) -> listTakes any iterable (list, tuple, etc) and applies normcase to each element.Returns a list.multi_splitdrivefaster_os.path.multi_splitdrive(paths) -> listTakes any iterable (list, tuple, etc) and applies splitdrive to each element.Returns a list.multi_isabsfaster_os.path.multi_isabs(paths) -> listTakes any iterable (list, tuple, etc) and applies isabs to each element.Returns a list.multi_joinfaster_os.path.multi_join(paths) -> listTakes any iterable (list, tuple, etc) and applies join to each element.Returns a list.multi_splitextfaster_os.path.multi_splitext(paths) -> listTakes any iterable (list, tuple, etc) and applies splitext to each element.Returns a list.multi_basenamefaster_os.path.multi_basename(paths) -> listTakes any iterable (list, tuple, etc) and applies basename to each element.Returns a list.multi_dirnamefaster_os.path.multi_dirname(paths) -> listTakes any iterable (list, tuple, etc) and applies dirname to each element.Returns a list.multi_relpathfaster_os.path.multi_relpath(paths) -> listTakes any iterable (list, tuple, etc) and applies relpath to each element.Returns a list.multi_expanduserfaster_os.path.multi_expanduser(paths) -> listTakes any iterable (list, tuple, etc) and applies expanduser to each element.Returns a list.multi_ismountfaster_os.path.multi_ismount(paths) -> listTakes any iterable (list, tuple, etc) and applies ismount to each element.Returns a list.multi_abspathfaster_os.path.multi_abspath(paths) -> listTakes any iterable (list, tuple, etc) and applies abspath to each element.Returns a list.multi_commonprefixfaster_os.path.multi_commonprefix(paths) -> listTakes any iterable (list, tuple, etc) and applies commonprefix to each element.Returns a list.multi_commonpathfaster_os.path.multi_commonpath(paths) -> listTakes any iterable (list, tuple, etc) and applies commonpath to each element.Returns a list.removedirsfaster_os.removedirs(path) -> NoneDeletes all the path components until the exception is raised.removedirswill try to delete each directory until the error is raised, for example, a directory is not empty or there's a permission error:
For example:Givenpath"C:\Users\User\Desktop\many\folders\here"Delete"C:\Users\User\Desktop\many\folders\here"Delete"C:\Users\User\Desktop\many\folders"Delete"C:\Users\User\Desktop\many"Delete"C:\Users\User\Desktop\"-> ERROR - returnremove_multiple_dirsfaster_os.remove_multiple_dirs(paths) -> NoneTakes any iterable (list, tuple, etc) and appliesremovedirsto each element.