<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: UDF fails with &amp;quot;No module named 'dbruntime'&amp;quot; when using dbutils in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/udf-fails-with-quot-no-module-named-dbruntime-quot-when-using/m-p/122402#M10211</link>
    <description>&lt;P&gt;Currently, dbutils cannot be used inside of UDFs. For secrets, instead of getting the secret inside of the UDF, you can define it as a free variable outside of the UDF and it will be passed in properly, like the below&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from pyspark.sql.functions import pandas_udf, col
from pyspark.sql.types import *
import pandas as pd

secret = dbutils.secrets.get("scope", "secret")

@pandas_udf(LongType())
def example_udf(value: pd.Series) -&amp;gt; pd.Series:
    print(secret)
    return value

spark.range(1).select(example_udf(col("id"))).display()&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 20 Jun 2025 21:40:18 GMT</pubDate>
    <dc:creator>cgrant</dc:creator>
    <dc:date>2025-06-20T21:40:18Z</dc:date>
    <item>
      <title>UDF fails with "No module named 'dbruntime'" when using dbutils</title>
      <link>https://community.databricks.com/t5/get-started-discussions/udf-fails-with-quot-no-module-named-dbruntime-quot-when-using/m-p/121214#M10155</link>
      <description>&lt;P&gt;I've got an UDF which I call using&amp;nbsp;&lt;SPAN&gt;applyInPandas&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;That UDF is to distribute API calls.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It uses my custom .py library files that make these calls.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Everything worked until I use `&lt;/SPAN&gt;&lt;SPAN&gt;dbutils.widgets.&lt;/SPAN&gt;&lt;SPAN&gt;get` and `&lt;/SPAN&gt;&lt;SPAN&gt;dbutils.secrets.&lt;/SPAN&gt;&lt;SPAN&gt;get` inside these libraries.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It throws huge stack trace.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So the question is: how either to configure those libraries or get dbutils working?&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;PythonException: Traceback (most recent call last):
org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 106.0 failed 4 times, most recent failure: Lost task 0.3 in stage 106.0 (TID 230) (10.139.64.4 executor driver): org.apache.spark.api.python.PythonException: Traceback (most recent call last):
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/runtime/__init__.py", line 79, in &amp;lt;module&amp;gt;
    from dbruntime import UserNamespaceInitializer
