Pathlib Abstract Base Classes
raw JSON → 0.5.2 verified Tue May 12 auth: no python install: verified
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+.
pip install pathlib-abc Common errors
error ModuleNotFoundError: No module named 'pathlib_abc' ↓
cause The `pathlib-abc` library is not installed in the current Python environment.
fix
pip install pathlib-abc
error TypeError: Can't instantiate abstract class JoinablePath with abstract methods '_parse_uri', '_uri', 'is_absolute', 'is_reserved', 'is_root' ↓
cause `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. error AttributeError: module 'pathlib' has no attribute '_Flavour' ↓
cause 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. error UnsupportedOperation: ... ↓
cause 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. Warnings
gotcha The `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.
breaking These 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.
gotcha The `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.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.01s 17.9M
3.10 alpine (musl) - - 0.01s 17.9M
3.10 slim (glibc) wheel 1.5s 0.01s 18M
3.10 slim (glibc) - - 0.01s 18M
3.11 alpine (musl) wheel - 0.02s 19.8M
3.11 alpine (musl) - - 0.04s 19.8M
3.11 slim (glibc) wheel 1.5s 0.03s 20M
3.11 slim (glibc) - - 0.02s 20M
3.12 alpine (musl) wheel - 0.02s 11.6M
3.12 alpine (musl) - - 0.02s 11.6M
3.12 slim (glibc) wheel 1.4s 0.02s 12M
3.12 slim (glibc) - - 0.02s 12M
3.13 alpine (musl) wheel - 0.01s 11.4M
3.13 alpine (musl) - - 0.02s 11.2M
3.13 slim (glibc) wheel 1.4s 0.01s 12M
3.13 slim (glibc) - - 0.01s 12M
3.9 alpine (musl) wheel - 0.01s 17.4M
3.9 alpine (musl) - - 0.01s 17.4M
3.9 slim (glibc) wheel 1.7s 0.01s 18M
3.9 slim (glibc) - - 0.01s 18M
Imports
- JoinablePath
from pathlib_abc import JoinablePath - ReadablePath
from pathlib_abc import ReadablePath - WritablePath
from pathlib_abc import WritablePath
Quickstart last tested: 2026-04-24
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}")