gravitino.filesystem.gvfs.GravitinoVirtualFileSystem

class gravitino.filesystem.gvfs.GravitinoVirtualFileSystem(*args, **kwargs)

Bases: AbstractFileSystem

This is a virtual file system that users can access fileset and other resources.

It obtains the actual storage location corresponding to the resource from the Gravitino server, and creates an independent file system for it to act as an agent for users to access the underlying storage.

__init__(server_uri: str | None = None, metalake_name: str | None = None, options: Dict | None = None, **kwargs)

Initialize the GravitinoVirtualFileSystem. :param server_uri: Gravitino server URI :param metalake_name: Gravitino metalake name :param options: Options for the GravitinoVirtualFileSystem :param kwargs: Extra args for super filesystem

Methods

__init__([server_uri, metalake_name, options])

Initialize the GravitinoVirtualFileSystem.

cat(path[, recursive, on_error])

Fetch (potentially multiple) paths' contents

cat_file(path[, start, end])

Get the content of a file.

cat_ranges(paths, starts, ends[, max_gap, ...])

Get the contents of byte ranges from one or more files

checksum(path)

Unique value for current version of file

clear_instance_cache()

Clear the cache of filesystem instances.

copy(path1, path2[, recursive, maxdepth, ...])

Copy within two locations in the filesystem

cp(path1, path2, **kwargs)

Alias of AbstractFileSystem.copy.

cp_file(path1, path2, **kwargs)

Copy a file.

created(path)

Return the created timestamp of a file as a datetime.datetime Only supports for fsspec.LocalFileSystem now.

current()

Return the most recently instantiated FileSystem

delete(path[, recursive, maxdepth])

Alias of AbstractFileSystem.rm.

disk_usage(path[, total, maxdepth])

Alias of AbstractFileSystem.du.

download(rpath, lpath[, recursive])

Alias of AbstractFileSystem.get.

du(path[, total, maxdepth, withdirs])

Space used by files and optionally directories within a path

end_transaction()

Finish write transaction, non-context version

exists(path, **kwargs)

Check if a file or a directory exists.

expand_path(path[, recursive, maxdepth])

Turn one or more globs or directories into a list of all matching paths to files or directories.

find(path[, maxdepth, withdirs, detail])

List all files below path.

from_json(blob)

Recreate a filesystem instance from JSON representation

get(rpath, lpath[, recursive, callback, ...])

Copy file(s) to local.

get_file(rpath, lpath[, callback, outfile])

Copy single remote file to local.

get_mapper([root, check, create, ...])

Create key/value store based on this file-system

glob(path[, maxdepth])

Find files by glob-matching.

head(path[, size])

Get the first size bytes from file

info(path, **kwargs)

Get file info.

invalidate_cache([path])

Discard any cached directory information

isdir(path)

Is this entry directory-like?

isfile(path)

Is this entry file-like?

lazy_load_class(module_name, class_name)

lexists(path, **kwargs)

If there is a file at the given path (including broken links)

listdir(path[, detail])

Alias of AbstractFileSystem.ls.

ls(path[, detail])

List the files and directories info of the path.

makedir(path[, create_parents])

Alias of AbstractFileSystem.mkdir.

makedirs(path[, exist_ok])

Make a directory recursively.

mkdir(path[, create_parents])

Make a directory.

mkdirs(path[, exist_ok])

Alias of AbstractFileSystem.makedirs.

modified(path)

Returns the modified time of the path file if it exists.

move(path1, path2, **kwargs)

Alias of AbstractFileSystem.mv.

mv(path1, path2[, recursive, maxdepth])

Move a file to another directory.

open(path[, mode, block_size, ...])

Open a file to read/write/append.

pipe(path[, value])

Put value into path

pipe_file(path, value, **kwargs)

Set the bytes of given file

put(lpath, rpath[, recursive, callback, ...])

Copy file(s) from local.

put_file(lpath, rpath[, callback])

Copy single file to remote

read_block(fn, offset, length[, delimiter])

Read a block of bytes from

read_bytes(path[, start, end])

Alias of AbstractFileSystem.cat_file.

read_text(path[, encoding, errors, newline])

Get the contents of the file as a string.

rename(path1, path2, **kwargs)

Alias of AbstractFileSystem.mv.

rm(path[, recursive, maxdepth])

Remove a file or directory. :param path: Virtual fileset path :param recursive: Whether to remove the directory recursively. When removing a directory, this parameter should be True. :param maxdepth: The maximum depth to remove the directory recursively.

rm_file(path)

Remove a file.

rmdir(path)

Remove a directory.

sign(path[, expiration])

We do not support to create a signed URL representing the given path in gvfs.

size(path)

Size in bytes of file

sizes(paths)

Size in bytes of each file in a list of paths

start_transaction()

Begin write transaction for deferring files, non-context version

