<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Import dbfs file into workspace using Python SDK in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/import-dbfs-file-into-workspace-using-python-sdk/m-p/37881#M5502</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am looking to replicate the functionality provided by the databricks_cli Python package using the Python SDK. Previously, using the databricks_cli WorkspaceApi object, I could use the import_workspace or import_workspace_dir methods to move a Python file, SQL file, or directory to my workspace. I am unsure how to do this using the SDK. I have tried a combination of the following:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
from databricks.sdk import WorkspaceClient
import databricks.sdk
from zipfile import ZipFile
import io

prod_w = WorkspaceClient(host=dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiUrl().get(),
                         token=dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiToken().get())
down = prod_w.dbfs.download('/FileStore/tmp/my_file.py')
# Try this?
prod_w.workspace.import_('/Users/myworkspace@email.com/my_file', content=down, format=databricks.sdk.service.workspace.ImportFormat.AUTO, language=databricks.sdk.service.workspace.Language.PYTHON, overwrite=True)
# Or this?
prod_w.workspace.upload('/Users/myworkspace@email.com/my_file', content=down, format=databricks.sdk.service.workspace.ImportFormat.AUTO, language=databricks.sdk.service.workspace.Language.PYTHON, overwrite=True)&lt;/LI-CODE&gt;&lt;P&gt;I get errors about the ImportFormat or the argument provided to the content parameter. In the event that I do get it to work, the file is empty.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please don't get&amp;nbsp;&lt;EM&gt;too&lt;/EM&gt; caught up in the details of the above code; I'm just trying my best to provide some tangible example of what I'm trying to do: import a valid dbfs file to my workspace using the Databricks Python SDK. I'm hoping someone more knowledgeable on the SDK can provide a working example of what I'm trying to do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Kurt&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jul 2023 16:22:37 GMT</pubDate>
    <dc:creator>kurtrm</dc:creator>
    <dc:date>2023-07-18T16:22:37Z</dc:date>
    <item>
      <title>Import dbfs file into workspace using Python SDK</title>
      <link>https://community.databricks.com/t5/get-started-discussions/import-dbfs-file-into-workspace-using-python-sdk/m-p/37881#M5502</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am looking to replicate the functionality provided by the databricks_cli Python package using the Python SDK. Previously, using the databricks_cli WorkspaceApi object, I could use the import_workspace or import_workspace_dir methods to move a Python file, SQL file, or directory to my workspace. I am unsure how to do this using the SDK. I have tried a combination of the following:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
from databricks.sdk import WorkspaceClient
import databricks.sdk
from zipfile import ZipFile
import io

prod_w = WorkspaceClient(host=dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiUrl().get(),
                         token=dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiToken().get())
down = prod_w.dbfs.download('/FileStore/tmp/my_file.py')
# Try this?
prod_w.workspace.import_('/Users/myworkspace@email.com/my_file', content=down, format=databricks.sdk.service.workspace.ImportFormat.AUTO, language=databricks.sdk.service.workspace.Language.PYTHON, overwrite=True)
# Or this?
prod_w.workspace.upload('/Users/myworkspace@email.com/my_file', content=down, format=databricks.sdk.service.workspace.ImportFormat.AUTO, language=databricks.sdk.service.workspace.Language.PYTHON, overwrite=True)&lt;/LI-CODE&gt;&lt;P&gt;I get errors about the ImportFormat or the argument provided to the content parameter. In the event that I do get it to work, the file is empty.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please don't get&amp;nbsp;&lt;EM&gt;too&lt;/EM&gt; caught up in the details of the above code; I'm just trying my best to provide some tangible example of what I'm trying to do: import a valid dbfs file to my workspace using the Databricks Python SDK. I'm hoping someone more knowledgeable on the SDK can provide a working example of what I'm trying to do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Kurt&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2023 16:22:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/import-dbfs-file-into-workspace-using-python-sdk/m-p/37881#M5502</guid>
      <dc:creator>kurtrm</dc:creator>
      <dc:date>2023-07-18T16:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: Import dbfs file into workspace using Python SDK</title>
      <link>https://community.databricks.com/t5/get-started-discussions/import-dbfs-file-into-workspace-using-python-sdk/m-p/37883#M5503</link>
      <description>&lt;P&gt;have you tried check&amp;nbsp;&lt;A href="https://docs.databricks.com/dev-tools/sdk-python.html" target="_blank"&gt;https://docs.databricks.com/dev-tools/sdk-python.html&lt;/A&gt;&amp;nbsp;?&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/databricks/databricks-sdk-py" target="_blank"&gt;https://github.com/databricks/databricks-sdk-py&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2023 16:43:48 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/import-dbfs-file-into-workspace-using-python-sdk/m-p/37883#M5503</guid>
      <dc:creator>Atanu</dc:creator>
      <dc:date>2023-07-18T16:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Import dbfs file into workspace using Python SDK</title>
      <link>https://community.databricks.com/t5/get-started-discussions/import-dbfs-file-into-workspace-using-python-sdk/m-p/37892#M5504</link>
      <description>&lt;P&gt;Hi Atanu,&lt;/P&gt;&lt;P&gt;Thank you for your reply. The examples provided in the GitHub repo are helpful but not much different than the ones provided in the &lt;A href="https://databricks-sdk-py.readthedocs.io/en/latest/workspace/workspace.html" target="_self"&gt;documentation&lt;/A&gt;. It is not clear what the difference is between the upload and import_ methods...&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2023 17:08:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/import-dbfs-file-into-workspace-using-python-sdk/m-p/37892#M5504</guid>
      <dc:creator>kurtrm</dc:creator>
      <dc:date>2023-07-18T17:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Import dbfs file into workspace using Python SDK</title>
      <link>https://community.databricks.com/t5/get-started-discussions/import-dbfs-file-into-workspace-using-python-sdk/m-p/37900#M5505</link>
      <description>&lt;P&gt;what is the exact issue you are facing ? any error message to share so we can check?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2023 19:28:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/import-dbfs-file-into-workspace-using-python-sdk/m-p/37900#M5505</guid>
      <dc:creator>Atanu</dc:creator>
      <dc:date>2023-07-18T19:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Import dbfs file into workspace using Python SDK</title>
      <link>https://community.databricks.com/t5/get-started-discussions/import-dbfs-file-into-workspace-using-python-sdk/m-p/38384#M5506</link>
      <description>&lt;P&gt;Even, I am looking for a way to bring files present in S3 to Workspace programmatically.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 13:37:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/import-dbfs-file-into-workspace-using-python-sdk/m-p/38384#M5506</guid>
      <dc:creator>Kratik</dc:creator>
      <dc:date>2023-07-25T13:37:34Z</dc:date>
    </item>
  </channel>
</rss>

