Skip to content
module

panpath.clients

Base client classes for sync and async cloud storage operations.

Classes
  • Client() Base class for cloud storage clients.</>
  • SyncClient() Base class for synchronous cloud storage clients.</>
  • AsyncClient() Base class for asynchronous cloud storage clients.</>
  • AsyncFileHandle(client_factory, bucket, blob, prefix, mode, encoding, chunk_size, upload_warning_threshold, upload_interval) Base class for async file handles.</>
  • SyncFileHandle(client, bucket, blob, prefix, mode, encoding, chunk_size, upload_warning_threshold, upload_interval) Base class for sync file handles.</>
abstract class

panpath.clients.Client()

Base class for cloud storage clients.

Methods
  • open(path, mode, encoding, **kwargs) (Union) Open file and return sync/async file handle.</>
abstract method

open(path, mode='r', encoding=None, **kwargs)

Open file and return sync/async file handle.

Parameters
  • path (str) Cloud storage path
  • mode (str, optional) File mode ('r', 'w', 'rb', 'wb', 'a', 'ab')
  • encoding (Optional, optional) Text encoding (for text modes)
  • **kwargs (Any) Additional arguments for specific implementations
Returns (Union)

SyncFileHandle/AsyncFileHandle instance

abstract class

panpath.clients.SyncClient()

Base class for synchronous cloud storage clients.

Methods
  • copy(src, dst, follow_symlinks) Copy file from src to dst.</>
  • copytree(src, dst, follow_symlinks) Copy directory tree from src to dst recursively.</>
  • delete(path) Delete file.</>
  • exists(path) (bool) Check if path exists.</>
  • get_metadata(path) (dict) Get object metadata.</>
  • glob(path, pattern) (Iterator) Find all paths matching pattern.</>
  • is_dir(path) (bool) Check if path is a directory.</>
  • is_file(path) (bool) Check if path is a file.</>
  • is_symlink(path) (bool) Check if path is a symlink (has symlink metadata).</>
  • list_dir(path) (Iterator) List directory contents.</>
  • mkdir(path, parents, exist_ok) Create a directory marker (empty blob with trailing slash).</>
  • open(path, mode, encoding, **kwargs) (Union) Open file and return sync/async file handle.</>
  • read_bytes(path) (bytes) Read file as bytes.</>
  • read_text(path, encoding) (str) Read file as text.</>
  • readlink(path) (str) Read symlink target from metadata.</>
  • rename(src, dst) Rename/move file.</>
  • rmdir(path) Remove directory marker.</>
  • rmtree(path, ignore_errors, onerror) Remove directory and all its contents recursively.</>
  • set_metadata(path, metadata) Set object metadata.</>
  • stat(path) (Any) Get file stats.</>
  • symlink_to(path, target) Create symlink by storing target in metadata.</>
  • touch(path, exist_ok) Create empty file or update metadata.</>
  • walk(path) (Iterator) Walk directory tree.</>
  • write_bytes(path, data) Write bytes to file.</>
  • write_text(path, data, encoding) Write text to file.</>
abstract method

open(path, mode='r', encoding=None, **kwargs)

Open file and return sync/async file handle.

Parameters
  • path (str) Cloud storage path
  • mode (str, optional) File mode ('r', 'w', 'rb', 'wb', 'a', 'ab')
  • encoding (Optional, optional) Text encoding (for text modes)
  • **kwargs (Any) Additional arguments for specific implementations
Returns (Union)

SyncFileHandle/AsyncFileHandle instance

abstract method

exists(path) → bool

Check if path exists.

abstract method

read_bytes(path) → bytes

Read file as bytes.

abstract method

write_bytes(path, data)

Write bytes to file.

abstract method

delete(path)

Delete file.

abstract method

list_dir(path) → Iterator

List directory contents.

abstract method

is_dir(path) → bool

Check if path is a directory.

abstract method

is_file(path) → bool

Check if path is a file.

abstract method

stat(path) → Any

Get file stats.

abstract method

mkdir(path, parents=False, exist_ok=False)

Create a directory marker (empty blob with trailing slash).

abstract method

glob(path, pattern) → Iterator

Find all paths matching pattern.

abstract method

walk(path) → Iterator

Walk directory tree.

abstract method

touch(path, exist_ok=True)

Create empty file or update metadata.

abstract method

rename(src, dst)

Rename/move file.

abstract method

rmdir(path)

Remove directory marker.

abstract method

get_metadata(path) → dict

Get object metadata.

abstract method

set_metadata(path, metadata)

Set object metadata.

abstract method

rmtree(path, ignore_errors=False, onerror=None)

Remove directory and all its contents recursively.

abstract method

copy(src, dst, follow_symlinks=True)

Copy file from src to dst.

abstract method

copytree(src, dst, follow_symlinks=True)

Copy directory tree from src to dst recursively.

method

read_text(path, encoding='utf-8') → str

Read file as text.

method

write_text(path, data, encoding='utf-8')