stat(path, **kwargs)

Alias of AbstractFileSystem.info.

tail(path[, size])

Get the last size bytes from file

to_json()

JSON representation of this filesystem instance

touch(path[, truncate])

Create empty file, or update timestamp

ukey(path)

Hash of file properties, to tell if it has changed

unstrip_protocol(name)

Format FS-specific path to generic, including protocol

upload(lpath, rpath[, recursive])

Alias of AbstractFileSystem.put.

walk(path[, maxdepth, topdown, on_error])

Return all files belows path

write_bytes(path, value, **kwargs)

Alias of AbstractFileSystem.pipe_file.

write_text(path, value[, encoding, errors, ...])

Write the text to the given file.

Attributes

SLASH

async_impl

blocksize

cachable

cache

fsid

Persistent filesystem id that can be used to compare filesystems across sessions.

mirror_sync_methods

protocol

root_marker

sep

transaction

A context within which files are committed together upon exit

cat(path, recursive=False, on_error='raise', **kwargs)

Fetch (potentially multiple) paths’ contents

Parameters

recursive: bool

If True, assume the path(s) are directories, and get all the contained files

on_error“raise”, “omit”, “return”

If raise, an underlying exception will be raised (converted to KeyError if the type is in self.missing_exceptions); if omit, keys with exception will simply not be included in the output; if “return”, all keys are included in the output, but the value will be bytes or an exception instance.

kwargs: passed to cat_file

Returns

dict of {path: contents} if there are multiple paths or the path has been otherwise expanded

cat_file(path, start=None, end=None, **kwargs)

Get the content of a file. :param path: Virtual fileset path :param start: The offset in bytes to start reading from. It can be None. :param end: The offset in bytes to end reading at. It can be None. :param kwargs: Extra args :return File content

cat_ranges(paths, starts, ends, max_gap=None, on_error='return', **kwargs)

Get the contents of byte ranges from one or more files

Parameters

paths: list

A list of of filepaths on this filesystems

starts, ends: int or list

Bytes limits of the read. If using a single int, the same value will be used to read all the specified files.

checksum(path)

Unique value for current version of file

If the checksum is the same from one moment to another, the contents are guaranteed to be the same. If the checksum changes, the contents might have changed.

This should normally be overridden; default will probably capture creation/modification timestamp (which would be good) or maybe access timestamp (which would be bad)

classmethod clear_instance_cache()

Clear the cache of filesystem instances.

Notes

Unless overridden by setting the cachable class attribute to False, the filesystem class stores a reference to newly created instances. This prevents Python’s normal rules around garbage collection from working, since the instances refcount will not drop to zero until clear_instance_cache is called.

copy(path1, path2, recursive=False, maxdepth=None, on_error=None, **kwargs)

Copy within two locations in the filesystem

on_error“raise”, “ignore”

If raise, any not-found exceptions will be raised; if ignore any not-found exceptions will cause the path to be skipped; defaults to raise unless recursive is true, where the default is ignore

cp(path1, path2, **kwargs)

Alias of AbstractFileSystem.copy.

cp_file(path1, path2, **kwargs)

Copy a file. :param path1: Virtual src fileset path :param path2: Virtual dst fileset path, should be consistent with the src path fileset identifier :param kwargs: Extra args

created(path)

Return the created timestamp of a file as a datetime.datetime Only supports for fsspec.LocalFileSystem now. :param path: Virtual fileset path :return Created time(datetime.datetime)

classmethod current()

Return the most recently instantiated FileSystem

If no instance has been created, then create one with defaults

delete(path, recursive=False, maxdepth=None)

Alias of AbstractFileSystem.rm.

disk_usage(path, total=True, maxdepth=None, **kwargs)

Alias of AbstractFileSystem.du.

download(rpath, lpath, recursive=False, **kwargs)

Alias of AbstractFileSystem.get.

du(path, total=True, maxdepth=None, withdirs=False, **kwargs)

Space used by files and optionally directories within a path

Directory size does not include the size of its contents.

Parameters

path: str total: bool

Whether to sum all the file sizes

maxdepth: int or None

Maximum number of directory levels to descend, None for unlimited.

withdirs: bool

Whether to include directory paths in the output.

kwargs: passed to find

Returns

Dict of {path: size} if total=False, or int otherwise, where numbers refer to bytes used.

end_transaction()

Finish write transaction, non-context version

exists(path, **kwargs)

Check if a file or a directory exists. :param path: Virtual fileset path :param kwargs: Extra args :return If a file or directory exists, it returns True, otherwise False

expand_path(path, recursive=False, maxdepth=None, **kwargs)

Turn one or more globs or directories into a list of all matching paths to files or directories.

kwargs are passed to glob or find, which may in turn call ls

find(path, maxdepth=None, withdirs=False, detail=False, **kwargs)

