class hscommon.path.Path

A handy class to work with paths.

We subclass tuple, each element of the tuple represents an element of the path.

  • Path('/foo/bar/baz')[1] –> 'bar'
  • Path('/foo/bar/baz')[1:2] –> Path('bar/baz')
  • Path('/foo/bar')['baz'] –> Path('/foo/bar/baz')
  • str(Path('/foo/bar/baz')) –> '/foo/bar/baz'

Whether other is a subpath of self.

Almost the same as other in self, but it’s a bit more self-explicative and when other == self, returns False.


Returns the parent path.

Path('/foo/bar/baz').parent() –> Path('/foo/bar')


Last element of the path (filename), with extension.

Path('/foo/bar/baz').name –> 'baz'


Catches OSError, IOError and WindowsError and log them


Ensure that every annotated Path arguments are actually paths.

When a function is decorated with @pathify, every argument with annotated as Path will be converted to a Path if it wasn’t already. Example:

def foo(path: Path, otherarg):
    return path.listdir()

Calling foo('/bar', 0) will convert '/bar' to Path('/bar').