Skip to main content

A LangChain toolkit for integrating Google Workspace (Gmail, Calendar, Tasks, Sheets, Drive)

Project description

GoogleSuiteToolkit for LangChain

A unified toolkit for integrating Google Workspace (Gmail, Calendar, Tasks, Sheets) with LangChain agents.

Features

  • Access Gmail, Google Calendar, Google Tasks, and Google Sheets via LangChain tools
  • Easy authentication using OAuth2 credentials
  • Simple API for tool retrieval and usage

Installation

  1. Clone this repository or copy the toolkit files into your project.
  2. Install dependencies:
pip install -r requirements.txt
  1. Set up your Google Cloud project and download credentials.json for OAuth2.

Usage

from langchain_gsuite import GoogleSuiteToolkit, build_gsuite_service, DEFAULT_SCOPES

# Basic usage
toolkit = GoogleSuiteToolkit()
print(toolkit.get_tools())
print(toolkit.get_tools_dict())

# Advanced: Customizing Google API resource
from google.oauth2.credentials import Credentials

# Example: Use custom scopes and credentials
custom_scopes = [
	"https://www.googleapis.com/auth/gmail.readonly",
	"https://www.googleapis.com/auth/calendar",
]
creds = Credentials.from_authorized_user_file("path/to/credentials.json", custom_scopes)
api_resource = build_gsuite_service(
	credentials=creds,
	service_name="gmail",  # or 'calendar', 'sheets', 'tasks'
	service_version="v1",
	scopes=custom_scopes
)

Required OAuth Scopes

Depending on the Google Workspace services you want to access, you must provide the appropriate OAuth scopes. Here are some common scopes:

  • Gmail: https://mail.google.com/ or https://www.googleapis.com/auth/gmail.readonly
  • Calendar: https://www.googleapis.com/auth/calendar
  • Sheets: https://www.googleapis.com/auth/spreadsheets
  • Drive (readonly): https://www.googleapis.com/auth/drive.readonly
  • Tasks: https://www.googleapis.com/auth/tasks

The toolkit provides two lists for convenience:

  • DEFAULT_SCOPES: Full access for all supported services
  • DEFAULT_SERVICE_SCOPES: Read-only access for all supported services

You can pass your own list of scopes to build_gsuite_service if you want to restrict or expand permissions.

Customizing build_gsuite_service

The build_gsuite_service function supports the following parameters:

  • credentials: (Optional) A google.oauth2.credentials.Credentials object. If not provided, credentials will be loaded automatically.
  • service_name: (str) The Google API service name (e.g., 'gmail', 'calendar', 'sheets', 'tasks').
  • service_version: (str) The API version (default: 'v1').
  • use_domain_wide: (bool) Use domain-wide delegation (for service accounts).
  • delegated_user: (Optional[str]) User to delegate domain-wide authority to.
  • service_account_file: (Optional[str]) Path to service account file.
  • scopes: (Optional[List[str]]) List of OAuth2 scopes. If not provided, defaults to DEFAULT_SCOPES or DEFAULT_SERVICE_SCOPES.

See the docstring in utils.py for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gsuite_langchain_tools-0.1.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gsuite_langchain_tools-0.1.0-py3-none-any.whl (2.5 kB view details)

Uploaded Python 3

File details

Details for the file gsuite_langchain_tools-0.1.0.tar.gz.

File metadata

  • Download URL: gsuite_langchain_tools-0.1.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for gsuite_langchain_tools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6275d2387219c817af9e6d98fb22b6f7b0e9ff969220ffbdac81d2c221d8f6ea
MD5 46087d90b7678f9c025b894ecb19fcfb
BLAKE2b-256 17b1182295116411e25f40c33bdb8e2c5b3ae887c851867f5e71c5b535d046c8

See more details on using hashes here.

File details

Details for the file gsuite_langchain_tools-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gsuite_langchain_tools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f897b5e7a3da052fbd8bb794d31bfdcfbee5e4fc06e2bbc02093d0538ec9064
MD5 81a4919d309cb5e510b3b945d496bd9d
BLAKE2b-256 e7321090260de7b12f6f284767dd772caa1d73b5c7baac7ec88e017ca828607a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page