List all files below path.

Like posix find command without conditions

Parameters

path : str maxdepth: int or None

If not None, the maximum number of levels to descend

withdirs: bool

Whether to include directory paths in the output. This is True when used by glob, but users usually only want files.

kwargs are passed to ls.

static from_json(blob)

Recreate a filesystem instance from JSON representation

See .to_json() for the expected structure of the input

Parameters

blob: str

Returns

file system instance, not necessarily of this particular class.

property fsid

Persistent filesystem id that can be used to compare filesystems across sessions.

get(rpath, lpath, recursive=False, callback=<fsspec.callbacks.NoOpCallback object>, maxdepth=None, **kwargs)

Copy file(s) to local.

Copies a specific file or tree of files (if recursive=True). If lpath ends with a “/”, it will be assumed to be a directory, and target files will go within. Can submit a list of paths, which may be glob-patterns and will be expanded.

Calls get_file for each source.

get_file(rpath, lpath, callback=None, outfile=None, **kwargs)

Copy single remote file to local. :param rpath: Remote file path :param lpath: Local file path :param callback: The callback class :param outfile: The output file path :param kwargs: Extra args

get_mapper(root='', check=False, create=False, missing_exceptions=None)

Create key/value store based on this file-system

Makes a MutableMapping interface to the FS at the given root path. See fsspec.mapping.FSMap for further details.

glob(path, maxdepth=None, **kwargs)

Find files by glob-matching.

If the path ends with ‘/’, only folders are returned.

We support "**", "?" and "[..]". We do not support ^ for pattern negation.

The maxdepth option is applied on the first ** found in the path.

kwargs are passed to ls.

head(path, size=1024)

Get the first size bytes from file

info(path, **kwargs)

Get file info. :param path: Virtual fileset path :param kwargs: Extra args :return A file info dict

invalidate_cache(path=None)

Discard any cached directory information

Parameters

path: string or None

If None, clear all listings cached else listings at or under given path.

isdir(path)

Is this entry directory-like?

isfile(path)

Is this entry file-like?

lexists(path, **kwargs)

If there is a file at the given path (including broken links)

listdir(path, detail=True, **kwargs)

Alias of AbstractFileSystem.ls.

ls(path, detail=True, **kwargs)

List the files and directories info of the path. :param path: Virtual fileset path :param detail: Whether to show the details for the files and directories info :param kwargs: Extra args :return If details is true, returns a list of file info dicts, else returns a list of file paths

makedir(path, create_parents=True, **kwargs)

Alias of AbstractFileSystem.mkdir.

makedirs(path, exist_ok=True)

Make a directory recursively. :param path: Virtual fileset path :param exist_ok: Continue if a directory already exists

mkdir(path, create_parents=True, **kwargs)

Make a directory. if create_parents=True, this is equivalent to makedirs.

Parameters:
  • path – Virtual fileset path

  • create_parents – Create parent directories if missing when set to True

  • kwargs – Extra args

mkdirs(path, exist_ok=False)

Alias of AbstractFileSystem.makedirs.

modified(path)

Returns the modified time of the path file if it exists. :param path: Virtual fileset path :return Modified time(datetime.datetime)

move(path1, path2, **kwargs)

Alias of AbstractFileSystem.mv.

mv(path1, path2, recursive=False, maxdepth=None, **kwargs)
Move a file to another directory.

This can move a file to another existing directory. If the target path directory does not exist, an exception will be thrown.

Parameters:
  • path1 – Virtual src fileset path

  • path2 – Virtual dst fileset path, should be consistent with the src path fileset identifier

  • recursive – Whether to move recursively

  • maxdepth – Maximum depth of recursive move

  • kwargs – Extra args

open(path, mode='rb', block_size=None, cache_options=None, compression=None, **kwargs)

Open a file to read/write/append. :param path: Virtual fileset path :param mode: The mode now supports: rb(read), wb(write), ab(append). See builtin open() :param block_size: Some indication of buffering - this is a value in bytes :param cache_options: Extra arguments to pass through to the cache :param compression: If given, open file using compression codec :param kwargs: Extra args :return A file-like object from the filesystem

pipe(path, value=None, **kwargs)

Put value into path

(counterpart to cat)

Parameters

path: string or dict(str, bytes)

If a string, a single remote location to put value bytes; if a dict, a mapping of {path: bytesvalue}.

value: bytes, optional

If using a single path, these are the bytes to put there. Ignored if path is a dict

pipe_file(path, value, **kwargs)

Set the bytes of given file

put(lpath, rpath, recursive=False, callback=<fsspec.callbacks.NoOpCallback object>, maxdepth=None, **kwargs)

Copy file(s) from local.

Copies a specific file or tree of files (if recursive=True). If rpath ends with a “/”, it will be assumed to be a directory, and target files will go within.

