Registry / serialization / pathlib-abc

pathlib-abc

JSON →
library0.5.2pypypi✓ verified 52d ago

pathlib-abc is a Python library that provides abstract base classes (ABCs) for `pathlib.Path`-like objects. It serves as a backport and preview of `pathlib` functionality intended for future Python standard library releases, specifically designed to enable path implementations for non-local filesystems (e.g., archives, remote storage). The library is currently at version 0.5.2 and is under active development, requiring Python 3.9+.

serialization
pip install pathlib-abc
Install & Compatibility
Where this runs
tested against v0.5.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.930 runs
installs and imports cleanly · install 0.0s · import 0.016s · 17.9MB
glibc
py 3.103.930 runs
installs and imports cleanly · install 1.5s · import 0.014s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

JoinablePath
from pathlib_abc import JoinablePath
ReadablePath
from pathlib_abc import ReadablePath
WritablePath
from pathlib_abc import WritablePath

This quickstart demonstrates how to create a custom path class by inheriting from `JoinablePath` and implementing the necessary abstract methods. It shows basic path manipulation using the overloaded division operator and accessing path components like `parent` and `name`.

from pathlib_abc import JoinablePath, PathInfo class CustomPath(JoinablePath): _parser = JoinablePath._pathmod.posixpath # Example: use POSIX path parsing def __init__(self, path_str): self._path = path_str def __str__(self): return self._path @property def info(self) -> PathInfo: # In a real implementation, this would return actual file system info. # For this example, we return a basic PathInfo instance. return PathInfo(is_dir=True, is_file=False, is_symlink=False) def _with_segments(self, segments): return CustomPath(self._parser.join(*segments)) # Example usage: base = CustomPath('/my/virtual/root') file_path = base / 'folder' / 'document.txt' print(f"Base path: {base}") print(f"File path: {file_path}") print(f"Parent of file_path: {file_path.parent}") print(f"Name of file_path: {file_path.name}")
Debug
Known issues
gotchaThe `pathlib-abc` classes (`JoinablePath`, `ReadablePath`, `WritablePath`) are currently not direct parent classes of the standard library `pathlib.Path` classes. Therefore, `isinstance(custom_path_object, pathlib.Path)` will return `False`.
fix
Do not assume direct inheritance from standard `pathlib` types. Implementations using `pathlib-abc` should define their own class hierarchies or explicitly cast/convert if `pathlib.Path` compatibility is needed.
affects: All versions
breakingThese base classes are under active development and are a 'preview' of future Python functionality. Their interface and behavior might change in minor versions as they evolve, and they may eventually be integrated into the standard library's public API, potentially making this package a backport.
fix
Regularly review the `pathlib-abc` changelog and documentation for updates. Pin exact versions in production environments to avoid unexpected changes.
affects: All versions (due to active development)
gotchaThe `pathlib` ABCs exist in Python 3.13+ within the *private* `pathlib._abc` module. Direct import or reliance on this private standard library module is discouraged and not officially supported.
fix
For consistent and stable usage across Python versions, always use `pathlib-abc` from PyPI when implementing custom path classes for non-local filesystems. Avoid importing from `pathlib._abc` in the standard library.
affects: Python 3.13+
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pathlib_abc'
The `pathlib-abc` library is not installed in the current Python environment.
fix
pip install pathlib-abc
TypeError: Can't instantiate abstract class JoinablePath with abstract methods '_parse_uri', '_uri', 'is_absolute', 'is_reserved', 'is_root'
`JoinablePath` (and similarly `ReadablePath`, `WritablePath`) are Abstract Base Classes (ABCs) and cannot be instantiated directly; their abstract methods must be implemented in a concrete subclass.
fix
Subclass the desired `pathlib-abc` ABC (e.g., `JoinablePath`) and implement all its required abstract methods within your custom path class.
AttributeError: module 'pathlib' has no attribute '_Flavour'
Your custom path implementation is relying on internal `pathlib` attributes (like `_Flavour`) that are not part of its public API and have been removed or changed in newer Python versions (e.g., Python 3.12), leading to incompatibility. `pathlib-abc` provides the correct public ABCs for creating compatible custom path objects.
fix
Update your custom path class to inherit from `pathlib-abc`'s `JoinablePath`, `ReadablePath`, or `WritablePath` ABCs instead of relying on `pathlib`'s internal structure.
UnsupportedOperation: ...
A method was called on a custom `pathlib-abc` implementation that is not supported by the underlying non-local filesystem (e.g., an archive or remote storage) that your path object represents.
fix
Implement the unsupported method in your custom `pathlib-abc` subclass if the operation is feasible for your specific non-local filesystem, or handle the `UnsupportedOperation` exception gracefully if the operation is genuinely not supported by your custom path's backend.
Upgrade
Version history
0.5.2latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
4
seranking-bot
4
ahrefsbot
2
Resources