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)

Specify range of listed events in two ways:

gc.get_events(start_date, end_date, order_by='updated')

or

gc[start_date:end_date:'updated']

start_date and end_date 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):

gc.get_events(query='Meeting')
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.

gc.get_events(single_events=True)

Get event by id

gc.get_event('<event_id>')

List recurring event instances

gc.get_instances('<recurring_event_id>')

or

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.

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:

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'
gc.update_event(event)

Import 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

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>')