Calls put_file for each source.

put_file(lpath, rpath, callback=<fsspec.callbacks.NoOpCallback object>, **kwargs)

Copy single file to remote

read_block(fn, offset, length, delimiter=None)

Read a block of bytes from

Starting at offset of the file, read length bytes. If delimiter is set then we ensure that the read starts and stops at delimiter boundaries that follow the locations offset and offset + length. If offset is zero then we start at zero. The bytestring returned WILL include the end delimiter string.

If offset+length is beyond the eof, reads to eof.

Parameters

fn: string

Path to filename

offset: int

Byte offset to start read

length: int

Number of bytes to read. If None, read to end.

delimiter: bytes (optional)

Ensure reading starts and stops at delimiter bytestring

Examples

>>> fs.read_block('data/file.csv', 0, 13)  
b'Alice, 100\nBo'
>>> fs.read_block('data/file.csv', 0, 13, delimiter=b'\n')  
b'Alice, 100\nBob, 200\n'

Use length=None to read to the end of the file. >>> fs.read_block(‘data/file.csv’, 0, None, delimiter=b’n’) # doctest: +SKIP b’Alice, 100nBob, 200nCharlie, 300’

See Also

fsspec.utils.read_block()

read_bytes(path, start=None, end=None, **kwargs)

Alias of AbstractFileSystem.cat_file.

read_text(path, encoding=None, errors=None, newline=None, **kwargs)

Get the contents of the file as a string.

Parameters

path: str

URL of file on this filesystems

encoding, errors, newline: same as open.

rename(path1, path2, **kwargs)

Alias of AbstractFileSystem.mv.

rm(path, recursive=False, maxdepth=None)

Remove a file or directory. :param path: Virtual fileset path :param recursive: Whether to remove the directory recursively.

When removing a directory, this parameter should be True.

Parameters:

maxdepth – The maximum depth to remove the directory recursively.

rm_file(path)

Remove a file. :param path: Virtual fileset path

rmdir(path)

Remove a directory. It will delete a directory and all its contents recursively for PyArrow.HadoopFileSystem. And it will throw an exception if delete a directory which is non-empty for LocalFileSystem. :param path: Virtual fileset path

sign(path, expiration=None, **kwargs)

We do not support to create a signed URL representing the given path in gvfs.

size(path)

Size in bytes of file

sizes(paths)

Size in bytes of each file in a list of paths

start_transaction()

Begin write transaction for deferring files, non-context version

stat(path, **kwargs)

Alias of AbstractFileSystem.info.

tail(path, size=1024)

Get the last size bytes from file

to_json()

JSON representation of this filesystem instance

Returns

str: JSON structure with keys cls (the python location of this class),

protocol (text name of this class’s protocol, first one in case of multiple), args (positional args, usually empty), and all other kwargs as their own keys.

touch(path, truncate=True, **kwargs)

Create empty file, or update timestamp

Parameters

path: str

file location

truncate: bool

If True, always set file size to 0; if False, update timestamp and leave file unchanged, if backend allows this

property transaction

A context within which files are committed together upon exit

Requires the file class to implement .commit() and .discard() for the normal and exception cases.

transaction_type

alias of Transaction

ukey(path)

Hash of file properties, to tell if it has changed

unstrip_protocol(name: str) str

Format FS-specific path to generic, including protocol

upload(lpath, rpath, recursive=False, **kwargs)

Alias of AbstractFileSystem.put.

walk(path, maxdepth=None, topdown=True, on_error='omit', **kwargs)

Return all files belows path

List all files, recursing into subdirectories; output is iterator-style, like os.walk(). For a simple list of files, find() is available.

When topdown is True, the caller can modify the dirnames list in-place (perhaps using del or slice assignment), and walk() will only recurse into the subdirectories whose names remain in dirnames; this can be used to prune the search, impose a specific order of visiting, or even to inform walk() about directories the caller creates or renames before it resumes walk() again. Modifying dirnames when topdown is False has no effect. (see os.walk)

Note that the “files” outputted will include anything that is not a directory, such as links.

Parameters

path: str

Root to recurse into

maxdepth: int

Maximum recursion depth. None means limitless, but not recommended on link-based file-systems.

topdown: bool (True)

Whether to walk the directory tree from the top downwards or from the bottom upwards.

on_error: “omit”, “raise”, a collable

if omit (default), path with exception will simply be empty; If raise, an underlying exception will be raised; if callable, it will be called with a single OSError instance as argument

kwargs: passed to ls

write_bytes(path, value, **kwargs)

Alias of AbstractFileSystem.pipe_file.

write_text(path, value, encoding=None, errors=None, newline=None, **kwargs)

Write the text to the given file.

An existing file will be overwritten.

Parameters

path: str

URL of file on this filesystems

value: str

Text to write.

encoding, errors, newline: same as open.