2

I am in the process of building a Python package that can be used by Data Scientists to manage their MLOps lifecycle. Now, this package can be used either locally (usually on PyCharm) or on Databricks.

I want a certain functionality of the package to be dependent on where it is running, i.e. I want it to do something different if it is called by a Databricks notebook and something else entirely if it is running locally.

Is there any way I can determine where it is being called from?

I am a little doubtful as to whether we can use something like the following that checks if your code is running on a notebook or otherwise since this will be a package that is going to be stored in your Databricks environment,
How can I check if code is executed in the IPython notebook?

Minura Punchihewa
  • 1,498
  • 1
  • 12
  • 35

1 Answers1

3

The workaround I've found to work is to check for databricks specific environment variables.

import os
def is_running_in_databricks() -> bool:
    return "DATABRICKS_RUNTIME_VERSION" in os.environ
Fabitosh
  • 98
  • 10