Registry / serialization / pathlib-mate

pathlib-mate

JSON →
library1.3.2pypypi✓ verified 23d ago

Pathlib Mate (pathlib-mate) is a Python library that extends and enhances the standard `pathlib` module, providing more powerful and user-friendly methods and attributes for path manipulation. It offers convenient attribute accessors for path components, advanced file and directory search capabilities, and utility methods for common file operations. The library is actively maintained, with releases occurring infrequently, the latest being in January 2024.

pip install pathlib-mate
INSTALL
IMPORT
SIG · PATHLIB-MATE
P
pathlib-mate
serializationpythonv1.3.2
Install
1.6s avg
Import
72ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.069s · 18.3MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.074s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Path
from pathlib_mate import Path
from pathlib import Path
To access the extended functionality provided by pathlib-mate, you must import its `Path` class, not the standard library's `pathlib.Path`.

This quickstart demonstrates how to create a `Path` object from `pathlib-mate`, access its extended attributes like `abspath`, `basename`, `fname`, and `ext`, and perform powerful search operations using methods like `select_by_ext`. It creates and cleans up a temporary directory and files to illustrate functionality.

import os from pathlib_mate import Path import shutil # Create a temporary directory and file for demonstration test_dir = Path("pathlib_mate_demo_dir") test_file = test_dir / "example.txt" try: test_dir.mkdir(parents=True, exist_ok=True) test_file.write_text("Hello, pathlib-mate!") # 1. Basic Path Creation and Attribute Access p = Path(test_file.abspath) print(f"Absolute path: {p.abspath}") print(f"File name with extension: {p.basename}") print(f"File name without extension: {p.fname}") print(f"File extension: {p.ext}") print(f"Parent directory name: {p.dirname}") print(f"Parent directory path: {p.dirpath}") print(f"File size in bytes: {p.size}") print(f"File size (human readable): {p.size_in_text}") # 2. Powerful Path Search (example: find all text files) # Create another file for search demo (test_dir / "another.txt").write_text("Another file.") (test_dir / "image.jpg").write_bytes(b'fake_image_data') print("\nSearching for .txt files:") for txt_file in test_dir.select_by_ext(ext=".txt", recursive=True): print(f" Found: {txt_file.basename}") finally: # Clean up temporary directory if test_dir.exists(): shutil.rmtree(test_dir.abspath) print("\nCleanup complete.")
Debug
Known issues
gotchaAlways import `Path` from `pathlib_mate` (e.g., `from pathlib_mate import Path`) to ensure you access the extended functionality. Importing from the standard `pathlib` will result in a basic `Path` object without the `pathlib-mate` enhancements.
fix
Ensure your import statement explicitly references `pathlib_mate`: `from pathlib_mate import Path`.
affects: All versions
gotchaAvoid converting `pathlib_mate.Path` objects to strings (`str(path_obj)`) prematurely. Many Python functions and modern libraries (including `open()`, `shutil` operations, `json` functions, etc.) natively accept `Path` objects (since Python 3.6+). Converting to string too early can lead to loss of Path object methods, reduce type safety, and mask potential cross-platform issues.
fix
Pass `Path` objects directly to functions whenever possible. Only convert to `str()` when interacting with older libraries that explicitly do not support `os.PathLike` objects.
affects: All versions
gotchaWhile `pathlib-mate` extends `pathlib`, some file manipulation methods may have improved alternatives. For example, `pathlib-mate` introduces `Path.moveto()` as a more powerful and flexible alternative to the default `Path.rename()` method for moving/renaming files. Be aware of these specialized methods to leverage the full power of the library.
fix
Review `pathlib-mate`'s documentation for enhanced file manipulation methods like `moveto()`, `copyto()`, and specialized `select_*()` methods, which often offer more control or simplified usage compared to their standard `pathlib` counterparts.
affects: All versions
gotchaFor extremely performance-critical operations involving thousands or millions of file system interactions in a tight loop, the object-oriented overhead of `pathlib` (and by extension `pathlib-mate`) *can* be slightly higher than raw string manipulation with `os.path`. For most applications, the benefits in readability and correctness outweigh this minor difference.
fix
Profile your code if performance is a concern. If `pathlib-mate` operations are identified as a bottleneck in extreme scenarios, consider low-level `os.path` functions for that specific, optimized section, though this is rarely necessary.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pathlib_mate'
The `pathlib-mate` library is not installed in the active Python environment or is not accessible from where the code is being executed.
fix
Install the library using pip: `pip install pathlib-mate`
AttributeError: partially initialized module 'pathlib' has no attribute 'Path' (most likely due to a circular import)
This error occurs when a user's own file or another module in the Python path is named `pathlib.py` or `pathlib_mate.py`, causing Python to import the local file instead of the actual `pathlib` or `pathlib-mate` library.
fix
Rename any custom files named `pathlib.py` or `pathlib_mate.py` to avoid name collisions with the installed library.
TypeError: unsupported operand type(s) for /: 'Path' and 'str'
This error usually indicates that the `Path` object being used for path concatenation with the `/` operator is not an instance of `pathlib.Path` (or by extension, `pathlib_mate.Path`), but rather a string or a `Path`-like object from a different library that does not support this specific operator with a string. This often happens due to an incorrect import.
fix
Ensure that you are correctly importing `Path` from `pathlib_mate` using `from pathlib_mate import Path` and that no other `Path` class from a different library is accidentally shadowing it.
FileNotFoundError: [Errno 2] No such file or directory: 'your_file.txt'
This is a common operating system error indicating that a file or directory specified in your `pathlib-mate` operation does not exist at the given path, often due to an incorrect relative path, an absolute path typo, or the file simply not being present.
fix
Verify the exact path, ensure the file/directory exists, and confirm that your script's current working directory is as expected, especially when using relative paths. Use `Path.cwd()` to check the current directory if necessary.
Upgrade
Version history
1.3.2latest on PyPI · released Jan 22, 2024
Audit
Dependencies
PythonrequiredRequires Python 3.7 or newer to run.
boltonsoptionalUsed for atomic write functionality (e.g., `Path.atomic_write()`).
Agent activity
7 hits · last 30 days
node
6
Resources
pathlib-mate — pip install pathlib-mate · libregistry