Integrate Google Services with LlamaIndex
Load data from Google Drive, Docs, Sheets, Chat, Maps, and more into LlamaIndex.
Why it matters
Seamlessly connect LlamaIndex to various Google services, enabling efficient data extraction and indexing for advanced AI applications.
Outcomes
What it gets done
Load data from Google Drive, Docs, Sheets, Gmail, Chat, and Maps.
Extract information and content from Google services.
Prepare data for indexing and retrieval within LlamaIndex.
Facilitate data querying and analysis across integrated Google sources.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/li-reader-readers-google | bash Overview
LlamaIndex Integration: Google Readers
A bundle of LlamaIndex readers for Google Drive, Docs, Sheets, Gmail, Chat, Calendar, Keep, and Maps, authenticated via Google Cloud OAuth. Use when indexing content from one or more Google Workspace services through a single consistent integration.
What it does
The Google Readers Integration bundles a set of Google-based data loaders for LlamaIndex, covering Google Calendar, Google Chat, Google Docs, Google Drive, Gmail, Google Keep, Google Maps, and Google Sheets. It now supports more advanced operations through ResourcesReaderMixin and FileSystemReaderMixin, letting some readers do more than a one-shot bulk load.
GoogleDriveReader, initialized with a folder_id and a service_account_key, illustrates this extended capability: beyond load_data() to load everything, it exposes list_resources() to enumerate what's in the drive, get_resource_info() for details on one resource, load_resource() to load a single named resource, and read_file_content() to read a file's raw content directly. GoogleDocsReader loads a specific set of documents by their document_ids. GoogleSheetsReader can load a list of spreadsheets either as standard LlamaIndex Documents via load_data() or as Pandas dataframes via load_data_in_pandas(), so tabular data can be worked with in whichever form fits the downstream task. GoogleMapsTextSearchReader runs a text-based location search - the source's example searches for quality Turkish food in Istanbul with a capped number_of_results - and indexes the returned places. GoogleChatReader loads messages from named chat spaces by space_names.
Authentication runs through a credentials.json file obtained from Google Cloud: creating a project in Google Cloud Console, enabling the relevant API (for example Gmail) under APIs & Services, creating an OAuth client ID as a web application with http://localhost:8080/ as the authorized redirect URI, and setting the OAuth consent screen to external so personal Google data can be connected once the user is added as an allowed test user.
When to use - and when NOT to
Use it when you need to bring content from one or more Google Workspace services into LlamaIndex - documents, spreadsheets, drive files, chat history, or location search results - through a single integration rather than separate per-service clients. Use GoogleDriveReader's resource-level methods (list_resources, get_resource_info, load_resource) when you need to inspect or selectively load specific files rather than pulling the whole folder. Do not use it without first completing the Google Cloud OAuth setup and obtaining credentials.json - none of the readers can authenticate without it.
Capabilities
Eight Google service readers: Calendar, Chat, Docs, Drive (with resource-level list/inspect/load/read operations), Gmail, Keep, Maps (text search), and Sheets (as documents or Pandas dataframes).
How to install
pip install llama-index-readers-google
Requires a credentials.json file from a Google Cloud project with the relevant API enabled and an OAuth client ID configured for external test users.
Who it's for
Developers who need to index content from one or more Google Workspace services - Drive, Docs, Sheets, Gmail, Chat, Calendar, Keep, or Maps - into a LlamaIndex pipeline through one consistent integration.
Source README
LlamaIndex Integration: Google Readers
Effortlessly incorporate Google-based data loaders into your Python workflow using LlamaIndex. It now supports more advanced operations through the implementation of ResourcesReaderMixin and FileSystemReaderMixin.
Unlock the potential of various readers to enhance your data loading capabilities, including:
- Google Calendar
- Google Chat
- Google Docs
- Google Drive
- Gmail
- Google Keep
- Google Maps
- Google Sheets
Installation
pip install llama-index-readers-google
Authentication
You will need a credentials.json file from Google Cloud to interact with Google Services. To get this file, follow these steps:
- Create a new project in the Google Cloud Console
- Go to APIs & Services -> Library and search for the API you want, e.g. Gmail
- Go to APIs & Services -> Credentials and create a new OAuth client ID
- Application type: Web application
- Authorized redirect URIs: http://localhost:8080/ (the last slash seems important)
- Go to APIs & Services -> OAuth consent screen and make the app external, which allows you to connect your personal Google data once you explicitly add yourself as an allowed test user
- Download the credentials JSON file from this screen and save it as
credentials.jsonin the root of your project
See this example for a sample of code that successfully authenticates with Gmail once you have the credentials.json file.
Examples
Google Drive Reader
from llama_index.readers.google import GoogleDriveReader
### Initialize the reader
reader = GoogleDriveReader(
folder_id="folder_id",
service_account_key="[SERVICE_ACCOUNT_KEY_JSON]",
)
### Load data
documents = reader.load_data()
### List resources in the drive
resources = reader.list_resources()
### Get information about a specific resource
resource_info = reader.get_resource_info("file.txt")
### Load a specific resource
specific_doc = reader.load_resource("file.txt")
### Read file content directly
file_content = reader.read_file_content("path/to/file.txt")
print(f"Loaded {len(documents)} documents")
print(f"Found {len(resources)} resources")
print(f"Resource info: {resource_info}")
print(f"Specific document: {specific_doc}")
print(f"File content length: {len(file_content)} bytes")
Google Docs Reader
from llama_index.readers.google import GoogleDocsReader
### Specify the document IDs you want to load
document_ids = ["<document_id>"]
### Load data from Google Docs
documents = GoogleDocsReader().load_data(document_ids=document_ids)
Google Sheets Reader (Documents and Dataframes)
from llama_index.readers.google import GoogleSheetsReader
### Specify the list of sheet IDs you want to load
list_of_sheets = ["spreadsheet_id"]
### Create a Google Sheets Reader instance
sheets_reader = GoogleSheetsReader()
### Load data into Pandas in Data Classes of choice (Documents or Dataframes)
documents = sheets.load_data(list_of_sheets)
dataframes = sheets_reader.load_data_in_pandas(list_of_sheets)
Integrate these readers seamlessly to efficiently manage and process your data within your Python environment, providing a robust foundation for your data-driven workflows with LlamaIndex.
Google Maps Text Search Reader
from llama_index.readers.google import GoogleMapsTextSearchReader
from llama_index.core import VectorStoreIndex
loader = GoogleMapsTextSearchReader()
documents = loader.load_data(
text="I want to eat quality Turkish food in Istanbul",
number_of_results=160,
)
index = VectorStoreIndex.from_documents(documents)
index.query("Which Turkish restaurant has the best reviews?")
Google Chat Reader
from llama_index.readers.google import GoogleChatReader
from llama_index.core import VectorStoreIndex
space_names = ["<CHAT_ID>"]
chatReader = GoogleChatReader()
docs = chatReader.load_data(space_names=sp
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.