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
import os
import streamlit as st
from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

download_file_path = st.text_input(
label="Path to file", placeholder="/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)

st.download_button(label="Download", data=file_data, file_name=file_name)

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.

If you declare volume access in a Databricks Asset Bundle, resources.apps[*].resources[*].uc_securable may not grant USE_CATALOG and USE_SCHEMA on the parent catalog and schema (the app still needs them at runtime). As a temporary workaround until bundles can declare those parent grants, add the privileges manually, or see apps_grants_sync: an example Databricks App and Asset Bundle that wires experimental.scripts.postdeploy so parent privileges are applied after each databricks bundle deploy (copy its tools/ into your bundle or mirror the same pattern in databricks.yml).

Dependencies

requirements.txt
databricks-sdk
streamlit