Forum Discussion

smpa01's avatar
smpa01
Community Champion
1 year ago
Solved

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

  • smpa01's avatar
    smpa01
    1 year ago

    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.

8 Replies

    • smpa01's avatar
      smpa01
      Community Champion

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

      • V-yubandi-msft's avatar
        V-yubandi-msft
        Community Support

        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

         

         

         

         

         

         

         

  • V-yubandi-msft's avatar
    V-yubandi-msft
    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's avatar
    V-yubandi-msft
    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.