I am running a machine learning experiment in Databricks and I want to obtain the workspace URL for certain uses.
I know how to manually obtain the workspace URL of notebook from this link https://docs.microsoft.com/en-us/azure/databricks/workspace/per-workspace-urls
Similar to how you can obtain the path of your notebook by
dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get()
How do I programmatically obtain the notebook's URL?
CodePudding user response:
There are two things available:
- Browser host name - it gives you just host name, without http/https schema, but it's really a name that you see in the browser:
dbutils.notebook.entry_point.getDbutils().notebook().getContext() \
.browserHostName().get()
- API URL: base URL with HTTPS schema that you can use to call APIs:
dbutils.notebook.entry_point.getDbutils().notebook().getContext() \
.apiUrl().get()
P.S. I really prefer to convert that information into a Python dict that it's easier to investigate and use. I use code like this:
import json
ctx = json.loads(dbutils.notebook.entry_point.getDbutils().notebook() \
.getContext().toJson())
ctx