{"id":2183,"library":"pathlib2","title":"pathlib2 Library","description":"pathlib2 is a backport of the standard library module `pathlib` to Python versions 2.6, 2.7, 3.2, and 3.3. It provides an object-oriented filesystem path abstraction. For Python 3.4 and up, `pathlib` is part of the standard library, making `pathlib2` generally unnecessary for modern projects. The current version is 2.3.7.post1, and it's in community maintenance.","status":"maintenance","version":"2.3.7.post1","language":"en","source_language":"en","source_url":"https://github.com/jazzband/pathlib2","tags":["filesystem","path","backport","python2","object-oriented"],"install":[{"cmd":"pip install pathlib2","lang":"bash","label":"Install `pathlib2`"}],"dependencies":[],"imports":[{"note":"When using `pathlib2`, ensure you import `Path` from `pathlib2`, not the standard library's `pathlib`.","wrong":"from pathlib import Path","symbol":"Path","correct":"from pathlib2 import Path"}],"quickstart":{"code":"from pathlib2 import Path\n\n# Create a Path object\np = Path('/tmp/my_file.txt')\n\n# Check if it exists\nprint(f\"Does {p} exist? {p.exists()}\")\n\n# Get parent directory\nprint(f\"Parent directory: {p.parent}\")\n\n# Get file name\nprint(f\"File name: {p.name}\")\n\n# Create a new path by joining\nnew_dir = Path('/tmp/my_data')\nnew_dir.mkdir(exist_ok=True)\nnew_file = new_dir / 'output.log'\nnew_file.touch()\n\nprint(f\"New file created: {new_file.exists()}\")\nprint(f\"Contents of new_file: {new_file.read_text()}\")\n\n# Clean up\nnew_file.unlink()\nnew_dir.rmdir()\n","lang":"python","description":"This quickstart demonstrates basic usage of `pathlib2.Path` to represent filesystem paths, check existence, manipulate path components, and create/delete files and directories."},"warnings":[{"fix":"Remove `pathlib2` from your dependencies and change imports from `from pathlib2 import Path` to `from pathlib import Path`.","message":"For Python 3.4 and newer, use the standard library module `pathlib` instead of `pathlib2`. `pathlib2` is a backport for older Python versions only.","severity":"breaking","affected_versions":"All Python versions >= 3.4"},{"fix":"If you require newer `pathlib` features, you must migrate to a Python version where the standard library `pathlib` includes those features and switch away from `pathlib2`.","message":"`pathlib2`'s API reflects an older state of the standard library `pathlib`. It does not include features, methods, or bug fixes introduced in `pathlib` in more recent Python versions (e.g., Python 3.5+).","severity":"gotcha","affected_versions":"All `pathlib2` versions compared to `pathlib` in Python 3.5+"},{"fix":"Be aware that `pathlib2` is stable but not actively evolving. For projects needing active development or modern `pathlib` features, prioritize Python versions with a current standard library `pathlib`.","message":"The `pathlib2` project is maintained by Jazzband, which implies community maintenance for its intended purpose (older Python versions). Active feature development or significant updates to align with the latest `pathlib` API are not expected.","severity":"gotcha","affected_versions":"All `pathlib2` versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}