In Databricks Python notebook I can easily use dbutils
module.
Now I also would like to use it within plain Python file which I import into Databricks notebook
Here is an example.
Here is content of some_python_module.py
secret_value = dbutils.secrets.get("some_location", "some_secret")
Later on I am importing it in Databricks notebook
import some_python_module.py
But I get error message: NameError: name 'dbutils' is not defined
I tried to add import statement into my some_python_module.py
import dbutils
but it returns: ModuleNotFoundError: No module named 'dbutils'
Aslo dbutils.secrets.get("some_location", "some_secret")
works fine in Databricks notebook
2
Answers
As you want to import the python file into Azure databricks workspace.
I have created the below python file and uploaded the file to my filestore dbfs path:
In the above code I have used
It is used to access the
dbutils
object in a Databricks notebook’s environment when it is not directly available in the imported module.So basically Accessing dbutils from the Databricks notebook’s
IPython
environmentI have tried to retrieve a secret using the below:
Results:
dbutils
is a variable/instance-of-DBUtils-class.You can create your own instance of
DBUtils
if you like.From my
conftest.py
for pytest