Databricks is smart and all, but how do you identify the path of your current notebook? The guide on the website does not help.
It suggests:
%scala
dbutils.notebook.getContext.notebookPath
res1: Option[String] = Some(/Users/user@org.dk/my_test_notebook)
This does not give me the complete path, but rather the path to some folder structure that is not accessible from the notebook. I need the path, such that I can make system calls in the same folder as the .ipynb file.
Any suggestions?
I ended up somewhat resolving the problem using the Databricks API to download and upload notebooks and other files to/from Databricks.
In the user interface do the following to generate an API Token and copy notebook path:
If you want to access a notebook file, you can download it using a curl-call. If you are located inside a Databricks notebook, you can simply make this call either using cell magic, %sh, or using a system call, os.system('insert command').
curl --header "Content-Type: application/json" --request GET --data '{"path":"{/Users/myuser@myorg.com/notebook_to_download}","format":"JUPYTER"}' https://{replace_with_your_databaricks}/api/2.0/workspace/export -H "Authorization: Bearer {my_token}" | jq -r .content | base64 --decode > my_downloaded_notebook.ipynb
You can similarly upload a notebook from a machine using the following curl call:
curl -n -F format=JUPYTER -F path="{/Users/myuser@myorg.com/uploaded_notebook}" -F language=PYTHON -F content=@{/my/local/notebook.ipynb} https://{replace_with_your_databaricks}/api/2.0/workspace/import -H "Authorization: Bearer {my_token}"