eniwoke
Contributor II

Hi alexkychen, assuming you have the file saved in DBFS in your Databricks workspace, you can read the file by getting the file's contents in DBFS via the Databricks API -> https://docs.databricks.com/api/workspace/dbfs/read

Here is a simple Python snippet that allows you to achieve this locally. This snippet uses a Personal access token, and prints the base64 encoded content of the file.

import requests
import json

DATABRICKS_HOST = 'https://<FILL_IN_DATABRICKS_HOST>'
DATABRICKS_TOKEN = '<FILL_IN_TOKEN>'

reqUrl = f"{DATABRICKS_HOST}/api/2.0/dbfs/read"

headersList = {
 f"Authorization": "Bearer {DATABRICKS_TOKEN}",
 "Content-Type": "application/json" 
}

payload = json.dumps({
  "path":"/dbfs/tmp/example_folder/test.csv"
})

response = requests.request("GET", reqUrl, data=payload,  headers=headersList)

# Print the content, which is Base64 encoded
print(response.text)

 Hope this helps 🙂

Eni