class LuxonisFileSystem:
Constructor: LuxonisFileSystem(path, allow_active_mlflow_run, allow_local, cache_storage, put_file_plugin)
An abstraction over remote and local sources.
This class provides a unified interface for file operations across different storage backends, including local filesystems, S3, GCS, and MLflow artifact storage.
For more flexibility, users can register custom implementations of the put_file method in PUT_FILE_REGISTRY. Its name can then be passed as the put_file_plugin argument when initializing LuxonisFileSystem. This allows for custom upload logic, such as additional processing before upload or integration with other services.
Example
>>> @PUT_FILE_REGISTRY.register() ... def put_file_plugin(*args, **kwargs) -> str: ... print("Custom put_file called!") ... return "remote_path" ... >>> fs = LuxonisFileSystem( ... "file:///tmp/luxonis-ml", ... put_file_plugin="put_file_plugin", ... ) >>> remote_path = fs.put_file("local/file.txt", "remote/file.txt") Custom put_file called! >>> print(remote_path) remote_path
| Static Method | download |
Download file or directory from remote storage. |
| Static Method | get |
Extract the detected protocol from a path. |
| Static Method | split |
Split the full path into protocol and absolute path. |
| Static Method | upload |
Upload file or directory to remote storage. |
| Method | __init__ |
Initialize the LuxonisFileSystem. |
| Method | delete |
Delete a directory and all its contents from remote storage. |
| Method | delete |
Delete a single file from remote storage. |
| Method | delete |
Delete multiple files from remote storage. |
| Method | exists |
Check whether the given remote path exists. |
| Method | get |
Copy many files from remote storage to local storage. |
| Method | get |
Copy a single file from remote storage. |
| Method | get |
Read a file and returns the (unique) UUID generated from file bytes. |
| Method | get |
Compute the UUIDs for all files stored in the filesystem. |
| Method | init |
Initialize an fsspec filesystem for the configured protocol. |
| Method | is |
Check whether the given remote path is a directory. |
| Method | put |
Upload a file to remote storage directly from file bytes. |
| Method | put |
Upload files to remote storage. |
| Method | put |
Copy a single file to remote storage. |
| Method | read |
Read a file into a string. |
| Method | read |
Read a file into a byte buffer. |
| Method | walk |
Walk through the individual files in a remote directory. |
| Instance Variable | allow |
Whether operations are allowed on the active MLflow run. |
| Instance Variable | allow |
Whether operations are allowed on the local file system. |
| Instance Variable | artifact |
MLflow artifact path when using MLflow filesystem. |
| Instance Variable | cache |
Path to cache storage, or None if no cache is used. |
| Instance Variable | experiment |
MLflow experiment ID when using MLflow filesystem. |
| Instance Variable | fs |
Initialized fsspec filesystem when using FSSPEC. |
| Instance Variable | fs |
Type of the filesystem, either MLFLOW or FSSPEC. |
| Instance Variable | path |
The path component of the input URL, with the protocol stripped. |
| Instance Variable | run |
MLflow run ID when using MLflow filesystem. |
| Instance Variable | tracking |
MLflow tracking URI when using MLflow filesystem. |
| Instance Variable | url |
The original input URL. |
| Property | full |
Full remote path. |
| Property | is |
Check whether the filesystem uses fsspec. |
| Property | is |
Check whether the filesystem is an MLflow filesystem. |
| Property | protocol |
Returns the protocol of the filesystem. |
| Static Method | _split |
Split an MLflow path into experiment, run, and artifact parts. |
| Instance Variable | _allow |
Undocumented |
| Instance Variable | _allow |
Undocumented |
| Instance Variable | _cache |
Undocumented |
| Instance Variable | _fs |
Undocumented |
| Instance Variable | _fs |
Undocumented |
| Instance Variable | _is |
Undocumented |
| Instance Variable | _path |
Undocumented |
| Instance Variable | _protocol |
Undocumented |
| Instance Variable | _url |
Undocumented |
Download file or directory from remote storage.
Intended for downloading a single remote object without needing to create a LuxonisFileSystem instance.
| Parameters | |
url:str | URL to the file or directory. |
dest:PathType | None | Destination directory. If None, the current working directory is used. |
| Returns | |
Path | Path to the downloaded file or directory. |
Extract the detected protocol from a path.
| Parameters | |
path:str | Path optionally containing the protocol. |
| Returns | |
str | Detected protocol. Defaults to "file" if no protocol is specified. |
Split the full path into protocol and absolute path.
| Parameters | |
path:PathType | Full path optionally containing the protocol. |
| Returns | |
tuple[ | The used protocol and absolute path. |
Upload file or directory to remote storage.
Useful for uploading a single local object
without having to create a LuxonisFileSystem instance.
| Parameters | |
localPathType | Path to the local file or directory. |
url:str | URL to the remote file or directory. |
str, allow_active_mlflow_run: bool | None = False, allow_local: bool | None = True, cache_storage: str | None = None, put_file_plugin: str | None = None):
¶
Initialize the LuxonisFileSystem.
| Parameters | |
path:str | Input path consisting of a protocol and path, or only a path for local files. |
allowbool | None | Whether operations are allowed on the active MLflow run. |
allowbool | None | Whether operations are allowed on the local file system. |
cachestr | None | Path to cache storage. No cache is used if not set. |
putstr | None | Name of a registered
function in PUT_FILE_REGISTRY to use instead of
LuxonisFileSystem.put_file. The registered function
must conform to the PutFile protocol. |
| Raises | |
ValueError |
|
Delete a directory and all its contents from remote storage.
| Parameters | |
remotePosixPathType | Relative path to the remote directory. |
allowbool | Whether to allow deleting the parent directory. |
| Raises | |
ValueError | If no directory is specified and deleting the parent directory is not allowed. |
NotImplementedError | If using a protocol that is not yet supported. |
Delete a single file from remote storage.
| Parameters | |
remotePosixPathType | Relative path to the remote file. |
| Raises | |
NotImplementedError | If using a protocol that is not yet supported. |
Delete multiple files from remote storage.
| Parameters | |
remotelist[ | Relative paths to remote files. |
| Raises | |
NotImplementedError | If using a protocol that is not yet supported. |
Check whether the given remote path exists.
| Parameters | |
remotePosixPathType | Relative path to the remote file. Defaults to an empty string, which represents the root path of the filesystem. |
| Returns | |
bool | True if the path exists, False otherwise. |
PosixPathType | Iterable[ PosixPathType], local_dir: PathType, mlflow_instance: ModuleType | None = None) -> Path:
¶
Copy many files from remote storage to local storage.
| Parameters | |
remotePosixPathType | Iterable[ | Either a path specifying a directory to walk, or an iterable of files that may be in different directories. |
localPathType | Path to the local directory. |
mlflowModuleType | None | Currently unused. MLflow downloads through this method are not implemented. |
| Returns | |
Path | Path to the downloaded directory. |
| Raises | |
NotImplementedError | If using a protocol that is not yet supported. |
PosixPathType, local_path: PathType, mlflow_instance: ModuleType | None = None) -> Path:
¶
Copy a single file from remote storage.
| Parameters | |
remotePosixPathType | Relative path to the remote file. |
localPathType | Path to the local file. |
mlflowModuleType | None | Currently unused. MLflow downloads through this method are not implemented. |
| Returns | |
Path | Path to the downloaded file. |
| Raises | |
NotImplementedError | If using a protocol that is not yet supported. |
Read a file and returns the (unique) UUID generated from file bytes.
| Parameters | |
path:PathType | Relative path to the remote file, or a local path when local is True. |
local:bool | Specifies a local path as opposed to a remote path. |
| Returns | |
str | UUID generated from the file bytes. |
| Raises | |
NotImplementedError | If using a protocol that is not yet supported. |
Compute the UUIDs for all files stored in the filesystem.
| Parameters | |
paths:Iterable[ | Relative remote paths, or local paths when local is True. |
local:bool | Specifies local paths as opposed to remote paths. |
| Returns | |
dict[ | Dictionary mapping paths to their UUIDs. |
Initialize an fsspec filesystem for the configured protocol.
| Returns | |
fsspec.AbstractFileSystem | Initialized fsspec filesystem. |
| Raises | |
NotImplementedError | If the protocol is not supported by fsspec. |
RuntimeError | If the credentials for the protocol are not properly set in environment variables. |
Check whether the given remote path is a directory.
| Parameters | |
remotePosixPathType | Relative path to the remote path. |
| Returns | |
bool | True if the path is a directory, False otherwise. |
bytes, remote_path: PosixPathType, mlflow_instance: ModuleType | None = None):
¶
Upload a file to remote storage directly from file bytes.
| Parameters | |
filebytes | File contents to upload. |
remotePosixPathType | Relative path to the remote file. |
mlflowModuleType | None | Currently unused. MLflow uploads from bytes are not implemented. |
| Raises | |
NotImplementedError | If using a protocol that is not yet supported. |
Iterable[ PathType], remote_dir: PosixPathType, uuid_dict: dict[ str, str] | None = None, mlflow_instance: ModuleType | None = None, copy_contents: bool = False) -> dict[ str, str]:PathType, remote_dir: PosixPathType, uuid_dict: dict[ str, str] | None = None, mlflow_instance: ModuleType | None = None, copy_contents: bool = False):Upload files to remote storage.
| Parameters | |
localPathType | Iterable[ | Either a path specifying a directory to walk, or an iterable of files that may be in different directories. |
remotePosixPathType | Relative path to the remote directory. |
uuiddict[ | Stores paths as keys and corresponding UUIDs as values to replace the file basename. |
mlflowModuleType | None | MLflow instance to use when uploading to an active run. |
copybool | If True, only copy the contents of the folder specified in local_paths. |
| Returns | |
dict[ | Mapping of local paths to remote paths if local_paths is an iterable of files, otherwise None. |
| Raises | |
NotImplementedError | If using a protocol that is not yet supported. |
ValueError | If local_paths is not a directory. |
PathType, remote_path: PosixPathType, mlflow_instance: ModuleType | None = None) -> str:
¶
Copy a single file to remote storage.
| Parameters | |
localPathType | Path to the local file. |
remotePosixPathType | Relative path to the remote file. |
mlflowModuleType | None | MLflow instance to use when uploading to an active run. |
| Returns | |
str | Full remote path of the uploaded file. |
| Raises | |
ValueError | If using MLflow and there is no active run or no MLflow instance provided. |
Read a file into a string.
| Parameters | |
remotePosixPathType | Relative path to the remote file. |
| Returns | |
str | bytes | The contents of the file. |
| Raises | |
NotImplementedError | If using a protocol that is not yet supported. |
Read a file into a byte buffer.
| Parameters | |
remotePosixPathType | None | Relative path to the remote file. If omitted, reads from self.path. |
| Returns | |
BytesIO | Byte buffer containing the file contents. |
| Raises | |
ValueError |
|
PosixPathType, recursive: bool = True, typ: Literal[ 'file', 'directory', 'all'] = 'file') -> Iterator[ str]:
¶
Walk through the individual files in a remote directory.
| Parameters | |
remotePosixPathType | Relative path to the remote directory. |
recursive:bool | If True, walks through the directory recursively. Defaults to True. |
typ:Literal[ | Type of entries to yield. Corresponds to the "type" field in fsspec's ls output. Defaults to "file". |
| Returns | |
Iterator[ | Undocumented |
| Yields | |
| Relative paths to the files in the remote directory. |
| Raises | |
NotImplementedError | If walking an MLflow artifact directory, which is not supported. |
Check whether the filesystem is an MLflow filesystem.
| Returns | |
| True if the filesystem is an MLflow filesystem, |