{"id":1009,"library":"pathlib-abc","title":"Pathlib Abstract Base Classes","description":"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+.","status":"active","version":"0.5.2","language":"python","source_language":"en","source_url":"https://github.com/barneygale/pathlib-abc","tags":["pathlib","abc","filesystem","virtual-filesystem","backport"],"install":[{"cmd":"pip install pathlib-abc","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"JoinablePath","correct":"from pathlib_abc import JoinablePath"},{"symbol":"ReadablePath","correct":"from pathlib_abc import ReadablePath"},{"symbol":"WritablePath","correct":"from pathlib_abc import WritablePath"}],"quickstart":{"code":"from pathlib_abc import JoinablePath, PathInfo\n\nclass CustomPath(JoinablePath):\n    _parser = JoinablePath._pathmod.posixpath # Example: use POSIX path parsing\n\n    def __init__(self, path_str):\n        self._path = path_str\n\n    def __str__(self):\n        return self._path\n\n    @property\n    def info(self) -> PathInfo:\n        # In a real implementation, this would return actual file system info.\n        # For this example, we return a basic PathInfo instance.\n        return PathInfo(is_dir=True, is_file=False, is_symlink=False)\n\n    def _with_segments(self, segments):\n        return CustomPath(self._parser.join(*segments))\n\n# Example usage:\nbase = CustomPath('/my/virtual/root')\nfile_path = base / 'folder' / 'document.txt'\nprint(f\"Base path: {base}\")\nprint(f\"File path: {file_path}\")\nprint(f\"Parent of file_path: {file_path.parent}\")\nprint(f\"Name of file_path: {file_path.name}\")\n","lang":"python","description":"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`."},"warnings":[{"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.","message":"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`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Regularly review the `pathlib-abc` changelog and documentation for updates. Pin exact versions in production environments to avoid unexpected changes.","message":"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.","severity":"breaking","affected_versions":"All versions (due to active development)"},{"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.","message":"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.","severity":"gotcha","affected_versions":"Python 3.13+"}],"env_vars":null,"last_verified":"2026-05-12T22:32:25.514Z","next_check":"2026-06-27T00:00:00.000Z","problems":[{"fix":"pip install pathlib-abc","cause":"The `pathlib-abc` library is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'pathlib_abc'"},{"fix":"Subclass the desired `pathlib-abc` ABC (e.g., `JoinablePath`) and implement all its required abstract methods within your custom path class.","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.","error":"TypeError: Can't instantiate abstract class JoinablePath with abstract methods '_parse_uri', '_uri', 'is_absolute', 'is_reserved', 'is_root'"},{"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.","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.","error":"AttributeError: module 'pathlib' has no attribute '_Flavour'"},{"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.","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.","error":"UnsupportedOperation: ..."}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.5.2","cli_name":"","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"17.9M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"17.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.5,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"18M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1,"disk_size":"19.8M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1,"disk_size":"19.8M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.5,"import_time_s":0.03,"mem_mb":1,"disk_size":"20M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.8,"disk_size":"11.6M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.8,"disk_size":"11.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.4,"import_time_s":0.02,"mem_mb":0.8,"disk_size":"12M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.8,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.9,"disk_size":"11.4M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.9,"disk_size":"11.2M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.4,"import_time_s":0.01,"mem_mb":0.7,"disk_size":"12M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.7,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"17.4M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"17.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.7,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"18M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":null,"tag_description":null,"results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}