Download a file
This recipe downloads a file from a Unity Catalog volume using the Databricks SDK for Python.
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 catalogUSE SCHEMA
on the volume's schemaREAD VOLUME
on the volume
See Privileges required for volume operations for more information.
Dependencies
- Databricks SDK for Python -
databricks-sdk
- Streamlit -
streamlit
requirements.txt
databricks-sdk
streamlit