Skip to content
module

panpath.local_path

Local filesystem path implementation.

Classes
  • LocalPath Local filesystem path (drop-in replacement for pathlib.Path).</>
class

panpath.local_path.LocalPath(*args, **kwargs)

Bases
pathlib.PosixPath panpath.base.PanPath pathlib.Path pathlib.PurePosixPath pathlib.PurePath

Local filesystem path (drop-in replacement for pathlib.Path).

Inherits from the platform-specific concrete path class (PosixPath/WindowsPath) and PanPath for full compatibility. The concrete class must come first in MRO to ensure proper flavour attribute inheritance in Python 3.10. Includes both sync methods (from Path) and async methods with a prefix.

Attributes
  • 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'] </>
Methods
  • __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, follow_symlinks) (PanPath) Copy file to target.</>
  • a_copytree(target, follow_symlinks) (PanPath) Recursively copy the directory and all its contents to the target path.</>
  • a_exists() (bool) Check if path exists (async).</>
  • a_glob(pattern) (AsyncGenerator) Asynchronously yield paths matching the glob pattern.</>
  • a_is_dir() (bool) Check if path is a directory (async).</>
  • a_is_file() (bool) Check if path is a file (async).</>
  • a_is_symlink() (bool) Check if path is a symlink (async).</>
  • a_iterdir() (AsyncGenerator) List directory contents (async).</>
  • a_mkdir(mode, parents, exist_ok) Create directory (async).</>
  • a_open(mode, buffering, encoding, errors, newline) (Any) Open file and return async file handle.</>
  • a_read_bytes() (bytes) Read file as bytes (async).</>
  • a_read_text(encoding) (str) Read file as text (async).</>
  • a_readlink() (LocalPath) Asynchronously read the target of a symbolic link.</>
  • a_rename(target) (PanPath) Rename the file or directory to target.</>
  • a_replace(target) (PanPath) Rename the file or directory to target, overwriting if target exists.</>
  • a_resolve() (PanPath) Resolve to absolute path (no-op for cloud paths).</>
  • a_rglob(pattern) (AsyncGenerator) Recursively yield all existing files matching the given pattern.</>
  • a_rmdir() Remove empty directory (async).</>
  • a_rmtree() Recursively remove directory and its contents (async).</>
  • a_stat(follow_symlinks) (stat_result) Get file stats (async).</>
  • a_symlink_to(target, target_is_directory) Asynchronously create a symbolic link pointing to target.</>
  • a_touch(mode, exist_ok) Create the file if it does not exist or update the modification time (async).</>
  • a_unlink(missing_ok) Delete file (async).</>
  • a_walk() (AsyncGenerator) Asynchronously walk the directory tree.</>
  • a_write_bytes(data) (int) Write bytes to file (async).</>
  • a_write_text(data, encoding) (int) Write text to file (async).</>
  • 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().</>
  • copy(target, follow_symlinks) (PanPath) Copy file to target.</>
  • copytree(target, follow_symlinks) (PanPath) Recursively copy the directory and all its contents to the target path.</>
  • 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) (PanPath) Rename the file or directory to target.</>
  • 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 empty directory.</>
  • rmtree() Recursively remove directory and its contents.</>
  • 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(*args, **kwargs) (Iterator) 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 like iterdir(). </>
  • 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.</>
staticmethod

__new__(cls, *args, **kwargs)PanPath

Create and return the appropriate path instance.

If called on a subclass, returns instance of that subclass. If called on PanPath itself, routes to the appropriate concrete class.

method

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().

method

__str__()

Return the string representation of the path, suitable forpassing to system calls.

method

as_posix()

Return the string representation of the path with forward (/)slashes.

method

__bytes__()

Return the bytes representation of the path. This is onlyrecommended to use under Unix.

method

as_uri()

Return the path as a 'file' URI.

method

with_name(name)

Return a new path with the file name changed.

method

with_stem(stem)

Return a new path with the stem changed.

method

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.

method

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.

method

is_relative_to(other, *_deprecated)

Return True if the path is relative to another path or False.

method

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).

method

is_absolute()

True if the path is absolute (has both a root and, if applicable,a drive).

method

is_reserved()

Return True if the path contains one of the special names reservedby the system, if any.

method

match(path_pattern, case_sensitive=None)

Return True if this path matches the given pattern.

method

stat(follow_symlinks=True)

Return the result of the stat() system call on this path, likeos.stat() does.

method

lstat()

Like stat(), except if the path points to a symlink, the symlink'sstatus information is returned, rather than its target's.

method

exists(follow_symlinks=True)

Whether this path exists.

This method normally follows symlinks; to check whether a symlink exists, add the argument follow_symlinks=False.

method

is_dir()

Whether this path is a directory.

method

is_file()

Whether this path is a regular file (also True for symlinks pointingto regular files).

method

is_mount()

Check if this path is a mount point

method

is_junction()

Whether this path is a junction.

method

is_block_device()

Whether this path is a block device.

method

is_char_device()

Whether this path is a character device.

method

is_fifo()

Whether this path is a FIFO.

method

is_socket()

Whether this path is a socket.

method

samefile(other_path)

Return whether other_path is the same or not as this file(as returned by os.path.samefile()).

method

open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)

Open the file pointed to by this path and return a file object, asthe built-in open() function does.

method

read_bytes()

Open the file in bytes mode, read it, and close the file.

method

read_text(encoding=None, errors=None)

Open the file in text mode, read it, and close the file.

method

write_bytes(data)

Open the file in bytes mode, write to it, and close the file.

method

