fspath - semantic path names and more

raw JSON →
20230629 verified Mon Apr 27 auth: no python

fspath (v20230629) provides semantic path names and file system path utilities for Python. It offers a lightweight, intuitive API for common path manipulations. The project is in maintenance mode with infrequent releases.

pip install fspath
error AttributeError: 'str' object has no attribute 'ext'
cause fspath methods and attributes (like .ext) are only available on fspath objects, not plain strings.
fix
Convert string paths to fspath: p = fspath.frompath('/path/to/file.txt') then use p.ext
error ImportError: No module named 'fspath'
cause fspath is not installed or installed in a different environment.
fix
Run 'pip install fspath' in your virtual environment.
gotcha fspath is not compatible with pathlib.Path on all operations. Converting between types may lose semantic attributes.
fix Always use fspath methods directly; avoid mixing with pathlib unless documented.
deprecated The library is in maintenance mode with rare updates. New projects should consider using pathlib (Python 3.4+) or pathlib2 for older versions.
fix Prefer pathlib for new projects; use fspath only for backward compatibility.

Basic usage: create fspath objects and access semantic path components.

import fspath

# Create a path object
p = fspath.frompath('/tmp/example.txt')
print(p)  # /tmp/example.txt

# Check properties
print(p.exists())
print(p.is_file())

# Use semantic methods
print(p.ext)  # .txt
print(p.stem)  # example
print(p.parent)