Project libraries¶
You can interact with the Library of each project through the API.
Getting the DSSLibrary object¶
You must first retrieve the DSSLibrary
through the get_library()
method
project = client.get_project("MYPROJECT")
library = project.get_library()
Retrieving the content of a file¶
library_file = library.get_file("/file.txt")
print("Content: %s" % library_file.read()))
# Alternate ways to retrieve a file handle
library_file = library.get_file("/python/some_code.py")
library_file = library.get_folder("/python").get_file("/some_code.py")
Getting the list of all the library items¶
def print_library_items(item):
print(item.path)
if "list" in dir(item):
for child in item.list():
print_library_items(child)
for item in lib.list():
print_library_items(item)
Add a new folder in the library¶
library.add_folder("/new_folder")
library.add_folder("/python/new_sub_folder")
library.get_folder("/python").add_folder("another_sub_folder")
Add a new file in the library¶
# create a new file in a folder
file = open("/path/to/local/file")
library.put_file("/new_folder/file.txt", file)
Rename a file or a folder in the library¶
# rename a file in the library
library.get_file("/folder/file.txt").rename("renamed_file.txt")
# rename a folder in the library
library.get_folder("/folder").rename("renamed_folder")
Move a file or a folder in the library¶
# move a file in the library
library.get_file("/folder/file.txt").move_to(library.get_folder("/folder2"))
# move a folder in the library
library.get_folder("/folder").move_to(library.get_folder("/folder2"))
Delete a file or a folder from the library¶
library.get_file("/path/to/item").delete()
library.get_folder("/path/to").get_file("/item").delete()
Reference documentation¶
-
class
dataikuapi.dss.projectlibrary.
DSSLibrary
(client, project_key)¶ A handle to manage the library of a project It saves locally a copy of taxonomy to help navigate in the library All modifications done through this object and related library items are done locally and on remote. Note: Taxonomy modifications done outside this library are not reflected locally.
You should reload the library in this case.
-
list
(folder_path='/')¶ Lists the contents in the given library folder or on the root if no folder is given. :param: str folder_path: the folder path (optional). If no path is given, it is defaulted to the root path. :returns: the list of contents in the library folder :rtype: list of
dataikuapi.dss.projectlibrary.DSSLibraryItem
-
get_file
(path)¶ Retrieves a file in the library :param: str path: the file path :returns: the file in the given path :rtype:
dataikuapi.dss.projectlibrary.DSSLibraryFile
-
get_folder
(path)¶ Retrieves a folder in the library :param: str path: the folder path :returns: the folder in the given path :rtype:
dataikuapi.dss.projectlibrary.DSSLibraryFolder
-
add_file
(file_name)¶ Create a file in the library root folder :param: str file_name: the file name :returns: the new file :rtype:
dataikuapi.dss.projectlibrary.DSSLibraryFile
-
add_folder
(folder_name)¶ Create a folder in the library root folder :param: str file_name: the file name :returns: the new folder :rtype:
dataikuapi.dss.projectlibrary.DSSLibraryFolder
-