panpath.base
Universal path base class and factory.
This class inherits from pathlib.Path and serves dual purposes: 1. Base class for all path types in the panpath package 2. Factory for creating appropriate path instances via new
As a base class, it's inherited by:
- - LocalPath (local filesystem paths with sync and async methods)
- - CloudPath (cloud storage paths with sync and async methods)
- - All cloud-specific subclasses (GSPath, S3Path, AzurePath, etc.)
As a factory, calling PanPath(...) returns the appropriate concrete implementationbased on the URI scheme.
Use isinstance(obj, PanPath) to check if an object is a path created by this package.
anchor— The concatenation of the drive and root, or ''.</>drive— The drive prefix (letter or UNC path), if any.</>name— The final path component, if any.</>parent— The logical parent of the path.</>parents— A sequence of this path's logical parents.</>parts— An object providing sequence-like access to thecomponents in the filesystem path. </>root— The root of the path, if any.</>stem— The final path component, minus its last suffix.</>suffix— The final component's last suffix, if any.
This includes the leading period. For example: '.txt' </>suffixes— A list of the final component's suffixes, if any.
These include the leading periods. For example: ['.tar', '.gz'] </>
__bytes__()— Return the bytes representation of the path. This is onlyrecommended to use under Unix. </>__new__(cls,*args,**kwargs)(PanPath) — Create and return the appropriate path instance.</>__str__()— Return the string representation of the path, suitable forpassing to system calls. </>a_copy(target)(PanPath) — Asynchronously copy this path to the target path.</>a_copytree(target,follow_symlinks)(PanPath) — Asynchronously copy the directory and all its contents recursively to the target path.</>a_exists()(bool) — Asynchronously check if the path exists.</>a_glob(pattern)(AsyncGenerator) — Asynchronously yield paths matching a glob pattern.</>a_is_dir()(bool) — Asynchronously check if the path is a directory.</>a_is_file()(bool) — Asynchronously check if the path is a file.</>a_is_symlink()(bool) — Asynchronously check if the path is a symbolic link.</>a_iterdir()(AsyncGenerator) — Asynchronously iterate over directory contents.</>a_mkdir(mode,parents,exist_ok)— Asynchronously create a directory at this path.</>a_open(mode,encoding,**kwargs)(AsyncFileHandle) — Asynchronously open the file and return an async file handle.</>a_read_bytes()(bytes) — Asynchronously read the file's bytes.</>a_read_text(encoding)(str) — Asynchronously read the file's text content.</>a_readlink()(PanPath) — Asynchronously read the target of the symbolic link.</>a_rename(target)(PanPath) — Asynchronously rename this path to the target path.</>a_replace(target)(PanPath) — Asynchronously replace this path with the target path.</>a_resolve()(PanPath) — Resolve to absolute path (no-op for cloud paths).</>a_rglob(pattern)(AsyncGenerator) — Asynchronously yield paths matching a recursive glob pattern.</>a_rmdir()— Asynchronously remove the directory and its contents recursively.</>a_rmtree(ignore_errors,onerror)— Asynchronously remove the directory and all its contents recursively.</>a_stat(follow_symlinks)(stat_result) — Asynchronously get the file or directory's status information.</>a_symlink_to(target,target_is_directory)— Asynchronously create a symbolic link pointing to the target path.</>a_touch(mode,exist_ok)— Asynchronously create the file if it does not exist.</>a_unlink(missing_ok)— Asynchronously remove (delete) the file or empty directory.</>a_walk()(AsyncGenerator) — Asynchronously walk the directory tree.</>a_write_bytes(data)(Optional) — Asynchronously write bytes to the file.</>a_write_text(data,encoding)(int) — Asynchronously write text to the file.</>absolute()— Return an absolute version of this path by prepending the currentworking directory. No normalization or symlink resolution is performed. </>as_posix()— Return the string representation of the path with forward (/)slashes. </>as_uri()— Return the path as a 'file' URI.</>chmod(mode,follow_symlinks)— Change the permissions of the path, like os.chmod().</>cwd()— Return a new path pointing to the current working directory.</>exists(follow_symlinks)— Whether this path exists.</>expanduser()— Return a new path with expanded ~ and ~user constructs(as returned by os.path.expanduser) </>glob(pattern,case_sensitive)— Iterate over this subtree and yield all existing files (of anykind, including directories) matching the given relative pattern. </>group()— Return the group name of the file gid.</>hardlink_to(target)— Make this path a hard link pointing to the same file as target.</>home()— Return a new path pointing to the user's home directory (asreturned by os.path.expanduser('~')). </>is_absolute()— True if the path is absolute (has both a root and, if applicable,a drive). </>is_block_device()— Whether this path is a block device.</>is_char_device()— Whether this path is a character device.</>is_dir()— Whether this path is a directory.</>is_fifo()— Whether this path is a FIFO.</>is_file()— Whether this path is a regular file (also True for symlinks pointingto regular files). </>is_junction()— Whether this path is a junction.</>is_mount()— Check if this path is a mount point</>is_relative_to(other,*_deprecated)— Return True if the path is relative to another path or False.</>is_reserved()— Return True if the path contains one of the special names reservedby the system, if any. </>is_socket()— Whether this path is a socket.</>is_symlink()— Whether this path is a symbolic link.</>iterdir()— Yield path objects of the directory contents.</>joinpath(*pathsegments)— Combine this path with one or several arguments, and return anew path representing either a subpath (if all arguments are relative paths) or a totally different path (if one of the arguments is anchored). </>lchmod(mode)— Like chmod(), except if the path points to a symlink, the symlink'spermissions are changed, rather than its target's. </>lstat()— Like stat(), except if the path points to a symlink, the symlink'sstatus information is returned, rather than its target's. </>match(path_pattern,case_sensitive)— Return True if this path matches the given pattern.</>mkdir(mode,parents,exist_ok)— Create a new directory at this given path.</>open(mode,buffering,encoding,errors,newline)— Open the file pointed to by this path and return a file object, asthe built-in open() function does. </>owner()— Return the login name of the file owner.</>read_bytes()— Open the file in bytes mode, read it, and close the file.</>read_text(encoding,errors)— Open the file in text mode, read it, and close the file.</>readlink()— Return the path to which the symbolic link points.</>relative_to(other,*_deprecated,walk_up)— Return the relative path to another path identified by the passedarguments. If the operation is not possible (because this is not related to the other path), raise ValueError. </>rename(target)— Rename this path to the target path.</>replace(target)— Rename this path to the target path, overwriting if that path exists.</>resolve(strict)— Make the path absolute, resolving all symlinks on the way and alsonormalizing it. </>rglob(pattern,case_sensitive)— Recursively yield all existing files (of any kind, includingdirectories) matching the given relative pattern, anywhere in this subtree. </>rmdir()— Remove this directory. The directory must be empty.</>samefile(other_path)— Return whether other_path is the same or not as this file(as returned by os.path.samefile()). </>stat(follow_symlinks)— Return the result of the stat() system call on this path, likeos.stat() does. </>symlink_to(target,target_is_directory)— Make this path a symlink pointing to the target path.Note the order of arguments (link, target) is the reverse of os.symlink. </>touch(mode,exist_ok)— Create this file with the given access mode, if it doesn't exist.</>unlink(missing_ok)— Remove this file or link.If the path is a directory, use rmdir() instead. </>walk()— Walk the directory tree.</>with_name(name)— Return a new path with the file name changed.</>with_segments(*pathsegments)— Construct a new path object from any number of path-like objects.Subclasses may override this method to customize how new path objects are created from methods likeiterdir(). </>with_stem(stem)— Return a new path with the stem changed.</>with_suffix(suffix)— Return a new path with the file suffix changed. If the pathhas no suffix, add given suffix. If the given suffix is an empty string, remove the suffix from the path. </>write_bytes(data)— Open the file in bytes mode, write to it, and close the file.</>write_text(data,encoding,errors,newline)— Open the file in text mode, write to it, and close the file.</>
with_segments(*pathsegments)
Construct a new path object from any number of path-like objects.Subclasses may override this method to customize how new path objects
are created from methods like iterdir().
with_suffix(suffix)
Return a new path with the file suffix changed. If the pathhas no suffix, add given suffix. If the given suffix is an empty string, remove the suffix from the path.
relative_to(other, *_deprecated, walk_up=False)
Return the relative path to another path identified by the passedarguments. If the operation is not possible (because this is not related to the other path), raise ValueError.
The walk_up parameter controls whether .. may be used to resolve
the path.
is_relative_to(other, *_deprecated)
Return True if the path is relative to another path or False.
is_absolute()
True if the path is absolute (has both a root and, if applicable,a drive).
is_reserved()
Return True if the path contains one of the special names reservedby the system, if any.
is_symlink()
Whether this path is a symbolic link.
is_junction()
Whether this path is a junction.
is_block_device()
Whether this path is a block device.
is_char_device()
Whether this path is a character device.
read_bytes()
Open the file in bytes mode, read it, and close the file.
write_bytes(data)
Open the file in bytes mode, write to it, and close the file.
write_text(data, encoding=None, errors=None, newline=None)
Open the file in text mode, write to it, and close the file.
Rename this path to the target path, overwriting if that path exists.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
symlink_to(target, target_is_directory=False)
Make this path a symlink pointing to the target path.Note the order of arguments (link, target) is the reverse of os.symlink.
hardlink_to(target)
Make this path a hard link pointing to the same file as target.
Note the order of arguments (self, target) is the reverse of os.link's.
expanduser()
Return a new path with expanded ~ and ~user constructs(as returned by os.path.expanduser)
a_exists()
Asynchronously check if the path exists.
True if the path exists, False otherwise.
a_read_bytes()
Asynchronously read the file's bytes.
File content as bytes.
a_read_text(encoding='utf-8')
Asynchronously read the file's text content.
encoding(str, optional) — Text encoding to use (default: 'utf-8')
File content as string.
a_write_bytes(data)
Asynchronously write bytes to the file.
data(bytes) — Bytes to write to the file.
Number of bytes written. For some cloud paths, may return None.
a_write_text(data, encoding='utf-8')
Asynchronously write text to the file.
data(str) — Text to write to the file.encoding(str, optional) — Text encoding to use (default: 'utf-8')
Number of characters written.
a_unlink(missing_ok=False)
Asynchronously remove (delete) the file or empty directory.
missing_ok(bool, optional) — If True, does not raise an error if the file does not exist.
a_iterdir()
Asynchronously iterate over directory contents.
PanPath instances for each item in the directory.
a_is_dir()
Asynchronously check if the path is a directory.
True if the path is a directory, False otherwise.
a_is_file()
Asynchronously check if the path is a file.
True if the path is a file, False otherwise.
a_stat(follow_symlinks=True)
Asynchronously get the file or directory's status information.
An object containing file status information (platform-dependent).
a_mkdir(mode=511, parents=False, exist_ok=False)
Asynchronously create a directory at this path.
mode(int, optional) — Directory mode (permissions) to set.parents(bool, optional) — If True, create parent directories as needed.exist_ok(bool, optional) — If True, does not raise an error if the directory already exists.
a_glob(pattern)
Asynchronously yield paths matching a glob pattern.
pattern(str) — Glob pattern to match.
List of PanPath instances matching the pattern.
a_rglob(pattern)
Asynchronously yield paths matching a recursive glob pattern.
pattern(str) — Recursive glob pattern to match.
List of PanPath instances matching the pattern.
a_walk()
Asynchronously walk the directory tree.
Tuples of (current_path, dirnames, filenames) at each level.
a_touch(mode=438, exist_ok=True)
Asynchronously create the file if it does not exist.
mode(int, optional) — File mode (permissions) to set if creating the file.exist_ok(bool, optional) — If False, raises an error if the file already exists.
a_rmdir()
Asynchronously remove the directory and its contents recursively.
a_is_symlink()
Asynchronously check if the path is a symbolic link.
For local path, this checks if the path is a symlink. For cloud paths, this will check if the object has a metdata flag indicating it's a symlink. Note that it is not a real symlink like in local filesystems. But for example, gcsfuse supports symlink-like behavior via metadata.
True if the path is a symlink, False otherwise.
a_symlink_to(target, target_is_directory=False)
Asynchronously create a symbolic link pointing to the target path.
For local path, this creates a real symlink. For cloud paths, this sets a metadata flag indicating the symlink target.
target(Union) — The target PanPath the symlink points to.target_is_directory(bool, optional) — Whether the target is a directory (ignored for cloud paths).
a_rmtree(ignore_errors=False, onerror=None)
Asynchronously remove the directory and all its contents recursively.
ignore_errors(bool, optional) — If True, ignores errors during removal.onerror(Any, optional) — Optional function to call on errors.
a_copytree(target, follow_symlinks=True)
Asynchronously copy the directory and all its contents recursively to the target path.
target(Union) — Destination PanPath to copy to.follow_symlinks(bool, optional) — If True, copies the contents of symlinks.
The copied PanPath instance.
a_open(mode='r', encoding='utf-8', **kwargs)
Asynchronously open the file and return an async file handle.
mode(str, optional) — Mode to open the file (e.g., 'r', 'rb', 'w', 'wb').encoding(str, optional) — Text encoding to use (default: 'utf-8').**kwargs(Any) — Additional arguments to pass to the underlying open method.
An async file handle.
walk()
Walk the directory tree.
Tuples of (current_path, dirnames, filenames) at each level.