<?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: Creating a private connection with Google Sheets in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/creating-a-private-connection-with-google-sheets/m-p/97689#M39523</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/125102"&gt;@dtb_usr&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;You can share the Google Sheet with the Service Account and use&amp;nbsp;Google Sheets API Client&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Open the Google Sheet you want to access.&lt;/LI&gt;&lt;LI&gt;Click on &lt;STRONG&gt;Share&lt;/STRONG&gt; and add the email address of the service account (it will look something like your-service-account@your-project.iam.gserviceaccount.com).&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;U&gt;This step allows the service account to access the Google Sheet securely without making it public.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;To access Google Sheets from Databricks, you’ll need the &lt;STRONG&gt;Google API Python client&lt;/STRONG&gt;. You can install it in your Databricks notebook:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;%pip install --upgrade google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client pandas&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And now you can read data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
from google.oauth2 import service_account
from googleapiclient.discovery import build

# Path to the service account key JSON file
SERVICE_ACCOUNT_FILE = "/dbfs/path/to/your/service_account_key.json"  # Adjust the path as needed

# Set up the credentials
credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_FILE,
    scopes=["https://www.googleapis.com/auth/spreadsheets.readonly"]
)

# Google Sheets API setup
spreadsheet_id = 'your_spreadsheet_id'  # Replace with your Google Sheet ID
range_name = 'Sheet1!A1:D'  # Specify the range you want to pull

service = build('sheets', 'v4', credentials=credentials)
sheet = service.spreadsheets()

# Fetch data from Google Sheets
result = sheet.values().get(spreadsheetId=spreadsheet_id, range=range_name).execute()
values = result.get('values', [])

# Convert to DataFrame for further processing
if values:
    df = pd.DataFrame(values[1:], columns=values[0])  # Assuming the first row is headers
else:
    df = pd.DataFrame()

display(df)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Replace 'your_spreadsheet_id' with the &lt;STRONG&gt;ID of your Google Sheet&lt;/STRONG&gt; (the part of the URL between /d/ and /edit).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;</description>
    <pubDate>Tue, 05 Nov 2024 07:30:31 GMT</pubDate>
    <dc:creator>agallard2</dc:creator>
    <dc:date>2024-11-05T07:30:31Z</dc:date>
    <item>
      <title>Creating a private connection with Google Sheets</title>
      <link>https://community.databricks.com/t5/data-engineering/creating-a-private-connection-with-google-sheets/m-p/92974#M38598</link>
      <description>&lt;P&gt;How do I ingest sensitive data from a googlesheet doc to Databricks unity catalogue without making the googlesheet public.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2024 15:44:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/creating-a-private-connection-with-google-sheets/m-p/92974#M38598</guid>
      <dc:creator>dtb_usr</dc:creator>
      <dc:date>2024-10-07T15:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a private connection with Google Sheets</title>
      <link>https://community.databricks.com/t5/data-engineering/creating-a-private-connection-with-google-sheets/m-p/97689#M39523</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/125102"&gt;@dtb_usr&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;You can share the Google Sheet with the Service Account and use&amp;nbsp;Google Sheets API Client&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Open the Google Sheet you want to access.&lt;/LI&gt;&lt;LI&gt;Click on &lt;STRONG&gt;Share&lt;/STRONG&gt; and add the email address of the service account (it will look something like your-service-account@your-project.iam.gserviceaccount.com).&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;U&gt;This step allows the service account to access the Google Sheet securely without making it public.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;To access Google Sheets from Databricks, you’ll need the &lt;STRONG&gt;Google API Python client&lt;/STRONG&gt;. You can install it in your Databricks notebook:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;%pip install --upgrade google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client pandas&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And now you can read data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
from google.oauth2 import service_account
from googleapiclient.discovery import build

# Path to the service account key JSON file
SERVICE_ACCOUNT_FILE = "/dbfs/path/to/your/service_account_key.json"  # Adjust the path as needed

# Set up the credentials
credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_FILE,
    scopes=["https://www.googleapis.com/auth/spreadsheets.readonly"]
)

# Google Sheets API setup
spreadsheet_id = 'your_spreadsheet_id'  # Replace with your Google Sheet ID
range_name = 'Sheet1!A1:D'  # Specify the range you want to pull

service = build('sheets', 'v4', credentials=credentials)
sheet = service.spreadsheets()

# Fetch data from Google Sheets
result = sheet.values().get(spreadsheetId=spreadsheet_id, range=range_name).execute()
values = result.get('values', [])

# Convert to DataFrame for further processing
if values:
    df = pd.DataFrame(values[1:], columns=values[0])  # Assuming the first row is headers
else:
    df = pd.DataFrame()

display(df)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Replace 'your_spreadsheet_id' with the &lt;STRONG&gt;ID of your Google Sheet&lt;/STRONG&gt; (the part of the URL between /d/ and /edit).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 07:30:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/creating-a-private-connection-with-google-sheets/m-p/97689#M39523</guid>
      <dc:creator>agallard2</dc:creator>
      <dc:date>2024-11-05T07:30:31Z</dc:date>
    </item>
  </channel>
</rss>

