<?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 Re: Import notebook with python script using API in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10932#M5975</link>
    <description>&lt;P&gt;&lt;A href="https://docs.databricks.com/dev-tools/cli/index.html" target="test_blank"&gt;https://docs.databricks.com/dev-tools/cli/index.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but I checked what is working there on github as cli docs are more for...cli not sdk &lt;A href="https://github.com/databricks/databricks-cli/tree/master/databricks_cli/sdk" target="test_blank"&gt;https://github.com/databricks/databricks-cli/tree/master/databricks_cli/sdk&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;there is class JobsService and method run_now. I think is what you are looking for.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Nov 2021 15:01:44 GMT</pubDate>
    <dc:creator>Hubert-Dudek</dc:creator>
    <dc:date>2021-11-16T15:01:44Z</dc:date>
    <item>
      <title>Import notebook with python script using API</title>
      <link>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10925#M5968</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I would like to import a python notebook to my databricks workspace from my local machine using a python script.&lt;/P&gt;&lt;P&gt;I manages to create the folder but then I have a status code 400 when I try to import a file :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;create_folder = requests.post(
  '{}/api/2.0/workspace/mkdirs'.format(DBW_URL),
  headers={'Authorization': 'Bearer {}'.format(TOKEN)},
  json={"path": "/Repos/test"}
)
&amp;nbsp;
print(create_folder.status_code) # -&amp;gt; 200
&amp;nbsp;
python_code = """
# Databricks notebook source
print("This notebook has been imported via API.")
"""
&amp;nbsp;
data = base64.standard_b64encode(python_code.encode('utf-8')).decode('utf-8')
&amp;nbsp;
import_notebook = requests.post(
  '{}/api/2.0/workspace/import'.format(DBW_URL),
  headers={'Authorization': 'Bearer {}'.format(TOKEN)},
  json={
      "content": data,
      "path": "/Repos/test/hello.py",
      "language": "PYTHON",
      "overwrite": True,
      "format": "SOURCE"      
  }
)
&amp;nbsp;
print(import_notebook.status_code) # -&amp;gt; 400&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am not sure about the way I encoded the "content" value but I d'ont think this is the problem.&lt;/P&gt;&lt;P&gt;Thansk for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 13:45:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10925#M5968</guid>
      <dc:creator>RantoB</dc:creator>
      <dc:date>2021-11-12T13:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Import notebook with python script using API</title>
      <link>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10926#M5969</link>
      <description>&lt;P&gt;Where is this python code running, on your local machine or in Databricks?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 13:49:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10926#M5969</guid>
      <dc:creator>cconnell</dc:creator>
      <dc:date>2021-11-12T13:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Import notebook with python script using API</title>
      <link>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10927#M5970</link>
      <description>&lt;P&gt;on my local machine.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 15:32:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10927#M5970</guid>
      <dc:creator>RantoB</dc:creator>
      <dc:date>2021-11-12T15:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Import notebook with python script using API</title>
      <link>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10928#M5971</link>
      <description>&lt;P&gt;you can make your life easier and use cli api:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;pip install databricks-cli&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and then:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from databricks_cli.workspace.api import WorkspaceApi
