panpath.gs_client
Google Cloud Storage client implementation.
GSClient— Synchronous Google Cloud Storage client implementation.</>GSSyncFileHandle— Sync file handle for GCS with chunked streaming support.</>
panpath.gs_client.GSClient(**kwargs)
Synchronous Google Cloud Storage client implementation.
copy(source,target,follow_symlinks)— Copy file to target.</>copytree(source,target,follow_symlinks)— Copy directory tree to target recursively.</>delete(path)— Delete GCS blob.</>exists(path)(bool) — Check if GCS blob exists.</>get_metadata(path)(dict) — Get blob metadata.</>glob(path,pattern)(Iterator) — Glob for files matching pattern.</>is_dir(path)(bool) — Check if GCS path is a directory (has blobs with prefix).</>is_file(path)(bool) — Check if GCS path is a file.</>is_symlink(path)(bool) — Check if blob is a symlink (has symlink_target metadata).</>list_dir(path)(list) — List GCS blobs with prefix.</>mkdir(path,parents,exist_ok)— Create a directory marker (empty blob with trailing slash).</>open(path,mode,encoding,**kwargs)(Any) — Open GCS blob for reading/writing with streaming support.</>read_bytes(path)(bytes) — Read GCS blob as bytes.</>read_text(path,encoding)(str) — Read file as text.</>readlink(path)(str) — Read symlink target from metadata.</>rename(source,target)— 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 blob metadata.</>stat(path)(Any) — Get GCS blob metadata.</>symlink_to(path,target)— Create symlink by storing target in metadata.</>touch(path,exist_ok)— Create empty file.</>walk(path)(Iterator) — Walk directory tree.</>write_bytes(path,data)— Write bytes to GCS blob.</>write_text(path,data,encoding)— Write text to file.</>
read_text(path, encoding='utf-8') → str
Read file as text.
write_text(path, data, encoding='utf-8')
Write text to file.
exists(path) → bool
Check if GCS blob exists.
read_bytes(path) → bytes
Read GCS blob as bytes.
write_bytes(path, data)
Write bytes to GCS blob.
delete(path)
Delete GCS blob.
list_dir(path) → list
List GCS blobs with prefix.
is_dir(path) → bool
Check if GCS path is a directory (has blobs with prefix).
is_file(path) → bool
Check if GCS path is a file.
stat(path) → Any
Get GCS blob metadata.
open(path, mode='r', encoding=None, **kwargs)
Open GCS blob for reading/writing with streaming support.
path(str) — GCS path (gs://bucket/blob)mode(str, optional) — File mode ('r', 'w', 'rb', 'wb', 'a', 'ab')encoding(Optional, optional) — Text encoding (for text modes)**kwargs(Any) — Additional arguments (chunk_size, upload_warning_threshold,upload_interval supported)
GSSyncFileHandle with streaming support
mkdir(path, parents=False, exist_ok=False)
Create a directory marker (empty blob with trailing slash).
path(str) — GCS path (gs://bucket/path)parents(bool, optional) — If True, create parent directories as needed (ignored for GCS)exist_ok(bool, optional) — If True, don't raise error if directory already exists
get_metadata(path)
Get blob metadata.
path(str) — GCS path
Dictionary of metadata key-value pairs
set_metadata(path, metadata)
Set blob metadata.
path(str) — GCS pathmetadata(dict) — Dictionary of metadata key-value pairs
symlink_to(path, target)
Create symlink by storing target in metadata.
path(str) — GCS path for the symlinktarget(str) — Target path the symlink should point to
is_symlink(path)
Check if blob is a symlink (has symlink_target metadata).
path(str) — GCS path
True if symlink metadata exists
readlink(path)
Read symlink target from metadata.
path(str) — GCS path
Symlink target path
glob(path, pattern)
Glob for files matching pattern.
path(str) — Base GCS pathpattern(str) — Glob pattern (e.g., ".txt", "**/.py")
List of matching paths (as PanPath objects or strings)
walk(path)
Walk directory tree.
path(str) — Base GCS path
List of (dirpath, dirnames, filenames) tuples
touch(path, exist_ok=True)
Create empty file.
path(str) — GCS pathexist_ok(bool, optional) — If False, raise error if file exists
rename(source, target)
Rename/move file.
source(str) — Source GCS pathtarget(str) — Target GCS path
rmdir(path)
Remove directory marker.
path(str) — GCS path
rmtree(path, ignore_errors=False, onerror=None)
Remove directory and all its contents recursively.
path(str) — GCS pathignore_errors(bool, optional) — If True, errors are ignoredonerror(Optional, optional) — Callable that accepts (function, path, excinfo)
copy(source, target, follow_symlinks=True)
Copy file to target.
source(str) — Source GCS pathtarget(str) — Target GCS pathfollow_symlinks(bool, optional) — If False, symlinks are copied as symlinks (not dereferenced)
copytree(source, target, follow_symlinks=True)
Copy directory tree to target recursively.
source(str) — Source GCS pathtarget(str) — Target GCS pathfollow_symlinks(bool, optional) — If False, symlinks are copied as symlinks (not dereferenced)
panpath.gs_client.GSSyncFileHandle(*args, **kwargs)
Sync file handle for GCS with chunked streaming support.
Uses google-cloud-storage's streaming API for efficient reading of large files.
closed(bool) — Check if file is closed.</>
__del__()— Destructor to ensure stream is closed.</>__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 streaming reader/writer.</>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.</>
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.
__enter__() → SyncFileHandle
Enter context manager.
__exit__(exc_type, exc_val, exc_tb)
Exit async context manager.
read(size=-1)
Read and return up to size bytes/characters.
size(int, optional) — Number of bytes/chars to read (-1 for all)
Data read from file
readline(size=-1) → Union
Read and return one line from the file.
readlines() → List
Read and return all lines from the file.
write(data) → int
Write data to the file.
writelines(lines)
Write a list of lines to the file.
close()
Close the file and flush write buffer to cloud storage.
__iter__() → SyncFileHandle
Support async iteration over lines.
__next__() → Union
Get next line in async iteration.
tell()
Return current stream position.
Current position in the file
seek(offset, whence=0)
Change stream position (forward seeking only).
offset(int) — Position offsetwhence(int, optional) — Reference point (0=start, 1=current, 2=end)
New absolute position
OSError— If backward seeking is attemptedValueError— 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
reset_stream()
Reset streaming reader/writer.
__del__()
Destructor to ensure stream is closed.