Unipath

raw JSON →
1.1 verified Mon Apr 27 auth: no python maintenance

Unipath provides an object-oriented alternative to os/os.path/shutil for Python file system path manipulation, wrapping common operations in a Path class. Current version is 1.1, stable but in maintenance mode with infrequent releases.

pip install Unipath
error AttributeError: module 'unipath' has no attribute 'Path'
cause Incorrect import: 'from unipath import Path' is correct; 'import unipath' does not expose Path directly.
fix
Use: from unipath import Path
error TypeError: expected str, bytes or os.PathLike object, not Path
cause Unipath Path is a subclass of str, but some functions in Python standard library may not accept it directly. Convert to str explicitly.
fix
Use str(p) when passing to functions that expect str or os.PathLike.
error DeprecationWarning: unipath.Path is deprecated, use pathlib instead
cause Unipath is deprecated; this warning may be issued in some environments.
fix
Migrate to pathlib.Path: from pathlib import Path.
breaking Unipath does not work with Python 3.12+ if using any import of 'os.path' functions that have been removed (e.g., os.path.walk). The library itself is compatible with Python up to 3.11. For Python 3.12+, consider using pathlib which is available in the standard library.
fix Migrate to pathlib.Path for Python 3.12+ compatibility. Unipath may not receive updates.
deprecated Unipath is no longer actively developed. The author recommends using pathlib from the standard library for new projects.
fix Use pathlib.Path instead: from pathlib import Path.
gotcha Unipath's Path inherits from str, so string concatenation with '+' may not work as expected. Use .child() method for joining paths.
fix Use p.child('subdir') instead of p + '/subdir'.
gotcha The .exists() method caches results; if the file system changes, use .exists(refresh=True) to get current status.
fix Call p.exists(refresh=True) to bypass cache.

Basic usage: create a Path and check existence/read content.

from unipath import Path

# Create a Path object
p = Path('/tmp/example.txt')
# Check existence
print(p.exists())  # True if file exists
# Read content
if p.exists():
    print(p.read_file())