cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Unittesting databricks.sdk.runtime

samarth_solanki
New Contributor II

How to mock a code that uses dbutils from
"from databricks.sdk.runtime import dbutils"
it shows databricks-sdk has no attribute runtime

1 ACCEPTED SOLUTION

Accepted Solutions

Ayushi_Suthar
Databricks Employee
Databricks Employee

Hi @samarth_solanki , I Hope you are doing well! 

Based on the information you have shared, it seems like you're trying to import dbutils from databricks.sdk.runtime, but you're encountering an error that says "databricks-sdk has no attribute runtime". 

This issue might be due to the incorrect import statement or the version of the Databricks SDK you're using.  To use dbutils with the Databricks SDK for Python is to call it from the WorkspaceClient. Kindly refer to this as a example: 

from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
d = w.dbutils.fs.ls('/')
for f in d:
    print(f.path)

If you still face the issue then I would suggest checking the latest version of the Databricks SDK you are using and you can upgrade to the latest version using the below command: 

%pip install databricks-sdk --upgrade

Please refer this document for the more details: https://docs.databricks.com/ja/dev-tools/sdk-python.html#use-databricks-utilities

Please let me know if this helps and leave a like if this information is useful, followups are appreciated.
Kudos
Ayushi

View solution in original post

1 REPLY 1

Ayushi_Suthar
Databricks Employee
Databricks Employee

Hi @samarth_solanki , I Hope you are doing well! 

Based on the information you have shared, it seems like you're trying to import dbutils from databricks.sdk.runtime, but you're encountering an error that says "databricks-sdk has no attribute runtime". 

This issue might be due to the incorrect import statement or the version of the Databricks SDK you're using.  To use dbutils with the Databricks SDK for Python is to call it from the WorkspaceClient. Kindly refer to this as a example: 

from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
d = w.dbutils.fs.ls('/')
for f in d:
    print(f.path)

If you still face the issue then I would suggest checking the latest version of the Databricks SDK you are using and you can upgrade to the latest version using the below command: 

%pip install databricks-sdk --upgrade

Please refer this document for the more details: https://docs.databricks.com/ja/dev-tools/sdk-python.html#use-databricks-utilities

Please let me know if this helps and leave a like if this information is useful, followups are appreciated.
Kudos
Ayushi

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now