Calapi 1.0.0

A light weight python wrapper for Google’s Calendar API v3 written upon Google’s API Python Client.

Features provided by Calapi

  • Documented functions and usage instructions.

  • Pythonic style usage.


Installation

To install, simply use pip or easy_install:

$ pip install calapi

or:

$ easy_install calapi

Acquire Google Oauth credentials

1. Create a new project on google console dashboard on below link

https://console.cloud.google.com/apis/dashboard

2. Enable Google Calendar API on the below link

https://console.cloud.google.com/apis/library/calendar-json.googleapis.com

3. Configure Oauth Consent Screen

3. Create Oauth Client ID credentials for Users consent


Get Started

Instantiate Calapi Oauth Instance

from calapi import Oauth
client = Oauth(
  credentials_path='./credentials.json',
  scopes=[
    'openid',
    'https://www.googleapis.com/auth/userinfo.email',
    'https://www.googleapis.com/auth/userinfo.profile',
    'https://www.googleapis.com/auth/calendar.events',
    'https://www.googleapis.com/auth/calendar',
    'https://www.googleapis.com/auth/calendar.readonly'
  ]
)

Instantiate Session Object for user

from calapi import Session
session = Session(session_credentials=session_credentials)

Using Events API

(Refer Google’s docs: https://developers.google.com/calendar/v3/reference/events) (Get all the usage information for events api using below line)

help(session.events)

Create Event on Users Calendar

# Generate query for inserting
query = session.events.query.start(
            date_time='2021-06-03T09:00:00-07:00',
            time_zone='America/Los_Angeles'
        ).end(
            date_time='2021-06-03T09:30:00-07:00',
            time_zone='America/Los_Angeles'
        ).attendees([
            {'email': 'lp_age@example.com'},
            {'email': 'sbrin@example.com'},
        ]).summary(
            'Google I/O 2015'
        ).description(
            '800 Howard St., San Francisco, CA 94103'
        ).recurrence([
            'RRULE:FREQ=DAILY;COUNT=2'
        ]).reminders({
            'use_default': False,
            'overrides': [
                {'method': 'email', 'minutes': 24 * 60},
                {'method': 'popup', 'minutes': 10},
            ],
        })
# Insert to the calendar
created_event = session.events.insert(query)

Get Event using event id

event = session.events.get(event_id)

Update Event using event id

query = session.events.query.summary(
                'Updated summary Google I/O 2015'
            ).description(
                'Updated description 800 Howard St., San Francisco, CA 94103'
            )
resp = session.events.update(event_id, query)

Delete Event

resp = session.events.delete(event_id)

Using Calendars API

(Refer Google’s docs: https://developers.google.com/calendar/v3/reference/calendars)

Get all the usage information for calendars api using below line

help(session.calendars)

Create Secondary Calendar

# Generate query for inserting
query = session.events.query.summary(
            'calendarSummary'
        ).time_zone(
            'America/Los_Angeles'
        )
# Insert Secondary calendar
calendar = session.calendars.insert(query)

Get metadata for a calendar

resp = session.calendars.get(calendar_id)

Update metadata for a calendar

query = session.calendars.query.summary(
                    'New Summary'
                )
resp = session.calendars.update(query)

Delete a secondary calendar

resp = session.calendars.get(calendar_id)

For all the apis, calapi provides all the usage information in respected help function

To learn about the usage for other apis, use below lines of code

# For Oauth usage instruction
help(calapi.Oauth)

# For Session usage instruction
help(calapi.Session)

# For ACL Api usage instruction
help(session.acl)

# For Calendar List Api usage instruction
help(session.calendarlist)

# For Calendars Api usage instruction
help(session.calendars)

# For Settings Api usage instruction
help(session.settings)

# For Colors Api usage instruction
help(session.colors)

# For Events Api usage instruction
help(session.events)

(Note: I tried to cover all the basic details which are required by each api in the docs. If there are any missing docs, please feel free to report in the issue section)


To-Dos

  • Test cases.

Contribute

  1. Look for an open issue or create new issue to get a dialog going about the new feature or bug that you’ve discovered.

  2. Fork the repository on Github to start making your changes to the master branch (or branch off of it).

  3. Write a test which shows that the bug was fixed or that the feature works as expected.

  4. Make a pull request.