File storage utilities.
Class |
|
Enumeration of the available file systems. |
Class |
|
Context manager that creates and destroys a temporary directory. |
Function | abspath |
Converts the given path to an absolute path, resolving relative path indicators such as . and ... |
Function | copy |
Copies the input directory to the output directory. |
Function | copy |
Copies the input file to the output location. |
Function | copy |
Copies the files to the given locations. |
Function | delete |
Deletes the given directory and recursively deletes any empty directories from the resulting directory tree. |
Function | delete |
Deletes the file at the given path. |
Function | delete |
Deletes the files from the given locations. |
Function | ensure |
Makes the base directory of the given path, if necessary. |
Function | ensure |
Makes the given directory, if necessary. |
Function | ensure |
Ensures that the given directory exists and is empty. |
Function | ensure |
Ensures that the given path is local. |
Function | exists |
Determines whether the given file or directory exists. |
Function | extract |
Extracts the contents of an archive. |
Function | get |
Gets the bucket name from the given path. |
Function | get |
Returns the file system enum for the given path. |
Function | get |
Returns a list of file paths matching the given glob pattern. |
Function | get |
Finds the root directory of the given glob pattern, i.e., the deepest subdirectory that contains no glob characters. |
Function | is |
Determines whether the given path is local. |
Function | isabs |
Determines whether the given path is absolute. |
Function | isdir |
Determines whether the given directory exists. |
Function | isfile |
Determines whether the given file exists. |
Function | join |
Joins the given path components into a single path. |
Function | list |
Lists the file systems that are currently available for use with methods like list_files and list_buckets . |
Function | list |
Lists the available buckets in the given file system. |
Function | list |
Lists the files in the given directory. |
Function | list |
Lists the subdirectories in the given directory, sorted alphabetically and excluding hidden directories. |
Function | load |
Loads JSON from the input argument. |
Function | load |
Loads NDJSON from the input argument. |
Function | make |
Makes an archive containing the given directory. |
Function | make |
Makes a temporary directory. |
Function | move |
Moves the contents of the given directory into the given output directory. |
Function | move |
Moves the given file to a new location. |
Function | move |
Moves the files to the given locations. |
Function | normalize |
Normalizes the given path by converting it to an absolute path and expanding the user directory, if necessary. |
Function | normpath |
Normalizes the given path by converting all slashes to forward slashes on Unix and backslashes on Windows and removing duplicate slashes. |
Function | open |
Opens the given file for reading or writing. |
Function | open |
Opens the given files for reading or writing. |
Function | read |
Reads the file. |
Function | read |
Reads the specified files into memory. |
Function | read |
Reads a JSON file. |
Function | read |
Reads an NDJSON file. |
Function | read |
Reads a YAML file. |
Function | realpath |
Converts the given path to absolute, resolving symlinks and relative path indicators such as . and ... |
Function | run |
Applies the given function to each element of the given tasks. |
Function | sep |
Returns the path separator for the given path. |
Function | split |
Splits the file system prefix from the given path. |
Function | write |
Writes the given string/bytes to a file. |
Function | write |
Writes JSON object to file. |
Function | write |
Writes the list of JSON dicts in NDJSON format. |
Function | write |
Writes the object to a YAML file. |
Variable | logger |
Undocumented |
Function | _copy |
Undocumented |
Function | _copy |
Undocumented |
Function | _delete |
Undocumented |
Function | _do |
Undocumented |
Function | _do |
Undocumented |
Function | _do |
Undocumented |
Function | _do |
Undocumented |
Function | _do |
Undocumented |
Function | _get |
Undocumented |
Function | _open |
Undocumented |
Function | _read |
Undocumented |
Function | _run |
Undocumented |
Function | _to |
Undocumented |
Converts the given path to an absolute path, resolving relative path indicators such as . and ...
Parameters | |
path | the filepath |
Returns | |
the absolute path |
Copies the input directory to the output directory.
Parameters | |
indir | the input directory |
outdir | the output directory |
overwrite:True | whether to delete an existing output directory (True) or merge its contents (False) |
skipFalse | whether to gracefully continue without raising an error if an operation fails |
progress:None | whether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead |
Copies the files to the given locations.
Parameters | |
inpaths | a list of input paths |
outpaths | a list of output paths |
skipFalse | whether to gracefully continue without raising an error if an operation fails |
progress:None | whether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead |
Deletes the given directory and recursively deletes any empty directories from the resulting directory tree.
Parameters | |
dirpath | the directory path |
Deletes the file at the given path.
Any empty directories are also recursively deleted from the resulting directory tree.
Parameters | |
path | the filepath |
Deletes the files from the given locations.
Any empty directories are also recursively deleted from the resulting directory tree.
Parameters | |
paths | a list of paths |
skipFalse | whether to gracefully continue without raising an error if an operation fails |
progress:None | whether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead |
Ensures that the given directory exists and is empty.
Parameters | |
dirpath | the directory path |
cleanup:False | whether to delete any existing directory contents |
Raises | |
ValueError | if the directory is not empty and cleanup is False |
Determines whether the given file or directory exists.
Parameters | |
path | the file or directory path |
Returns | |
True/False |
Extracts the contents of an archive.
The following formats are guaranteed to work: .zip, .tar, .tar.gz, .tgz, .tar.bz, .tbz.
If an archive not in the above list is found, extraction will be attempted via the patool package, which supports many formats but may require that additional system packages be installed.
Parameters | |
archive | the archive path |
outdir:None | the directory into which to extract the archive. By default, the directory containing the archive is used |
cleanup:False | whether to delete the archive after extraction |
Gets the bucket name from the given path.
The bucket name for local paths is "".
Example usages:
import fiftyone.core.storage as fos fos.get_bucket_name("/path/to/file") # '' fos.get_bucket_name("a/file") # ''
Parameters | |
path | a path |
Returns | |
the bucket name string |
Returns a list of file paths matching the given glob pattern.
The matches are returned in sorted order.
Parameters | |
glob | a glob pattern like /path/to/files-*.jpg |
Returns | |
a list of file paths |
Finds the root directory of the given glob pattern, i.e., the deepest subdirectory that contains no glob characters.
Parameters | |
glob | a glob pattern like /path/to/files-*.jpg |
Returns | |
a tuple of |
|
Determines whether the given directory exists.
Cloud "folders" are deemed to exist only if they are non-empty.
Parameters | |
dirpath | the directory path |
Returns | |
True/False |
Joins the given path components into a single path.
Parameters | |
a | the root |
*p | additional path components |
Returns | |
the joined path |
Lists the file systems that are currently available for use with methods
like list_files
and list_buckets
.
Returns | |
a list of FileSystem values |
Lists the available buckets in the given file system.
This method returns subdirectories of / (or the current drive on Windows).
Parameters | |
fs | a FileSystem value |
absFalse | whether to return absolute paths |
Returns | |
a list of buckets |
Lists the files in the given directory.
If the directory does not exist, an empty list is returned.
Parameters | |
dirpath | the path to the directory to list |
absFalse | whether to return the absolute paths to the files |
recursive:False | whether to recursively traverse subdirectories |
includeFalse | whether to include dot files |
returnFalse | whether to return metadata dicts for each file instead of filepaths |
sort:True | whether to sort the list of files |
Returns | |
a list of filepaths or metadata dicts |
Loads JSON from the input argument.
Parameters | |
path | the filepath or JSON string |
Returns | |
the loaded JSON |
Loads NDJSON from the input argument.
Parameters | |
path | the filepath or NDJSON string |
Returns | |
a list of JSON dicts |
Makes an archive containing the given directory.
Supported formats include .zip, .tar, .tar.gz, .tgz, .tar.bz and .tbz.
Parameters | |
dirpath | the directory to archive |
archive | the archive path to write |
cleanup:False | whether to delete the directory after archiving it |
Makes a temporary directory.
Parameters | |
basedir:None | an optional directory in which to create the new directory. The default is fiftyone.config.default_dataset_dir |
Returns | |
the temporary directory path |
Moves the contents of the given directory into the given output directory.
Parameters | |
indir | the input directory |
outdir | the output directory |
overwrite:True | whether to delete an existing output directory (True) or merge its contents (False) |
skipFalse | whether to gracefully continue without raising an error if an operation fails |
progress:None | whether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead |
Moves the files to the given locations.
Parameters | |
inpaths | a list of input paths |
outpaths | a list of output paths |
skipFalse | whether to gracefully continue without raising an error if an operation fails |
progress:None | whether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead |
Normalizes the given path by converting it to an absolute path and expanding the user directory, if necessary.
Parameters | |
path | a path |
Returns | |
the normalized path |
Normalizes the given path by converting all slashes to forward slashes on Unix and backslashes on Windows and removing duplicate slashes.
Use this function when you need a version of os.path.normpath that converts \ to / on Unix.
Parameters | |
path | a path |
Returns | |
the normalized path |
Opens the given file for reading or writing.
Example usage:
import fiftyone.core.storage as fos with fos.open_file("/tmp/file.txt", "w") as f: f.write("Hello, world!") with fos.open_file("/tmp/file.txt", "r") as f: print(f.read())
Parameters | |
path | the path |
mode:"r" | the mode. Supported values are ("r", "rb", "w", "wb") |
Returns | |
an open file-like object |
Opens the given files for reading or writing.
Parameters | |
paths | a list of paths |
mode:"r" | the mode. Supported values are ("r", "rb", "w", "wb") |
skipFalse | whether to gracefully continue without raising an error if an operation fails |
progress:None | whether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead |
Returns | |
a list of open file-like objects |
Reads the file.
Parameters | |
path | the filepath |
binary:False | whether to read the file in binary mode |
Returns | |
the file contents |
Reads the specified files into memory.
Parameters | |
paths | a list of filepaths |
binary:False | whether to read the files in binary mode |
skipFalse | whether to gracefully continue without raising an error if an operation fails |
progress:None | whether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead |
Returns | |
a list of file contents |
Converts the given path to absolute, resolving symlinks and relative path indicators such as . and ...
Parameters | |
path | the filepath |
Returns | |
the resolved path |
Applies the given function to each element of the given tasks.
Parameters | |
fcn | a function that accepts a single argument |
tasks | an iterable of function arguments |
returnTrue | whether to return the function results |
numNone | a suggested number of threads to use |
progress:None | whether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead |
Returns | |
the list of function outputs, or None if return_results == False |
Splits the file system prefix from the given path.
The prefix for local paths is "".
Example usages:
import fiftyone.core.storage as fos fos.split_prefix("/path/to/file") # ('', '/path/to/file') fos.split_prefix("a/file") # ('', 'a/file')
Parameters | |
path | a path |
Returns | |
a (prefix, path) tuple |
Writes the given string/bytes to a file.
If a string is provided, it is encoded via .encode().
Parameters | |
str | the string or bytes |
path | the filepath |
Writes JSON object to file.
Parameters | |
d | JSON data |
path | the filepath |
prettyFalse | whether to render the JSON in human readable format with newlines and indentations |