Retrieve Envinroment Info In MS Fabric Notebook
Introduction
I was working on a Fabric notebook the other day and I needed to know how to get the name of the notebook and workspace my notebook was in so I could send it to some logging. It took me longer than it should have to figure this part out so I thought I would make a post about it so that I didn't have to do that again.
While you can get the notebook name and workspace name this way, you can also use it to get a lot of other information that might be useful to you.
Notebook Utilities
Notebook Utilities, also known as notebookutils, is a library in Fabric that allows you to interact with the Fabric environment. In this blog post I am going to be focusing on one very small but useful aspect of this library which is how to retrieve information about your notebook and workspace.
The main function we are going to use is runtime.context.get(). The main definition of the function looks like the below code.
artifact = notebookutils.runtime.context.get("artifact_name")
Now that we know the definition, we can start retrieving information about our environment by entering in some parameters.
# Get the current notebook name
notebook_name = notebookutils.runtime.context.get("currentNotebookName")
# Get the current workspace name
workspace_name = notebookutils.runtime.context.get("currentWorkspaceName")
display(notebook_name)
display(workspace_name)
You can see more options for "artifacts" can be used by reading the github docs for Fabric. To make things easier, I just copied the list in the table below.
Parameter | Explanation |
---|---|
currentNotebookName | The name of the current notebook |
currentNotebookId | The unique ID of the current notebook |
currentWorkspaceName | The name of the current workspace |
currentWorkspaceId | The ID of the current workspace |
defaultLakehouseName | The display name of the default lakehouse, if defined |
defaultLakehouseId | The ID of the default lakehouse, if defined |
defaultLakehouseWorkspaceName | The workspace name of the default lakehouse, if defined |
defaultLakehouseWorkspaceId | The workspace ID of the default lakehouse, if defined |
currentRunId | In a reference run, the current run ID |
parentRunId | In a reference run with nested runs, this ID is the parent run ID |
rootRunId | In a reference run with nested runs, this ID is the root run ID |
isForPipeline | Whether the run is for a pipeline |
isReferenceRun | Whether the current run is a reference run |
referenceTreePath | The tree structure of nested reference runs, used only for the snapshot hierarchy in the monitoring L2 page |
rootNotebookId | (Only in reference run) The ID of the root notebook in a reference run. |
rootNotebookName | (Only in reference run) The name of the root notebook in a reference run. |
rootWorkspaceId | (Only in reference run) The workspace ID of the root notebook in a reference run. |
rootWorkspaceName | (Only in reference run) The workspace name of the root notebook in a reference run. |
activityId | The Livy job ID for the current activity |
hcRepId | The REPL ID in High Concurrency Mode |
clusterId | The identity of the Synapse Spark cluster |
poolName | The name of the Spark pool being used |
environmentId | The environment ID where the job is running |
environmentWorkspaceId | The workspace ID of the environment |
userId | The user ID of the current user |
userName | The user name of the current user |
Conclusion
Notebookutils is a great way to retrieve information about your notebook and its environment. You can use this same library to do many other things from restarting your session to copying files. We will explore some of those options in future posts.
I don't have a comments section yet, so feel free to send me feedback on this blog.
Kevin is a data engineer and is the Business Intelligence Practice Lead at Software Design Partners specializing in data warehousing. He is a father, an occasional gamer, and lover of many different types of music.
The opinions expressed on this site are my own and may not represent my employer's view.
About this blog...
This post takes a look at how to use notebook utils to get information about the notebook environment in Microsoft Fabric
Archives
- 2025
- 2023
- 2022
- 2021