To programmatically retrieve the Databricks workspace name from within a notebook, you can use Spark configuration or the notebook context. One method is to read the workspace URL using spark.conf.get("spark.databricks.workspaceUrl") and then extract the instance name—for example, by splitting at the first period. Alternatively, you can access the notebook context with dbutils.notebook.entry_point.getDbutils().notebook().getContext().browserHostName().toString() (or via the equivalent JSON tags), which provides the hostname corresponding to the workspace. Both approaches give you a way to dynamically capture and use the workspace identifier in your code.
Wiliam Rosa
Data Engineer | Machine Learning Engineer
LinkedIn: linkedin.com/in/wiliamrosa