- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there a function to check the workspace name / ID in Fabric notebook?
Hi fabricators, is there a function by which we can see the name of the workspace or the workspace ID in fabric notebook?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @igorkk
Thanks for using Fabric Community.
You can use the below codes:
Hope this helps. Please let me know if you have any further questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Although marked as solved, it really isn't, so here's a solution...
How to get the workspace name when running a notebook. Use sempy (semantic link)
Here’s the function page help
https://learn.microsoft.com/en-us/fabric/data-science/semantic-link-semantic-functions
Install like this
%pip install -U semantic-link
Then run this...
import sempy.fabric as fabric
# Get the id of this notebooks workspace
workspace_id = fabric.get_notebook_workspace_id()
# You can also get this with fabric.get_workspace_id()
# From all workspaces, filter by Id and then just get the Name
workspaces = fabric.list_workspaces()
workspace_row = workspaces[workspaces.Id == workspace_id]
workspace_name = workspace_row['Name']
Edit: In the above code I put a comment to say that you could also use fabric.get_workspace_id(). Due to a possible bug in Fabric, you cannot use this, and should only use fabric.get_notebook_workspace_id(), like I did in the above code.
Thanks to Element115 for mentioning this. See replies for details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There's a simpler, one line, way to get the workspace name. Behold!!! 😁
import sempy.fabric as fabric
workspace_name = fabric.resolve_workspace_name()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nice find. Sempy is evolving nicely and so too is notebookutils (mssparkutils) with another one-liner.
notebookutils.mssparkutils.env.getWorkspaceName()
or
notebookutils.runtime.context.get("currentWorkspaceName")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
However, something I just noticed and don't know if it's a bug or intended to be such. Here's the context.
2 workspaces: SPARK and IVDS. 1 notebook: nb_test. Current workspace == SPARK.
I created nb_test in workspace IVDS. Later I saved it as a copy to workspace SPARK.
I am now working in SPARK-->nb_test.
This
workspace_id = fabric.get_notebook_workspace_id()
returns 'SPARK'.
But this
workspace_id = fabric.get_workspace_id()
returns 'IVDS' or the workspace where the copy's original was first created.
Go figure.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I agree that this looks like a bug.
As your code references id's, the return values will be workspace GUIDs, not names, but I assumed you meant the ids are referencing different workspaces and was intrigued so I tried it out, and I found exactly the same thing. fabric.get_workspace_id() gets the pre-copy workspace id. and if you used it to subsequently get the workspace name from a lookup using it, the result would be incorrect. get_notebook_workspace_id() returns the correct value so probably a better choice.
Rather more worrying, I also note that if you deploy with deployment pipelines rather than using Save a copy, you still get this behaviour.
(tested on 2024-09-24)
To get the workspace name, using notebookutils.mssparkutils is probably easier, but this library fdoesn't have a method to get the workspace_id
mssparkutils.env.getWorkspaceName()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's not my code but your code btw 😁, I lifted from your older post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
import sempy.fabric as fabric
def get_current_workspace_name():
# Get the id of this notebook's workspace
workspace_id = fabric.get_notebook_workspace_id()
# From all workspaces, filter by Id and then just get the Name
workspaces = fabric.list_workspaces()
workspace_row = workspaces[workspaces.Id == workspace_id]
workspace_name = workspace_row['Name'].values[0] # Extract the first value as a string
return workspace_name
# Usage example
workspace_name = get_current_workspace_name()
print(f'name: {workspace_name}')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @igorkk
Thanks for using Fabric Community.
You can use the below codes:
Hope this helps. Please let me know if you have any further questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Due to a change to notebookutils, these snippets work now:
fabric_workspace_id = notebookutils.runtime.context.get("currentWorkspaceId") # current workspace ID
fabric_workspace_name = notebookutils.runtime.context.get("currentWorkspaceName") # current workspace name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could you please share the link where this is documented?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I tried this and it works as expected for the Id, but when I call:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @igorkk
We haven’t heard from you on the last response and was just checking back to see if your query got resolved. Otherwise, will respond back with the more details and we will try to help.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @igorkk
We haven’t heard from you on the last response and was just checking back to see if your query got resolved. Otherwise, will respond back with the more details and we will try to help.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @igorkk
Glad that your query got resolved. Please continue using Fabric Community for any help regarding your queries.

Helpful resources
Join us at the Microsoft Fabric Community Conference
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Fabric Monthly Update - February 2025
Check out the February 2025 Fabric update to learn about new features.

Subject | Author | Posted | |
---|---|---|---|
01-22-2024 03:19 AM | |||
11-08-2024 04:02 AM | |||
01-06-2025 08:11 AM | |||
01-29-2025 07:02 AM | |||
02-13-2025 07:16 AM |
User | Count |
---|---|
35 | |
17 | |
3 | |
3 | |
2 |
User | Count |
---|---|
40 | |
14 | |
13 | |
12 | |
10 |