A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://python.langchain.com/docs/integrations/tools/google_calendar below:

Google Calendar Toolkit | 🦜️🔗 LangChain

Google Calendar Toolkit

Google Calendar is a product of Google Workspace that allows users to organize their schedules and events. It is a cloud-based calendar that allows users to create, edit, and delete events. It also allows users to share their calendars with others.

Overview

This notebook will help you get started with the Google Calendar Toolkit. This toolkit interacts with the Google Calendar API to perform various operations on the calendar. It allows you to:

Setup

To use this toolkit, you will need to:

  1. Have a Google account with access to Google Calendar.
  2. Set up your credentials as explained in the Google Calendar API docs. Once you've downloaded the credentials.json file, you can start using the Google Calendar API.

To enable automated tracing of individual tools, set your LangSmith API key:

Installation

This toolkit lives in the langchain-google-community package of the langchain-google repository. We'll need the calendar extra:

%pip install -qU langchain-google-community\[calendar\]
Instantiation

By default the toolkit reads the local credentials.json file. You can also manually provide a Credentials object.

from langchain_google_community import CalendarToolkit

toolkit = CalendarToolkit()
Customizing Authentication

Behind the scenes, a googleapi resource is created using the following methods. you can manually build a googleapi resource for more auth control.

from langchain_google_community import CalendarToolkit
from langchain_google_community.calendar.utils import (
build_resource_service,
get_google_credentials,
)



credentials = get_google_credentials(
token_file="token.json",
scopes=["https://www.googleapis.com/auth/calendar"],
client_secrets_file="credentials.json",
)

api_resource = build_resource_service(credentials=credentials)
toolkit = CalendarToolkit(api_resource=api_resource)

View available tools:

tools = toolkit.get_tools()
tools
[CalendarCreateEvent(api_resource=<googleapiclient.discovery.Resource object at 0x10ad13fb0>),
CalendarSearchEvents(api_resource=<googleapiclient.discovery.Resource object at 0x10ad13fb0>),
CalendarUpdateEvent(api_resource=<googleapiclient.discovery.Resource object at 0x10ad13fb0>),
GetCalendarsInfo(api_resource=<googleapiclient.discovery.Resource object at 0x10ad13fb0>),
CalendarMoveEvent(api_resource=<googleapiclient.discovery.Resource object at 0x10ad13fb0>),
CalendarDeleteEvent(api_resource=<googleapiclient.discovery.Resource object at 0x10ad13fb0>),
GetCurrentDatetime(api_resource=<googleapiclient.discovery.Resource object at 0x10ad13fb0>)]
Invocation Invoke directly with args

You can invoke the tool directly by passing the required arguments in a dictionary format. Here is an example of creating a new event using the CalendarCreateEvent tool.

from langchain_google_community.calendar.create_event import CalendarCreateEvent

tool = CalendarCreateEvent()
tool.invoke(
{
"summary": "Calculus exam",
"start_datetime": "2025-07-11 11:00:00",
"end_datetime": "2025-07-11 13:00:00",
"timezone": "America/Mexico_City",
"location": "UAM Cuajimalpa",
"description": "Event created from the LangChain toolkit",
"reminders": [{"method": "popup", "minutes": 60}],
"conference_data": True,
"color_id": "5",
}
)
'Event created: https://www.google.com/calendar/event?eid=amoxdjVsM2UzMW51Yjk2czc4ajhvaGdkcGcgam9yZ2VhbmczM0Bt'
Use within an agent

Below we show how to incorporate the toolkit into an agent.

We will need a LLM or chat model:

pip install -qU "langchain[google-genai]"
import getpass
import os

if not os.environ.get("GOOGLE_API_KEY"):
os.environ["GOOGLE_API_KEY"] = getpass.getpass("Enter API key for Google Gemini: ")

from langchain.chat_models import init_chat_model

llm = init_chat_model("gemini-2.5-flash", model_provider="google_genai")
from langgraph.prebuilt import create_react_agent

agent_executor = create_react_agent(llm, tools)
example_query = "Create a green event for this afternoon to go for a 30-minute run."

events = agent_executor.stream(
{"messages": [("user", example_query)]},
stream_mode="values",
)
for event in events:
event["messages"][-1].pretty_print()
================================ Human Message =================================

Create a green event for this afternoon to go for a 30-minute run.
================================== Ai Message ==================================
Tool Calls:
get_current_datetime (call_drHRRhm6pdvcAuqagONUEKs5)
Call ID: call_drHRRhm6pdvcAuqagONUEKs5
Args:
================================= Tool Message =================================
Name: get_current_datetime

Time zone: America/Mexico_City, Date and time: 2025-04-02 19:07:30
================================== Ai Message ==================================
Tool Calls:
create_calendar_event (call_p60zSVMmmjTy5Ctezzmlb9zD)
Call ID: call_p60zSVMmmjTy5Ctezzmlb9zD
Args:
summary: Run
start_datetime: 2025-04-02 19:30:00
end_datetime: 2025-04-02 20:00:00
timezone: America/Mexico_City
color_id: 2
================================= Tool Message =================================
Name: create_calendar_event

Event created: https://www.google.com/calendar/event?eid=czZyZHVpcG43ajNiY241dmJmNWwycjE0NWsgam9yZ2VhbmczM0Bt
================================== Ai Message ==================================

I have created a green event for your run this afternoon. You can view it [here](https://www.google.com/calendar/event?eid=czZyZHVpcG43ajNiY241dmJmNWwycjE0NWsgam9yZ2VhbmczM0Bt). Enjoy your run!
API reference

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4