Skip to content

bagof.paths.PurePath

PurePath(path: Any, *, driver: Any = None, storage_options: Mapping[str, Any] | None = None)

Bases: PurePathMixin, BaseWrapper

A path for lexical operations only, local or in the cloud.

A PurePath parses and manipulates a path without touching any filesystem. It provides the lexical surface -- name, parent, suffix, joinpath, with_name, and the rest -- together with the location properties protocol, path, drive, and root. It has no reading, writing, listing, or other I/O methods.

A remote URL is understood with no backend installed, so a cloud location can be taken apart and rebuilt without universal-pathlib or cloudpathlib.

>>> from bagof.paths import PurePath
>>> p = PurePath("/data/sets/train.zarr")
>>> p.name
'train.zarr'
>>> p.parent
PurePath('/data/sets')
>>> p.suffix
'.zarr'

A PurePath, a Path and an AsyncPath for the same location compare equal and hash alike, so one serves to look another up in a set or a dictionary. This mirrors pathlib, where a pure path equals the full path beside it. A local one also equals, and hashes like, the pathlib path at the same place.