Python to Export File to Local Drive

Pete1
Pete1 Registered Posts: 1 ✭✭✭

Is there a way I can take a file (.csv or .xlsx) from a folder in DSS and send it to a local folder using Python?


Operating system used: Windows

Tagged:

Best Answer

  • Catalina
    Catalina Dataiker, Dataiku DSS Core Designer, Registered Posts: 135 Dataiker
    edited July 17 Answer ✓

    Hi @Pete1
    ,

    Below is an example Python code that uses Dataiku Python APIs to export the files from a DSS folder to a local folder called output :

    import dataikuapi
    import io, os
    
    host="http://localhost:11200"
    apiKey = "*******"
    project_key="******"
    folder_id="*****"
    
    def api_py_function(project_key, folder_id):
        client = dataikuapi.DSSClient(host,apiKey)
        folder = dataikuapi.dss.managedfolder.DSSManagedFolder(client, project_key, folder_id)
        contents = folder.list_contents()
        if not os.path.exists("output"):
            os.mkdir("output")
        for item in contents["items"]:
            with open("output/"+item["path"], "wb") as f:
                    file = folder.get_file(item["path"])
                    f.write(file.content) ​
    
    api_py_function(project_key,folder_id) 

Setup Info
    Tags
      Help me…