Write text to file.

abstract class

panpath.clients.AsyncClient()

Base class for asynchronous cloud storage clients.

Methods
  • __aenter__() (AsyncClient) Enter async context manager.</>
  • __aexit__(exc_type, exc_val, exc_tb) Exit async context manager.</>
  • close() Close any open connections/resources.</>
  • copy(src, dst, follow_symlinks) Copy file from src to dst.</>
  • copytree(src, dst, follow_symlinks) Copy directory tree from src to dst recursively.</>
  • delete(path) Delete file.</>
  • exists(path) (bool) Check if path exists.</>
  • get_metadata(path) (dict) Get object metadata.</>
  • glob(path, pattern) (AsyncGenerator) Find all paths matching pattern.</>
  • is_dir(path) (bool) Check if path is a directory.</>
  • is_file(path) (bool) Check if path is a file.</>
  • is_symlink(path) (bool) Check if path is a symlink (has symlink metadata).</>
  • list_dir(path) (list) List directory contents.</>
  • mkdir(path, parents, exist_ok) Create a directory marker (empty blob with trailing slash).</>
  • open(path, mode, encoding, **kwargs) (Union) Open file and return sync/async file handle.</>
  • read_bytes(path) (bytes) Read file as bytes.</>
  • read_text(path, encoding) (str) Read Azure blob as text.</>
  • readlink(path) (str) Read symlink target from metadata.</>
  • rename(src, dst) Rename/move file.</>
  • rmdir(path) Remove directory marker.</>
  • rmtree(path, ignore_errors, onerror) Remove directory and all its contents recursively.</>
  • set_metadata(path, metadata) Set object metadata.</>
  • stat(path) (Any) Get file stats.</>
  • symlink_to(path, target) Create symlink by storing target in metadata.</>
  • touch(path, exist_ok) Create empty file or update metadata.</>
  • walk(path) (AsyncGenerator) Walk directory tree.</>
  • write_bytes(path, data) (int) Write bytes to file.</>
  • write_text(path, data, encoding) (int) Write text to Azure blob.</>
abstract method

open(path, mode='r', encoding=None, **kwargs)

Open file and return sync/async file handle.

Parameters
  • path (str) Cloud storage path
  • mode (str, optional) File mode ('r', 'w', 'rb', 'wb', 'a', 'ab')
  • encoding (Optional, optional) Text encoding (for text modes)
  • **kwargs (Any) Additional arguments for specific implementations
Returns (Union)

SyncFileHandle/AsyncFileHandle instance

abstract method

close()

Close any open connections/resources.

abstract method

exists(path) → bool

Check if path exists.

abstract method

read_bytes(path) → bytes

Read file as bytes.

abstract method

write_bytes(path, data) → int

Write bytes to file.

abstract method

delete(path)

Delete file.

abstract method

list_dir(path) → list

List directory contents.

abstract method

is_dir(path) → bool

Check if path is a directory.

abstract method

is_file(path) → bool

Check if path is a file.

abstract method

stat(path) → Any

Get file stats.

abstract method

mkdir(path, parents=False, exist_ok=False)

Create a directory marker (empty blob with trailing slash).

abstract method

glob(path, pattern) → AsyncGenerator

Find all paths matching pattern.

abstract method

walk(path) → AsyncGenerator

Walk directory tree.

abstract method

touch(path, exist_ok=True)

Create empty file or update metadata.

abstract method

rename(src, dst)

Rename/move file.

abstract method

rmdir(path)

Remove directory marker.

abstract method

get_metadata(path) → dict

Get object metadata.

abstract method

set_metadata(path, metadata)

Set object metadata.

abstract method

rmtree(path, ignore_errors=False, onerror=None)

Remove directory and all its contents recursively.

abstract method

copy(src, dst, follow_symlinks=True)

Copy file from src to dst.

abstract method

copytree(src, dst, follow_symlinks=True)

Copy directory tree from src to dst recursively.

method

__aenter__()AsyncClient

Enter async context manager.

method

__aexit__(exc_type, exc_val, exc_tb)

Exit async context manager.

method

read_text(path, encoding='utf-8') → str

Read Azure blob as text.

method

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

Write text to Azure blob.

abstract class

panpath.clients.AsyncFileHandle(client_factory, bucket, blob, prefix, mode='r', encoding=None, chunk_size=4096, upload_warning_threshold=100, upload_interval=1.0)

Base class for async file handles.

This abstract base class defines the interface for async file operations on cloud storage. Each cloud provider implements its own version using the provider's specific streaming capabilities.

Attributes
  • closed (bool) Check if file is closed.</>