ModuleNotFoundError: No module named 'dbruntime'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/config.py", line 473, in init_auth
    self._header_factory = self._credentials_strategy(self)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/credentials_provider.py", line 703, in __call__
    raise ValueError(
ValueError: cannot configure default credentials, please check https://docs.databricks.com/en/dev-tools/auth.html#databricks-client-unified-authentication to configure credentials for your preferred authentication method.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/config.py", line 123, in __init__
    self.init_auth()
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/config.py", line 478, in init_auth
    raise ValueError(f'{self._credentials_strategy.auth_type()} auth: {e}') from e
ValueError: default auth: cannot configure default credentials, please check https://docs.databricks.com/en/dev-tools/auth.html#databricks-client-unified-authentication to configure credentials for your preferred authentication method.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/databricks/spark/python/pyspark/serializers.py", line 192, in _read_with_length
    return self.loads(obj)
           ^^^^^^^^^^^^^^^
  File "/databricks/spark/python/pyspark/serializers.py", line 617, in loads
    return cloudpickle.loads(obj, encoding=encoding)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/databricks/spark/python/pyspark/cloudpickle/cloudpickle.py", line 649, in subimport
    __import__(name)
  File "/Workspace/Shared/sparky/lib/graphql/shopify_stock_graphql.py", line 2, in &amp;lt;module&amp;gt;
    import lib.configuration as conf
  File "/Workspace/Shared/sparky/lib/configuration.py", line 1, in &amp;lt;module&amp;gt;
    from databricks.sdk.runtime import *
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/runtime/__init__.py", line 172, in &amp;lt;module&amp;gt;
    dbutils = RemoteDbUtils()
              ^^^^^^^^^^^^^^^
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/dbutils.py", line 194, in __init__
    self._config = Config() if not config else config
                   ^^^^^^^^
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/config.py", line 127, in __init__
    raise ValueError(message) from e
ValueError: default auth: cannot configure default credentials, please check https://docs.databricks.com/en/dev-tools/auth.html#databricks-client-unified-authentication to configure credentials for your preferred authentication method.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/databricks/spark/python/pyspark/worker.py", line 2212, in main
    func, profiler, deserializer, serializer = read_udfs(pickleSer, infile, eval_type)
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/databricks/spark/python/pyspark/worker.py", line 1893, in read_udfs
    arg_offsets, f = read_single_udf(
                     ^^^^^^^^^^^^^^^^
  File "/databricks/spark/python/pyspark/worker.py", line 909, in read_single_udf
    f, return_type = read_command(pickleSer, infile)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/databricks/spark/python/pyspark/worker_util.py", line 71, in read_command
    command = serializer._read_with_length(file)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/databricks/spark/python/pyspark/serializers.py", line 196, in _read_with_length
    raise SerializationError("Caused by " + traceback.format_exc())
pyspark.serializers.SerializationError: Caused by Traceback (most recent call last):
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/runtime/__init__.py", line 79, in &amp;lt;module&amp;gt;
    from dbruntime import UserNamespaceInitializer
ModuleNotFoundError: No module named 'dbruntime'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/config.py", line 473, in init_auth
    self._header_factory = self._credentials_strategy(self)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/credentials_provider.py", line 703, in __call__
    raise ValueError(
ValueError: cannot configure default credentials, please check https://docs.databricks.com/en/dev-tools/auth.html#databricks-client-unified-authentication to configure credentials for your preferred authentication method.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/config.py", line 123, in __init__
    self.init_auth()
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/config.py", line 478, in init_auth
    raise ValueError(f'{self._credentials_strategy.auth_type()} auth: {e}') from e
ValueError: default auth: cannot configure default credentials, please check https://docs.databricks.com/en/dev-tools/auth.html#databricks-client-unified-authentication to configure credentials for your preferred authentication method.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/databricks/spark/python/pyspark/serializers.py", line 192, in _read_with_length
    return self.loads(obj)
           ^^^^^^^^^^^^^^^
  File "/databricks/spark/python/pyspark/serializers.py", line 617, in loads
    return cloudpickle.loads(obj, encoding=encoding)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/databricks/spark/python/pyspark/cloudpickle/cloudpickle.py", line 649, in subimport
    __import__(name)
  File "/Workspace/Shared/sparky/lib/graphql/shopify_stock_graphql.py", line 2, in &amp;lt;module&amp;gt;
    import lib.configuration as conf
  File "/Workspace/Shared/sparky/lib/configuration.py", line 1, in &amp;lt;module&amp;gt;
    from databricks.sdk.runtime import *
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/runtime/__init__.py", line 172, in &amp;lt;module&amp;gt;
    dbutils = RemoteDbUtils()
              ^^^^^^^^^^^^^^^
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/dbutils.py", line 194, in __init__
    self._config = Config() if not config else config
                   ^^^^^^^^
  File "/databricks/python/lib/python3.12/site-packages/databricks/sdk/config.py", line 127, in __init__
    raise ValueError(message) from e
ValueError: default auth: cannot configure default credentials, please check https://docs.databricks.com/en/dev-tools/auth.html#databricks-client-unified-authentication to configure credentials for your preferred authentication method.


..........&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 03:49:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/udf-fails-with-quot-no-module-named-dbruntime-quot-when-using/m-p/121214#M10155</guid>
      <dc:creator>Dimitry</dc:creator>
      <dc:date>2025-06-09T03:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: UDF fails with "No module named 'dbruntime'" when using dbutils</title>
      <link>https://community.databricks.com/t5/get-started-discussions/udf-fails-with-quot-no-module-named-dbruntime-quot-when-using/m-p/122402#M10211</link>
      <description>&lt;P&gt;Currently, dbutils cannot be used inside of UDFs. For secrets, instead of getting the secret inside of the UDF, you can define it as a free variable outside of the UDF and it will be passed in properly, like the below&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from pyspark.sql.functions import pandas_udf, col
from pyspark.sql.types import *
import pandas as pd

secret = dbutils.secrets.get("scope", "secret")

@pandas_udf(LongType())
def example_udf(value: pd.Series) -&amp;gt; pd.Series:
    print(secret)
    return value

spark.range(1).select(example_udf(col("id"))).display()&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 20 Jun 2025 21:40:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/udf-fails-with-quot-no-module-named-dbruntime-quot-when-using/m-p/122402#M10211</guid>
      <dc:creator>cgrant</dc:creator>
      <dc:date>2025-06-20T21:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: UDF fails with "No module named 'dbruntime'" when using dbutils</title>
      <link>https://community.databricks.com/t5/get-started-discussions/udf-fails-with-quot-no-module-named-dbruntime-quot-when-using/m-p/122735#M10220</link>
      <description>&lt;P&gt;What about creating a function like this?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CREATE OR REPLACE FUNCTION geocode_address(address STRING)

RETURNS STRUCT&amp;lt;latitude: DOUBLE, longitude: DOUBLE&amp;gt;

LANGUAGE PYTHON

ENVIRONMENT (

dependencies = '["requests"]',

environment_version = "None"

)

AS $$

import requests

api_key = dbutils.secrets.get("my-secret-scope", "google-maps-geocoding-api-key")

url = f"https://maps.googleapis.com/maps/api/geocode/json?address={address}&amp;amp;key={api_key}"

response = requests.get(url)

if response.status_code != 200:
    return None

try:
    data = response.json()

    if data['status'] == 'OK':
        location = data['results'][0]['geometry']['location']
        return (location['lat'], location['lng'])
    else:
        return None
except (KeyError, ValueError):
    return None
$$&lt;/LI-CODE&gt;&lt;P&gt;...and then testing it like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT geocode_address('1600 Amphitheatre Parkway, Mountain View, CA');&lt;/LI-CODE&gt;&lt;P&gt;Currently it results in the following error:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;NameError: name 'dbutils' is not defined&lt;/LI-CODE&gt;&lt;P&gt;What's the recommended way of retrieving the secret in this case?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jun 2025 19:31:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/udf-fails-with-quot-no-module-named-dbruntime-quot-when-using/m-p/122735#M10220</guid>
      <dc:creator>df_dbx</dc:creator>
      <dc:date>2025-06-24T19:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: UDF fails with "No module named 'dbruntime'" when using dbutils</title>
      <link>https://community.databricks.com/t5/get-started-discussions/udf-fails-with-quot-no-module-named-dbruntime-quot-when-using/m-p/122738#M10221</link>
      <description>&lt;P&gt;Answering my own question. Similar to the original response, the answer was to pass in the secret as a function argument:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CREATE OR REPLACE FUNCTION geocode_address(address STRING, api_key STRING)

RETURNS STRUCT&amp;lt;latitude: DOUBLE, longitude: DOUBLE&amp;gt;

LANGUAGE PYTHON

AS $$

import requests

url = f"https://maps.googleapis.com/maps/api/geocode/json?address={address}&amp;amp;key={api_key}"

response = requests.get(url)

if response.status_code != 200:
    return None

try:
    data = response.json()

    if data['status'] == 'OK':
        location = data['results'][0]['geometry']['location']
        return (location['lat'], location['lng'])
    else:
        return None
except (KeyError, ValueError):
    return None
$$&lt;/LI-CODE&gt;&lt;P&gt;And then here is how to call it:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT geocode_address('1600 Amphitheatre Parkway, Mountain View, CA', secret("my-secret-scope", "google-maps-geocoding-api-key"));&lt;/LI-CODE&gt;&lt;P&gt;Note: this won't work on a Serverless Warehouse (or Serverless compute) as by default they restrict outbound traffic.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jun 2025 20:46:33 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/udf-fails-with-quot-no-module-named-dbruntime-quot-when-using/m-p/122738#M10221</guid>
      <dc:creator>df_dbx</dc:creator>
      <dc:date>2025-06-24T20:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: UDF fails with "No module named 'dbruntime'" when using dbutils</title>
      <link>https://community.databricks.com/t5/get-started-discussions/udf-fails-with-quot-no-module-named-dbruntime-quot-when-using/m-p/122743#M10222</link>
      <description>&lt;P&gt;I ran outbound graphql on serverless, but on Azure version of the Databricks. Azure VMs don't restrict this.&lt;/P&gt;&lt;P&gt;My problem with serverless is&amp;nbsp;&lt;A href="https://community.databricks.com/t5/get-started-discussions/how-to-quot-python-versions-in-the-spark-connect-client-and/td-p/121213" target="_blank"&gt;How to "Python versions in the Spark Connect clien... - Databricks Community - 121213&lt;/A&gt;, so serverless is still unusable for UDFs.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jun 2025 23:17:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/udf-fails-with-quot-no-module-named-dbruntime-quot-when-using/m-p/122743#M10222</guid>
      <dc:creator>Dimitry</dc:creator>
      <dc:date>2025-06-24T23:17:14Z</dc:date>
    </item>
  </channel>
</rss>

