The pathlib module, added in Python 3.4, offers classes representing filesystem paths with semantics appropriate to different operating systems. Path classes divide into pure paths, which provide purely computational operations without I/O, and concrete paths, which inherit from pure paths and add I/O. Path is most likely what you need: it instantiates a concrete path for the platform the code runs on. Use a pure class such as PureWindowsPath when manipulating Windows paths on a Unix machine (a WindowsPath cannot be instantiated there) or when code must manipulate paths without accessing the OS. Join segments with the / operator — Path('/etc') / 'init.d' / 'reboot' — list subdirectories with iterdir(), search a tree with glob('*/.py'), query with exists() and is_dir(), and open files with open(). The resolve() method makes the path absolute, resolving any symlinks. For low-level path manipulation on strings, use the os.path module. Scope: Python 3. Reviewed October 4, 2026.
Object-oriented filesystem paths with pathlib
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- docs.python.org
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.