Events
Event in gcsa is represented by the class Event. It stores all the needed information about
the event including its summary, starting and ending dates/times, attachments, reminders, recurrence rules, etc.
gcsa allows you to create a new events, retrieve, update, move and delete existing events.
To do so, create a GoogleCalendar instance (see Getting started to get your
credentials):
from gcsa.google_calendar import GoogleCalendar
gc = GoogleCalendar()
List events
This code will print out events for one year starting today:
for event in gc:
print(event)
Note
In the following examples, get_events() and
get_instances() return generators. You can iterate over them directly:
for event in gc.get_events():
print(event)
but to get the list of events use:
events = list(gc.get_events())
Specify range of listed events in two ways:
events = gc.get_events(time_min, time_max, order_by='updated')
or
events = gc[time_min:time_max:'updated']
time_min and time_max can be date or datetime objects. order_by can be ‘startTime’
or ‘updated’. If not specified, unspecified stable order is used.
Use query parameter for free text search through all event fields (except for extended properties):
events = gc.get_events(query='Meeting')
or
events = gc.get_events(query='John') # Name of attendee
Use single_events parameter to expand recurring events into instances and only return single one-off events and
instances of recurring events, but not the underlying recurring events themselves.
events = gc.get_events(single_events=True)
List recurring event instances
events = gc.get_instances('<recurring_event_id>')
or
events = gc.get_instances(recurring_event)
where recurring_event is Event object with set event_id. You’d probably get it from
the get_events method.
Get event by id
event = gc.get_event('<event_id>')
Create event
from beautiful_date import Apr, hours
from gcsa.event import Event
start = (22/Apr/2019)[12:00]
end = start + 2 * hours
event = Event('Meeting',
start=start,
end=end)
or to create an all-day event, use a date object:
from beautiful_date import Aug, days
from gcsa.event import Event
start = 1/Aug/2021
end = start + 7 * days
event = Event('Vacation',
start=start,
end=end)
For date/datetime objects you can use Pythons datetime module or as in the
example beautiful_date library (because it’s beautiful… just like you).
Now add your event to the calendar:
event = gc.add_event(event)
See dedicated pages on how to add Attendees, Attachments, Conference, Reminders, and Recurrence to an event.
Update event
event.location = 'Prague'
event = gc.update_event(event)
Import event
event = gc.import_event(event)
This operation is used to add a private copy of an existing event to a calendar.
Move event to another calendar
event = gc.move_event(event, destination_calendar_id='primary')
Delete event
gc.delete_event(event)
Event has to have event_id to be updated, moved, or deleted. Events that you get from
get_events() method already have their ids.
You can also delete the event by providing its id.
gc.delete_event('<event_id>')