List of Notebooks in a Workspace - Databricks

Viewed 1812

I want to list down the Notebooks in a folder in Databricks. I tried to use the utilities like , dbutils.fs.ls("/path") - > It shows the path of the storage folder.

I also tried to check dbutil.notebook.help() - nothing useful.

Lets say, there is a folder - XXYY. This folder contains multiple Notebooks. I just want the list of the Notebooks in that folder. Is their any command available. Any suggestion.

1 Answers

dbutils.fs.ls works with files on the Databricks File System, so you can't use it.

You can get what you need via the the List command of Workspaces REST API - you can call your local workspace with something like this (this code doesn't include parsing of the output):

import requests
ctx = dbutils.notebook.entry_point.getDbutils().notebook().getContext()
host_name = ctx.tags().get("browserHostName").get()
host_token = ctx.apiToken().get()

response = requests.post(
    f'https://{host_name}/api/2.0/workspace/list',
    headers={'Authorization': f'Bearer {host_token}'},
    data = {'path': '<your-path>'}
  ).json()
# add parsing of output here

Or you can use databricks workspace ls command from databricks-cli.

Related