Skip to main content

Download a file

This recipe downloads a file from a Unity Catalog volume using the Databricks SDK for Python.

note

Unlike notebooks, Databricks Apps does not support mounting Unity Catalog volumes and directly reading and writing files. As this code snippet demonstrates, each file needs to be downloaded to the app compute before being able to manipulate it.

Code snippet

app.py
from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

download_file_path = "/Volumes/catalog/schema/volume_name/file.csv"
response = w.files.download(download_file_path)
file_data = response.contents.read()
file_name = os.path.basename(download_file_path)

Resources

Permissions

Your app service principal needs the following permissions:

  • USE CATALOG on the volume's catalog
  • USE SCHEMA on the volume's schema
  • READ VOLUME on the volume

See Privileges required for volume operations for more information.

Dependencies

requirements.txt
databricks-sdk
dash