pathlib pathlib.Path is the modern, object-oriented way to handle file paths. It works on every OS and replaces most of os.path. Task pathlib Join paths Path("data") / "users.csv" Read / write text p.readtext(encoding="utf-8"), p.writetext(...) Parts p.name, p.stem, p.suffix, p.parent Exists / type p.exists(), p.isfile(), p.isdir() Create dirs p.mkdir(parents=True, existok=True) Find files p.glob(".py"), p.rglob("/.md") open() Use with open(path, mode, encoding="utf-8") as f: — modes: r, w (truncate), a (append), x (create only), plus b for binary. Iterate the file object to read large files line by line. Formats in the standard library json (dump/load), csv (DictReader/DictWriter), tomllib (read TOML, 3.11), sqlite3, pickle (never unpickle untrusted data).