<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to read csv files stored in my Databricks workspace using a Python script in my local comput in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-read-csv-files-stored-in-my-databricks-workspace-using-a/m-p/83186#M36865</link>
    <description>&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;Hi&amp;nbsp;&lt;A href="https://community.databricks.com/t5/user/viewprofilepage/user-id/116189" target="_blank" rel="noopener"&gt;alexkychen,&lt;/A&gt;&amp;nbsp;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 -&amp;gt;&amp;nbsp;&lt;A href="https://docs.databricks.com/api/workspace/dbfs/read" target="_blank"&gt;https://docs.databricks.com/api/workspace/dbfs/read&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
import json

DATABRICKS_HOST = 'https://&amp;lt;FILL_IN_DATABRICKS_HOST&amp;gt;'
DATABRICKS_TOKEN = '&amp;lt;FILL_IN_TOKEN&amp;gt;'

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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Hope this helps &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Aug 2024 07:25:13 GMT</pubDate>
    <dc:creator>eniwoke</dc:creator>
    <dc:date>2024-08-16T07:25:13Z</dc:date>
    <item>
      <title>How to read csv files stored in my Databricks workspace using a Python script in my local computer?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-read-csv-files-stored-in-my-databricks-workspace-using-a/m-p/83153#M36856</link>
      <description>&lt;P&gt;I am developing a Python app on my local computer, and I would like to let it read some data stored in my Databricks workspace using preferably Pandas. The data are stored in .csv files in the workspace. How can I make this happen? Is it possible to achieve via file URL? A code snippet would be appreciated! Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 01:07:42 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-read-csv-files-stored-in-my-databricks-workspace-using-a/m-p/83153#M36856</guid>
      <dc:creator>alexkychen</dc:creator>
      <dc:date>2024-08-16T01:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to read csv files stored in my Databricks workspace using a Python script in my local comput</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-read-csv-files-stored-in-my-databricks-workspace-using-a/m-p/83186#M36865</link>
      <description>&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;Hi&amp;nbsp;&lt;A href="https://community.databricks.com/t5/user/viewprofilepage/user-id/116189" target="_blank" rel="noopener"&gt;alexkychen,&lt;/A&gt;&amp;nbsp;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 -&amp;gt;&amp;nbsp;&lt;A href="https://docs.databricks.com/api/workspace/dbfs/read" target="_blank"&gt;https://docs.databricks.com/api/workspace/dbfs/read&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
import json

DATABRICKS_HOST = 'https://&amp;lt;FILL_IN_DATABRICKS_HOST&amp;gt;'
DATABRICKS_TOKEN = '&amp;lt;FILL_IN_TOKEN&amp;gt;'

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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Hope this helps &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 07:25:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-read-csv-files-stored-in-my-databricks-workspace-using-a/m-p/83186#M36865</guid>
      <dc:creator>eniwoke</dc:creator>
      <dc:date>2024-08-16T07:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to read csv files stored in my Databricks workspace using a Python script in my local comput</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-read-csv-files-stored-in-my-databricks-workspace-using-a/m-p/83259#M36893</link>
      <description>&lt;P&gt;Hi Eni,&lt;/P&gt;&lt;P&gt;Thank you very much for your reply. I also did some research, but realized that storing sensitive data (which is in my case) in DBFS is no longer recommended by Databricks due to security reason as it states here:&amp;nbsp;&lt;A href="https://docs.databricks.com/en/files/index.html#work-with-files-in-dbfs-mounts-and-dbfs-root" target="_blank" rel="noopener"&gt;https://docs.databricks.com/en/files/index.html#work-with-files-in-dbfs-mounts-and-dbfs-root&lt;/A&gt;. I will look for other solutions to better store the data on Databricks and can be accessed locally and securely.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, your reply is much appreciated!&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 18:39:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-read-csv-files-stored-in-my-databricks-workspace-using-a/m-p/83259#M36893</guid>
      <dc:creator>alexkychen</dc:creator>
      <dc:date>2024-08-16T18:39:31Z</dc:date>
    </item>
  </channel>
</rss>

