Calendar¶
Calendar ¶
Calendar(auth: GoogleAuth, calendar_id: str = 'primary')
High-level Calendar client.
Example
auth = GoogleAuth() auth.authenticate()
cal = Calendar(auth)
Get upcoming events¶
for event in cal.get_upcoming(days=7): print(f"{event.start}: {event.summary}")
Create event¶
cal.create_event( summary="Meeting", start=datetime(2026, 1, 30, 10, 0), end=datetime(2026, 1, 30, 11, 0), )
Initialize Calendar client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth
|
GoogleAuth
|
GoogleAuth instance with valid credentials |
required |
calendar_id
|
str
|
Default calendar ID ("primary" for main calendar) |
'primary'
|
iter_events ¶
iter_events(time_min: datetime | None = None, time_max: datetime | None = None, calendar_id: str | None = None, max_results: int | None = 250, single_events: bool = True, order_by: str = 'startTime') -> Iterator[Event]
Lazily yield events in a time range, following result pages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_min
|
datetime | None
|
Start of range (default: now). Naive datetimes are UTC. |
None
|
time_max
|
datetime | None
|
End of range |
None
|
calendar_id
|
str | None
|
Calendar ID (default: primary) |
None
|
max_results
|
int | None
|
Maximum events to yield (None = all) |
250
|
single_events
|
bool
|
Expand recurring events |
True
|
order_by
|
str
|
Sort order (startTime or updated) |
'startTime'
|
get_events ¶
get_events(time_min: datetime | None = None, time_max: datetime | None = None, calendar_id: str | None = None, max_results: int | None = 250, single_events: bool = True, order_by: str = 'startTime') -> list[Event]
Get events in a time range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_min
|
datetime | None
|
Start of range (default: now). Naive datetimes are UTC. |
None
|
time_max
|
datetime | None
|
End of range |
None
|
calendar_id
|
str | None
|
Calendar ID (default: primary) |
None
|
max_results
|
int | None
|
Maximum events to return (None = all) |
250
|
single_events
|
bool
|
Expand recurring events |
True
|
order_by
|
str
|
Sort order (startTime or updated) |
'startTime'
|
Returns:
| Type | Description |
|---|---|
list[Event]
|
List of Event objects |
get_upcoming ¶
get_upcoming(days: int = 7, calendar_id: str | None = None, max_results: int = 100) -> list[Event]
Get upcoming events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
days
|
int
|
Number of days ahead (default: 7) |
7
|
calendar_id
|
str | None
|
Calendar ID |
None
|
max_results
|
int
|
Maximum events |
100
|
Returns:
| Type | Description |
|---|---|
list[Event]
|
List of upcoming events |
get_today ¶
get_today(calendar_id: str | None = None) -> list[Event]
Get today's events, where "today" is in GSUITE_DEFAULT_TIMEZONE.
sync ¶
sync(sync_token: str | None = None, calendar_id: str | None = None, single_events: bool = True) -> EventsDelta
Events changed or cancelled since sync_token (every event without one).
The API allows no time range with sync tokens, so the first sync lists
the whole calendar; later ones return only what changed. Keep
delta.sync_token for the next call, with the same single_events.
Raises:
| Type | Description |
|---|---|
SyncTokenExpiredError
|
Google invalidated the token (410); sync again without it. |
watch ¶
watch(address: str, token: str, calendar_id: str | None = None, channel_id: str | None = None, ttl: int | None = None) -> Channel
Have Google POST to address whenever an event of the calendar changes.
The notification has no body: call sync() with the token you kept
to get what changed. Google sends token back in
X-Goog-Channel-Token; check it, the notification isn't signed.
Channels expire (channel.expiration) and aren't renewed: watch
again before then and stop the old channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
HTTPS URL that receives the notifications |
required |
token
|
str
|
Secret to verify them with |
required |
calendar_id
|
str | None
|
Calendar to watch (default: the client's) |
None
|
channel_id
|
str | None
|
Your ID for the channel (default: a random UUID) |
None
|
ttl
|
int | None
|
Seconds the channel should live (Google caps it) |
None
|
stop_channel ¶
stop_channel(channel: Channel | str, resource_id: str | None = None) -> None
Stop a notification channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
Channel | str
|
The Channel |
required |
resource_id
|
str | None
|
The channel's |
None
|
get_event ¶
get_event(event_id: str, calendar_id: str | None = None) -> Event | None
Get a specific event by ID.
create_event ¶
create_event(summary: str, start: datetime | date, end: datetime | date | None = None, description: str | None = None, location: str | None = None, attendees: list[str] | None = None, calendar_id: str | None = None, all_day: bool = False, recurrence: list[str] | None = None, meet: bool = False, send_updates: SendUpdates = 'none') -> Event
Create a new event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary
|
str
|
Event title |
required |
start
|
datetime | date
|
Start time (datetime) or date (for all-day) |
required |
end
|
datetime | date | None
|
End time (default: start + 1 hour) |
None
|
description
|
str | None
|
Event description |
None
|
location
|
str | None
|
Event location |
None
|
attendees
|
list[str] | None
|
List of attendee emails |
None
|
calendar_id
|
str | None
|
Calendar to create in |
None
|
all_day
|
bool
|
Create as all-day event |
False
|
recurrence
|
list[str] | None
|
RRULE lines, e.g. ["RRULE:FREQ=WEEKLY;BYDAY=MO,WE"] |
None
|
meet
|
bool
|
Attach a new Google Meet link (see Event.meet_link) |
False
|
send_updates
|
SendUpdates
|
Email attendees: "all", "externalOnly" or "none" |
'none'
|
Returns:
| Type | Description |
|---|---|
Event
|
Created Event |
quick_add ¶
quick_add(text: str, calendar_id: str | None = None, send_updates: SendUpdates = 'none') -> Event
Create an event from natural language: "Lunch with Ana tomorrow at 1pm".
update_event ¶
update_event(event_id: str, summary: str | None = None, start: datetime | date | None = None, end: datetime | date | None = None, description: str | None = None, location: str | None = None, attendees: list[str] | None = None, all_day: bool = False, calendar_id: str | None = None, send_updates: SendUpdates = 'none') -> Event
Change an event. Only the arguments you pass are updated.
Moving an event: pass start (and end, or it becomes 1 hour long). attendees replaces the whole list.
Returns:
| Type | Description |
|---|---|
Event
|
The updated Event |
get_instances ¶
get_instances(event_id: str, time_min: datetime | None = None, time_max: datetime | None = None, max_results: int | None = 250, calendar_id: str | None = None) -> list[Event]
Occurrences of a recurring event (optionally within a time range).
get_free_busy ¶
get_free_busy(time_min: datetime, time_max: datetime, calendars: list[str] | None = None) -> FreeBusy
Busy intervals per calendar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calendars
|
list[str] | None
|
Calendar IDs or emails ("me" = your primary calendar). Default: this client's calendar. |
None
|
Returns:
| Type | Description |
|---|---|
FreeBusy
|
{calendar: [{"start": datetime, "end": datetime}, ...]}. A calendar |
FreeBusy
|
you can't see comes back with no busy times and a logged warning. |
delete_event ¶
delete_event(event_id: str, calendar_id: str | None = None, send_updates: SendUpdates = 'none') -> bool
Delete an event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
send_updates
|
SendUpdates
|
Email attendees about the cancellation: "all", "externalOnly" or "none" |
'none'
|
Returns:
| Type | Description |
|---|---|
bool
|
True if deleted, False if it didn't exist. Other failures (auth, |
bool
|
rate limit, ...) raise instead of looking like "not found". |
AsyncCalendar ¶
AsyncCalendar(auth: Any, calendar_id: str = 'primary', *, timeout: float | None = None, transport: Any = None)
Async Calendar client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth
|
Any
|
GoogleAuth (OAuth or service account) or google-auth credentials |
required |
calendar_id
|
str
|
Default calendar ID ("primary" for the main calendar) |
'primary'
|
timeout
|
float | None
|
Seconds per request (default: GSUITE_REQUEST_TIMEOUT) |
None
|
transport
|
Any
|
httpx transport (tests) |
None
|
iter_events
async
¶
iter_events(time_min: datetime | None = None, time_max: datetime | None = None, calendar_id: str | None = None, max_results: int | None = 250, single_events: bool = True, order_by: str = 'startTime') -> AsyncIterator[Event]
Lazily yield events in a time range (default: from now), following result pages.
get_events
async
¶
get_events(time_min: datetime | None = None, time_max: datetime | None = None, calendar_id: str | None = None, max_results: int | None = 250, single_events: bool = True, order_by: str = 'startTime') -> list[Event]
Events in a time range (naive datetimes are UTC; None = all).
get_upcoming
async
¶
get_upcoming(days: int = 7, calendar_id: str | None = None, max_results: int = 100) -> list[Event]
Events in the next days days.
get_today
async
¶
get_today(calendar_id: str | None = None) -> list[Event]
Today's events, where "today" is in GSUITE_DEFAULT_TIMEZONE.
sync
async
¶
sync(sync_token: str | None = None, calendar_id: str | None = None, single_events: bool = True) -> EventsDelta
Events changed or cancelled since sync_token (see Calendar.sync).
Raises:
| Type | Description |
|---|---|
SyncTokenExpiredError
|
Google invalidated the token; sync again without it. |
watch
async
¶
watch(address: str, token: str, calendar_id: str | None = None, channel_id: str | None = None, ttl: int | None = None) -> Channel
Have Google POST to address when the calendar changes (see Calendar.watch).
stop_channel
async
¶
stop_channel(channel: Channel | str, resource_id: str | None = None) -> None
Stop a notification channel (the Channel, or its ID and resource ID).
get_event
async
¶
get_event(event_id: str, calendar_id: str | None = None) -> Event | None
An event by ID, or None if it doesn't exist.
get_instances
async
¶
get_instances(event_id: str, time_min: datetime | None = None, time_max: datetime | None = None, max_results: int | None = 250, calendar_id: str | None = None) -> list[Event]
Occurrences of a recurring event (optionally within a time range).
get_free_busy
async
¶
get_free_busy(time_min: datetime, time_max: datetime, calendars: list[str] | None = None) -> FreeBusy
Busy intervals per calendar ("me" = your primary; default: this client's).
create_event
async
¶
create_event(summary: str, start: datetime | date, end: datetime | date | None = None, description: str | None = None, location: str | None = None, attendees: list[str] | None = None, calendar_id: str | None = None, all_day: bool = False, recurrence: list[str] | None = None, meet: bool = False, send_updates: SendUpdates = 'none') -> Event
Create an event (same arguments as Calendar.create_event).
quick_add
async
¶
quick_add(text: str, calendar_id: str | None = None, send_updates: SendUpdates = 'none') -> Event
Create an event from natural language: "Lunch with Ana tomorrow at 1pm".
update_event
async
¶
update_event(event_id: str, summary: str | None = None, start: datetime | date | None = None, end: datetime | date | None = None, description: str | None = None, location: str | None = None, attendees: list[str] | None = None, all_day: bool = False, calendar_id: str | None = None, send_updates: SendUpdates = 'none') -> Event
Change an event; only the arguments you pass are updated.
delete_event
async
¶
delete_event(event_id: str, calendar_id: str | None = None, send_updates: SendUpdates = 'none') -> bool
Delete an event; False if it didn't exist (other failures raise).
Event
dataclass
¶
Event(id: str, summary: str, description: str | None = None, location: str | None = None, start: datetime | None = None, end: datetime | None = None, all_day: bool = False, recurring: bool = False, recurrence: list[str] | None = None, attendees: list[Attendee] = list(), organizer: str | None = None, calendar_id: str = 'primary', html_link: str | None = None, status: str = 'confirmed', meet_link: str | None = None, timezone: str | None = None, created: datetime | None = None, updated: datetime | None = None, creator: str | None = None, recurring_event_id: str | None = None, ical_uid: str | None = None, original_start: datetime | None = None, organizer_name: str | None = None, organizer_self: bool = False, raw: dict[str, Any] = dict())
Calendar event.
Represents a single calendar event with all its metadata.
duration_minutes
property
¶
duration_minutes: int | None
Get event duration in minutes.
If only one of start/end has a timezone (an Event built by hand), the naive one is taken as UTC rather than raising TypeError.
CalendarEntity
dataclass
¶
CalendarEntity(id: str, summary: str, description: str | None = None, time_zone: str | None = None, primary: bool = False, access_role: str = 'reader', background_color: str | None = None, foreground_color: str | None = None)
EventsDelta
dataclass
¶
EventsDelta(changed: list[Event] = list(), cancelled: list[Event] = list(), sync_token: str | None = None)
Events changed or cancelled since a sync token (every event on the first sync).
Deleted events come back cancelled, often with little more than their ID.
Keep sync_token and pass it to the next Calendar.sync.