from databricks_cli.sdk.api_client import ApiClient
&amp;nbsp;
client = ApiClient(
    host='https://your.databricks-url.net',
    token=api_key
)
workspace_api = WorkspaceApi(client)
workspace_api.import_workspace(
    source_path="/your/dir/here/hello.py",
    target_path="/Repos/test/hello.py",
    overwrite=True
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 17:30:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10928#M5971</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2021-11-14T17:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Import notebook with python script using API</title>
      <link>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10929#M5972</link>
      <description>&lt;P&gt;Hi, Thanks for your answer.&lt;/P&gt;&lt;P&gt;Actually both your code and mine are working. However, I cannot write in the directory Repos which is reserved (but I can create subdirectories...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks to your code I got an error message which helped me to understand. With my code I had no error message.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 08:13:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10929#M5972</guid>
      <dc:creator>RantoB</dc:creator>
      <dc:date>2021-11-15T08:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: Import notebook with python script using API</title>
      <link>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10930#M5973</link>
      <description>&lt;P&gt;any chance to be selected as the best answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ? &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 15:46:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10930#M5973</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2021-11-15T15:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Import notebook with python script using API</title>
      <link>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10931#M5974</link>
      <description>&lt;P&gt;Hi @Hubert Dudek​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you know where I can find the documentation about the pythno api for databricks ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Besides, do you know how to launch a job or notebook remotely with python api ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 13:33:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10931#M5974</guid>
      <dc:creator>RantoB</dc:creator>
      <dc:date>2021-11-16T13:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: Import notebook with python script using API</title>
      <link>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10932#M5975</link>
      <description>&lt;P&gt;&lt;A href="https://docs.databricks.com/dev-tools/cli/index.html" target="test_blank"&gt;https://docs.databricks.com/dev-tools/cli/index.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but I checked what is working there on github as cli docs are more for...cli not sdk &lt;A href="https://github.com/databricks/databricks-cli/tree/master/databricks_cli/sdk" target="test_blank"&gt;https://github.com/databricks/databricks-cli/tree/master/databricks_cli/sdk&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;there is class JobsService and method run_now. I think is what you are looking for.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 15:01:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10932#M5975</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2021-11-16T15:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Import notebook with python script using API</title>
      <link>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10933#M5976</link>
      <description>&lt;P&gt;I finally found. What I needed was there :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from databricks_cli.jobs.api import JobsApi
from databricks_cli.sdk.api_client import ApiClient&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I had to guess based on what you told me about databricks_cli.workspace.api&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 15:06:03 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10933#M5976</guid>
      <dc:creator>RantoB</dc:creator>
      <dc:date>2021-11-16T15:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: Import notebook with python script using API</title>
      <link>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10934#M5977</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I tried the same code but it's not working for me. I keep getting &lt;/P&gt;&lt;P&gt;&amp;nbsp;import_workspace() got an unexpected keyword argument 'format'. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;token_credential = DefaultAzureCredential()&lt;/P&gt;&lt;P&gt;scope = "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default"&lt;/P&gt;&lt;P&gt;token = token_credential.get_token(scope)&lt;/P&gt;&lt;P&gt;access_token = str(token.token)&lt;/P&gt;&lt;P&gt;from databricks_cli.workspace.api import WorkspaceApi&lt;/P&gt;&lt;P&gt;from databricks_cli.sdk.api_client import ApiClient&lt;/P&gt;&lt;P&gt;client = ApiClient(&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;host='https://your.databricks-url.net',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;token=access_token&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;&lt;P&gt;workspace_api = WorkspaceApi(client)&lt;/P&gt;&lt;P&gt;workspace_api.import_workspace(&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;source_path="/home/hello.py",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;target_path="/repo/test/hello.py",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;language="PYTHON",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;format = "SOURCE"&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 04:40:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10934#M5977</guid>
      <dc:creator>Ramya</dc:creator>
      <dc:date>2022-09-20T04:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Import notebook with python script using API</title>
      <link>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10935#M5978</link>
      <description>&lt;P&gt;Looks like the recent import_workspace api parameter is different. It worked after changed the correct parameter&lt;/P&gt;&lt;P&gt;workspace_api.import_workspace(&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;source_path="/home/&lt;A href="https://hello.py/" alt="https://hello.py/" target="_blank"&gt;hello.py&lt;/A&gt;",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;target_path="/repo/test/&lt;A href="https://hello.py/" alt="https://hello.py/" target="_blank"&gt;hello.py&lt;/A&gt;",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;language="PYTHON",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;fmt="SOURCE",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;is_overwrite = True&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 19:31:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/import-notebook-with-python-script-using-api/m-p/10935#M5978</guid>
      <dc:creator>Ramya</dc:creator>
      <dc:date>2022-09-20T19:31:53Z</dc:date>
    </item>
  </channel>
</rss>

