Search code examples
databricksazure-databricksdatabricks-sdk

Databricks list notebook contents in python


I'm struggling to list notebook contents in python in the list, I'm able to list all notebooks path in the Workspace, i need contents for each NB, I have to check which mountpoint are usable in the workspace, because I have many active mountpoints

enter image description here

enter image description here


Solution

  • Don't use that SDK - it's deprecated. Instead, use the new Databricks Python SDK that has a built-in command to list objects recursively. Plus SDK also supports unified authentication, including implicit authentication when code is running in the notebook.

    Here is an example from the repository:

    from databricks.sdk import WorkspaceClient
    
    w = WorkspaceClient()
    
    # change this 
    start_path = f'/Users/{w.current_user.me().user_name}'
    
    names = []
    for i in w.workspace.list(start_path, recursive=True):
        names.append(i.path)