Path utilities for Python
Pathtools is a Python library providing pattern matching and various utilities for file system paths. The library is currently at version 0.1.2 and was last updated in 2011, indicating an abandoned or extremely slow release cadence.
Warnings
- breaking The `pathtools` library is incompatible with Python 3.12 and newer versions due to its reliance on the removed `imp` module in its `setup.py`.
- deprecated The `pathtools` project appears to be unmaintained, with the last commit over 10 years ago and no new releases since 2011. For new projects, the built-in `pathlib` module (available since Python 3.4) offers a more modern, object-oriented, and actively maintained alternative for path manipulation.
- gotcha The library's functionality is limited compared to modern alternatives like `pathlib`. It lacks features such as direct path object manipulation, platform-independent path construction (beyond basic separators), and integration with asynchronous operations.
Install
-
pip install pathtools
Imports
- filter_paths
from pathtools.patterns import filter_paths
- match_path
from pathtools.patterns import match_path
- absolute_path
from pathtools.path import absolute_path
Quickstart
import os
from pathtools.patterns import filter_paths
# Create some dummy files for demonstration
os.makedirs("temp_dir", exist_ok=True)
with open("temp_dir/file1.txt", "w") as f: f.write("test")
with open("temp_dir/image.png", "w") as f: f.write("test")
with open("temp_dir/document.pdf", "w") as f: f.write("test")
all_paths = [
"temp_dir/file1.txt",
"temp_dir/image.png",
"temp_dir/document.pdf",
"temp_dir/another.txt",
"ignore_me.log"
]
# Filter paths to include only .txt files and exclude 'ignore_me.log'
included_patterns = ['*.txt']
excluded_patterns = ['*ignore_me.log']
filtered = filter_paths(all_paths, included_patterns, excluded_patterns)
print(list(filtered))
# Clean up
os.remove("temp_dir/file1.txt")
os.remove("temp_dir/image.png")
os.remove("temp_dir/document.pdf")
os.rmdir("temp_dir")