Table.add_files

Table.add_files(*, files=None, directory=None, max_parallelization=os.cpu_count() * 5) → list(File)

Uploads either a list of files or all files in a directory to an index table. The index table must be on an unreleased version. Attempting to add files to a non-index table will result in an error.

Parameters:

files : list(str) | list(dict<path=str, name=str, data=str | bytes>), default None A list of files to upload. Either this or directory must be specified, but not both. Can either be a list of file paths, or a list of dicts with the keys path, name, and/or data. If providing a list of dicts, each dict must specify either path (the path to the file on disk) or data, representing the content to upload. name is optional if path is specified (defaulting to the file name), but required if data is specified.

directory : str, default None A directory of files to upload. Either this or files must be specified, but not both. All files in the directory will be uploaded, including hidden files and those in any subdirectories.

max_parallelization : int, default os.cpu_count() * 5 The maximum concurrency when uploading files. If you have lots of small files, you may want to increase the concurrency, while you may want to decrease it if you have just a few large files.

Returns:

list(File)

Examples:

dataset = redivis.user("my_username").dataset("my_dataset")

table = dataset.table("my_files")
# If the file index table doesn't already exist, we can create it
# table.create(is_file_index=True)

# upload all contents in a directory
table.add_files(directory="/path/to/directory/")

# upload specific files
table.add_files(files=list(
    {"path": "/path/to/file.png"}, # file name will be "file.png"
    {"path": "/path/to/other/file.png", "name": "other_file.png"}, # file name will be other_file.png
    {"data": "Hello world", "name": "hello_world.txt"} # Data can be string or bytes 
)

Last updated