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 reflex as rx
import os
from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
class DownloadFileState(rx.State):
download_file_path: str = ""
async def handle_download(self):
response = w.files.download(self.download_file_path)
file_data = response.contents.read()
file_name = os.path.basename(self.download_file_path)
return rx.download(data=file_data, filename=file_name)
Resources
Permissions
Your app service principal needs the following permissions:
USE CATALOGon the volume's catalogUSE SCHEMAon the volume's schemaREAD VOLUMEon the volume
See Privileges required for volume operations for more information.
Dependencies
- Databricks SDK for Python -
databricks-sdk - Reflex -
reflex
requirements.txt
databricks-sdk
reflex