> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Google drive integration

> Integrate with the Google drive tool using LangChain Python.

This notebook walks through connecting a LangChain to the `Google Drive API`.

## Prerequisites

1. Create a Google Cloud project or use an existing project
2. Enable the [Google Drive API](https://console.cloud.google.com/flows/enableapi?apiid=drive.googleapis.com)
3. [Authorize credentials for desktop app](https://developers.google.com/drive/api/quickstart/python#authorize_credentials_for_a_desktop_application)
4. `pip install -U google-api-python-client google-auth-httplib2 google-auth-oauthlib`

## Instructions for retrieving your Google docs data

By default, the `GoogleDriveTools` and `GoogleDriveWrapper` expects the `credentials.json` file to be `~/.credentials/credentials.json`, but this is configurable by setting the `GOOGLE_ACCOUNT_FILE` environment variable to your `custom/path/to/credentials.json`.
The location of `token.json` use the same directory (or use the parameter `token_path`). Note that `token.json` will be created automatically the first time you use the tool.

`GoogleDriveSearchTool` can retrieve a selection of files with some requests.

By default, If you use a `folder_id`, all the files inside this folder can be retrieved to `Document`, if the name match the query.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU  google-api-python-client google-auth-httplib2 google-auth-oauthlib
```

You can obtain your folder and document id from the URL:

* Folder: [drive.google.com/drive/u/0/folders/1yucgL9WGgWZdM1TOuKkeghlPizuzMYb5](https://drive.google.com/drive/u/0/folders/1yucgL9WGgWZdM1TOuKkeghlPizuzMYb5) -> folder id is `"1yucgL9WGgWZdM1TOuKkeghlPizuzMYb5"`
* Document: [docs.google.com/document/d/1bfaMQ18\_i56204VaQDVeAFpqEijJTgvurupdEDiaUQw/edit](https://docs.google.com/document/d/1bfaMQ18_i56204VaQDVeAFpqEijJTgvurupdEDiaUQw/edit) -> document id is `"1bfaMQ18_i56204VaQDVeAFpqEijJTgvurupdEDiaUQw"`

The special value `root` is for your personal home.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
folder_id = "root"
# folder_id='1yucgL9WGgWZdM1TOuKkeghlPizuzMYb5'
```

By default, all files with these mime-type can be converted to `Document`.

* text/text
* text/plain
* text/html
* text/csv
* text/markdown
* image/png
* image/jpeg
* application/epub+zip
* application/pdf
* application/rtf
* application/vnd.google-apps.document (GDoc)
* application/vnd.google-apps.presentation (GSlide)
* application/vnd.google-apps.spreadsheet (GSheet)
* application/vnd.google.colaboratory (Notebook colab)
* application/vnd.openxmlformats-officedocument.presentationml.presentation (PPTX)
* application/vnd.openxmlformats-officedocument.wordprocessingml.document (DOCX)

It's possible to update or customize this. See the documentation of `GoogleDriveAPIWrapper`.

The corresponding packages must be installed.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU  unstructured langchain-googledrive
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import os

from langchain_googledrive.tools.google_drive.tool import GoogleDriveSearchTool
from langchain_googledrive.utilities.google_drive import GoogleDriveAPIWrapper

os.environ["GOOGLE_ACCOUNT_FILE"] = "custom/path/to/credentials.json"

# By default, search only in the filename.
tool = GoogleDriveSearchTool(
    api_wrapper=GoogleDriveAPIWrapper(
        folder_id=folder_id,
        num_results=2,
        template="gdrive-query-in-folder",  # Search in the body of documents
    )
)
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import logging

logging.basicConfig(level=logging.INFO)
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
tool.run("machine learning")
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
tool.description
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
"A wrapper around Google Drive Search. Useful for when you need to find a document in google drive. The input should be formatted as a list of entities separated with a space. As an example, a list of keywords is 'hello word'."
```

## Use the tool within a ReAct agent

In order to create an agent that uses the Google Jobs tool install LangGraph

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU langgraph langchain-openai
```

and use the [`create_agent`](https://reference.langchain.com/python/langchain/agents/factory/create_agent) functionality to initialize a ReAct agent. You will also need to set up your OPEN\_API\_KEY (visit [platform.openai.com](https://platform.openai.com)) in order to access OpenAI's chat models.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import os

from langchain.chat_models import init_chat_model
from langchain.agents import create_agent


os.environ["OPENAI_API_KEY"] = "your-openai-api-key"


model = init_chat_model("gpt-5.4-mini", model_provider="openai", temperature=0)
agent = create_agent(model, tools=[tool])

stream = agent.stream_events(
    {"messages": [("user", "Search in google drive, who is 'Yann LeCun' ?")]},
    version="v3",
)
for snapshot in stream.values:
    snapshot["messages"][-1].pretty_print()
```

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/tools/google_drive.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
