Free busy

With gcsa you can retrieve the free/busy information of the calendars and groups.

To do so, create a GoogleCalendar instance (see Getting started to get your credentials):

from gcsa.google_calendar import GoogleCalendar

gc = GoogleCalendar()

Then to retrieve a free/busy information of the calendar for the following two weeks starting now use get_free_busy():

free_busy = gc.get_free_busy()

this will return a FreeBusy object. If only one calendar has been requested (like in the example above, only “primary” calendar’s information has been requested), you can iterate over FreeBusy object directly:

for start, end in free_busy:
    print(f'Busy from {start} to {end}')

To request group(s) or different calendar(s) (other than one specified as default during GoogleCalendar creation), use resource_ids argument of get_free_busy():

free_busy = gc.get_free_busy('secondary_calendar_id@gmail.com')

for start, end in free_busy:
    print(f'Busy from {start} to {end}')

or

free_busy = gc.get_free_busy(
    [
        'primary',
        'secondary_calendar_id@gmail.com',
        'group_id'
    ]
)

print('Primary calendar:')
for start, end in free_busy.calendars['primary']:
    print(f'Busy from {start} to {end}')

print('Secondary calendar:')
for start, end in free_busy.calendars['secondary_calendar_id@gmail.com']:
    print(f'Busy from {start} to {end}')

print('Group info:')
for calendar in free_busy.groups['group_id']:
    print(f'{calendar}:')
    for start, end in free_busy.calendars[calendar]:
        print(f'Busy from {start} to {end}')

Some calendars or groups in the request might cause errors. By default gcsa will raise FreeBusyQueryError in case of any errors. But you can ignore them with ignore_errors argument:

free_busy = gc.get_free_busy(
    resource_ids=[
        'primary',
        'secondary_calendar_id@gmail.com',
        'group_id'
    ],
    ignore_errors=True
)

In that case, all the errors can be found in FreeBusy’s groups_errors and calendars_errors fields:

print(free_busy.groups_errors)
print(free_busy.calendars_errors)