Methods
  • __aenter__() (AsyncFileHandle) Enter async context manager.</>
  • __aexit__(exc_type, exc_val, exc_tb) Exit async context manager.</>
  • __aiter__() (AsyncFileHandle) Support async iteration over lines.</>
  • __anext__() (Union) Get next line in async iteration.</>
  • close() Close the file and flush write buffer to cloud storage.</>
  • flush() Flush write buffer to cloud storage.</>
  • read(size) (Union) Read and return up to size bytes/characters.</>
  • readline(size) (Union) Read and return one line from the file.</>
  • readlines() (List) Read and return all lines from the file.</>
  • reset_stream() Reset the underlying stream to the beginning.</>
  • seek(offset, whence) (int) Change stream position (forward seeking only).</>
  • tell() (int) Return current stream position.</>
  • write(data) (int) Write data to the file.</>
  • writelines(lines) Write a list of lines to the file.</>
method

flush()

Flush write buffer to cloud storage.

After open, all flushes append to existing content using provider-native append operations. The difference between 'w' and 'a' modes is that 'w' clears existing content on open, while 'a' preserves it.

method

reset_stream()

Reset the underlying stream to the beginning.

method

__aenter__()AsyncFileHandle

Enter async context manager.

method

__aexit__(exc_type, exc_val, exc_tb)

Exit async context manager.

method

read(size=-1)

Read and return up to size bytes/characters.

Parameters
  • size (int, optional) Number of bytes/chars to read (-1 for all)
Returns (Union)

Data read from file

method

readline(size=-1) → Union

Read and return one line from the file.

method

readlines() → List

Read and return all lines from the file.

method

write(data) → int

Write data to the file.

method

writelines(lines)

Write a list of lines to the file.

method

close()

Close the file and flush write buffer to cloud storage.

method

__aiter__()AsyncFileHandle

Support async iteration over lines.

method

__anext__() → Union

Get next line in async iteration.

method

tell()

Return current stream position.

Returns (int)

Current position in the file

method

seek(offset, whence=0)

Change stream position (forward seeking only).

Parameters
  • offset (int) Position offset
  • whence (int, optional) Reference point (0=start, 1=current, 2=end)
Returns (int)

New absolute position

Raises
  • OSError If backward seeking is attempted
  • ValueError If called in write mode or on closed file

Note

  • Only forward seeking is supported due to streaming limitations
  • SEEK_END (whence=2) is not supported as blob size may be unknown
  • Backward seeking requires re-opening the stream
abstract class

panpath.clients.SyncFileHandle(client, bucket, blob, prefix, mode='r', encoding=None, chunk_size=4096, upload_warning_threshold=100, upload_interval=1.0)

Base class for sync file handles.

This abstract base class defines the interface for sync file operations on cloud storage. Each cloud provider implements its own version using the provider's specific streaming capabilities.

Attributes
  • closed (bool) Check if file is closed.</>
Methods
  • __enter__() (SyncFileHandle) Enter context manager.</>
  • __exit__(exc_type, exc_val, exc_tb) Exit async context manager.</>
  • __iter__() (SyncFileHandle) Support async iteration over lines.</>
  • __next__() (Union) Get next line in async iteration.</>
  • close() Close the file and flush write buffer to cloud storage.</>
  • flush() Flush write buffer to cloud storage.</>
  • read(size) (Union) Read and return up to size bytes/characters.</>
  • readline(size) (Union) Read and return one line from the file.</>
  • readlines() (List) Read and return all lines from the file.</>
  • reset_stream() Reset the underlying stream to the beginning.</>
  • seek(offset, whence) (int) Change stream position (forward seeking only).</>
  • tell() (int) Return current stream position.</>
  • write(data) (int) Write data to the file.</>
  • writelines(lines) Write a list of lines to the file.</>
method

flush()

Flush write buffer to cloud storage.

After open, all flushes append to existing content using provider-native append operations. The difference between 'w' and 'a' modes is that 'w' clears existing content on open, while 'a' preserves it.

method

reset_stream()

Reset the underlying stream to the beginning.

method

__enter__()SyncFileHandle

Enter context manager.

method

__exit__(exc_type, exc_val, exc_tb)

Exit async context manager.

method

read(size=-1)

Read and return up to size bytes/characters.

Parameters
  • size (int, optional) Number of bytes/chars to read (-1 for all)
Returns (Union)

Data read from file

method

readline(size=-1) → Union

Read and return one line from the file.

method

readlines() → List

Read and return all lines from the file.

method

write(data) → int

Write data to the file.

method

writelines(lines)

Write a list of lines to the file.

method

close()

Close the file and flush write buffer to cloud storage.

method

__iter__()SyncFileHandle

Support async iteration over lines.

method

__next__() → Union

Get next line in async iteration.

method

tell()

Return current stream position.

Returns (int)

Current position in the file

method

seek(offset, whence=0)

Change stream position (forward seeking only).

Parameters
  • offset (int) Position offset
  • whence (int, optional) Reference point (0=start, 1=current, 2=end)
Returns (int)

New absolute position

Raises
  • OSError If backward seeking is attempted
  • ValueError If called in write mode or on closed file

Note

  • Only forward seeking is supported due to streaming limitations
  • SEEK_END (whence=2) is not supported as blob size may be unknown
  • Backward seeking requires re-opening the stream