Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
smpa01
Super User
Super User

detect runtime

Is there any way for a code to return the environment in notebook;

 

 

//pseudocode

print(os.environ)
// detects either Fabric or Databricks runtime

 

 

thank you in advance

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION

The problem requires a code that runs across platforms

sys.modules

 and returns unique values related to 'fabric' or 'databricks' or a key that contains  'fabric' or 'databricks' .

 

I am still open for a better solution but for now I can survive with this.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

8 REPLIES 8
V-yubandi-msft
Community Support
Community Support

Hi @smpa01 ,

Has your issue been resolved, or do you require any further information? Your feedback is valuable to us. If the solution was effective, please mark it as 'Accepted Solution' to assist other community members experiencing the same issue.

V-yubandi-msft
Community Support
Community Support

Hi @smpa01 ,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank You.

V-yubandi-msft
Community Support
Community Support

Hi @smpa01 ,

You can utilize   ‘notebookutils.runtime.context’   in Microsoft Fabric to obtain information about the current session, such as the notebook name, workspace details, and lakehouse information.

 notebookutils.runtime.context

 

Helpful Reference:

NotebookUtils (former MSSparkUtils) for Fabric - Microsoft Fabric | Microsoft Learn

 

I hope this information is helpful to you.

 

I need a code that can run both in databricks and fabric notebooks

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi @smpa01 ,

Detecting the environment in a notebook whether it's running on Microsoft Fabric or Databricks requires different methods since both platforms handle runtime details differently. Unfortunately, there's no universal way to do this across both environments.

 

Each platform has its own way of providing system information:

1. Microsoft Fabric Notebooks -  Microsoft Fabric relies on notebookutils.runtime.context to fetch session, notebook, and workspace details. However, this API is specific to Fabric and isn't available in Databricks.

 

2. Databricks provides the DATABRICKS_RUNTIME_VERSION environment variable, which shows the runtime version. This variable is specific to Databricks and is not available in Microsoft Fabric.

FYI

Vyubandimsft_0-1742470807485.png

 

Vyubandimsft_1-1742470807489.png

 

 

 

 

 

 

The problem requires a code that runs across platforms

sys.modules

 and returns unique values related to 'fabric' or 'databricks' or a key that contains  'fabric' or 'databricks' .

 

I am still open for a better solution but for now I can survive with this.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

You managed to find a temporary solution, so it's best to mark it as accepted. This will be helpful for others facing the same issue for now.

lbendlin
Super User
Super User

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.