write_text(data, encoding=None, errors=None, newline=None)

Open the file in text mode, write to it, and close the file.

generator

iterdir()

Yield path objects of the directory contents.

The children are yielded in arbitrary order, and the special entries '.' and '..' are not included.

generator

glob(pattern, case_sensitive=None)

Iterate over this subtree and yield all existing files (of anykind, including directories) matching the given relative pattern.

generator

rglob(pattern, case_sensitive=None)

Recursively yield all existing files (of any kind, includingdirectories) matching the given relative pattern, anywhere in this subtree.

classmethod

cwd()

Return a new path pointing to the current working directory.

classmethod

home()

Return a new path pointing to the user's home directory (asreturned by os.path.expanduser('~')).

method

absolute()

Return an absolute version of this path by prepending the currentworking directory. No normalization or symlink resolution is performed.

Use resolve() to get the canonical path to a file.

method

resolve(strict=False)

Make the path absolute, resolving all symlinks on the way and alsonormalizing it.

method

owner()

Return the login name of the file owner.

method

group()

Return the group name of the file gid.

method

touch(mode=438, exist_ok=True)

Create this file with the given access mode, if it doesn't exist.

method

mkdir(mode=511, parents=False, exist_ok=False)

Create a new directory at this given path.

method

chmod(mode, follow_symlinks=True)

Change the permissions of the path, like os.chmod().

method

lchmod(mode)

Like chmod(), except if the path points to a symlink, the symlink'spermissions are changed, rather than its target's.

method

replace(target)

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.

method

expanduser()

Return a new path with expanded ~ and ~user constructs(as returned by os.path.expanduser)

method

a_touch(mode=438, exist_ok=True)

Create the file if it does not exist or update the modification time (async).

Parameters
  • 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.
method

a_rename(target)

Rename the file or directory to target.

Parameters
  • target (Union) New path
Returns (PanPath)

New path instance

method

a_replace(target)

Rename the file or directory to target, overwriting if target exists.

Parameters
  • target (Union) New path
Returns (PanPath)

New path instance

method

a_resolve()

Resolve to absolute path (no-op for cloud paths).

Returns (PanPath)

Self (cloud paths are already absolute)

method

a_copy(target, follow_symlinks=True)

Copy file to target.

Can copy between cloud and local paths.

Parameters
  • target (Union) Destination path (can be cloud or local)
Returns (PanPath)

Target path instance

method

a_copytree(target, follow_symlinks=True)

Recursively copy the directory and all its contents to the target path.

Parameters
  • target (Union) Destination PanPath to copy to.
  • follow_symlinks (bool, optional) If True, copies the contents of symlinks.
Returns (PanPath)

The copied PanPath instance.

method

a_walk()

Asynchronously walk the directory tree.

Returns (AsyncGenerator)

A list of tuples (dirpath, dirnames, filenames)

method

a_glob(pattern)

Asynchronously yield paths matching the glob pattern.

Parameters
  • pattern (str) Glob pattern (relative)
Yields (AsyncGenerator)

Matching LocalPath instances

method

a_rglob(pattern)

Recursively yield all existing files matching the given pattern.

Parameters
  • pattern (str) Glob pattern (relative)
Yields (AsyncGenerator)

Matching LocalPath instances

method

a_exists() → bool

Check if path exists (async).

method

a_is_file() → bool

Check if path is a file (async).

method

a_is_dir() → bool

Check if path is a directory (async).

method

a_read_bytes() → bytes

Read file as bytes (async).

method

a_read_text(encoding='utf-8') → str

Read file as text (async).

Parameters
  • encoding (str, optional) Text encoding to use (default: 'utf-8')
method

a_write_bytes(data) → int

Write bytes to file (async).

Parameters
  • data (bytes) Bytes to write to the file.
method

a_write_text(data, encoding='utf-8') → int

Write text to file (async).

Parameters
  • data (str) Text to write to the file.
  • encoding (str, optional) Text encoding to use (default: 'utf-8')
method

a_mkdir(mode=511, parents=False, exist_ok=False)

Create directory (async).

Parameters
  • 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.
method

a_rmdir()

Remove empty directory (async).

method

a_rmtree()

Recursively remove directory and its contents (async).

method

a_iterdir() → AsyncGenerator

List directory contents (async).

method

a_stat(follow_symlinks=True) → stat_result

Get file stats (async).

method

a_open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)

Open file and return async file handle.

Parameters
  • mode (str, optional) Mode to open the file (e.g., 'r', 'rb', 'w', 'wb').
  • encoding (Optional, optional) Text encoding to use (default: 'utf-8').
Returns (Any)

Async file handle from aiofiles

method

rename(target)

Rename the file or directory to target.

Parameters
  • target (Union) New path
Returns (PanPath)

New path instance

method

copy(target, follow_symlinks=True)

Copy file to target.

Can copy between cloud and local paths.

Parameters
  • target (Union) Destination path (can be cloud or local)
  • follow_symlinks (bool, optional) If True, follow symbolic links
Returns (PanPath)

Target path instance

method

copytree(target, follow_symlinks=True)

Recursively copy the directory and all its contents to the target path.

Parameters
  • target (Union) Destination PanPath to copy to.
  • follow_symlinks (bool, optional) If True, copies the contents of symlinks.
Returns (PanPath)

The copied PanPath instance.

method

rmdir()

Remove empty directory.

method

rmtree()

Recursively remove directory and its contents.

generator

walk(*args, **kwargs)

Walk the directory tree.

Returns (Iterator)

A list of tuples (dirpath, dirnames, filenames)