Skip to main content

Complete example

from gjirafatech.truai.storage import TruStorageClient

storage = TruStorageClient()

page1 = storage.list_objects(prefix="directory/data")
page2 = storage.list_objects(prefix="directory/data", last_key=page1[-1])

stream = storage.get_object(key="directory/file.ext")

storage.get_directory(prefix="directory/", directory="/home/jovyan/data/")

f = open("directory/file.txt", "r")
storage.put_object(key="directory/file.txt", content=f, content_type="text/plain")

storage.put_directory(directory="/home/jovyan/data/", prefix="directory/")

#move keys
storage.move_objects(
keys={
"directory/file.ext": "directory/data.ext",
"directory/sample.csv": "raw-data/sample.csv",
}
)

#move by prefix
storage.move_objects(
prefixes={
"directory1/": "directory2/",
"raw-data/": "data/",
}
)

# delete keys
storage.delete_objects(keys=["directory/file.ext", "directory/sample.csv"])

# delete by prefix
storage.delete_objects(prefixes=["directory/", "raw-data/"])