pathlib
Stdlib — OS/FilePython 3.4+Beginner
Object-oriented filesystem paths (modern replacement for os.path)
Quick Info
- Documentation
- Official Docs
- Python Version
- 3.4+
- Dependencies
- None — Python Standard Library
- Install
Included with Python
Learn by Difficulty
Quick Example
python
from pathlib import PurePosixPath as Path # Path operations (using PurePosixPath for Pyodide compatibility) p = Path("/home/user/documents/file.txt") print(f"Name: {p.name}") print(f"Stem: {p.stem}") print(f"Suffix: {p.suffix}") print(f"Parent: {p.parent}") print(f"Parts: {p.parts}")
The pathlib module is part of Python's standard library. Object-oriented filesystem paths (modern replacement for os.path).
Try in PlaygroundTags
stdlibfile-iopathmodern
Related Items
os.path
Stdlib — OS/File
Pathname manipulations: join, split, exists, isfile, isdir, abspath
glob
Stdlib — OS/File
Unix-style pathname pattern expansion (wildcards like *.txt)
shutil
Stdlib — OS/File
High-level file operations: copy, move, remove trees, archives
open()
Built-in Function
Opens a file and returns a file object for reading or writing
os
Stdlib — OS/File
Interface to the OS: env vars, process management, file operations