Most people have more than one calendar attached to their Google account — a work one, a personal one, and the birthdays one Google auto-creates. How would you count them from Python?
Same shape as counting emails? Call an action, get a list back, use len() on whatever list comes out?
Exactly. The action is GOOGLECALENDAR_LIST_CALENDARS and the response shape is {"items": [...]} — the list lives under items instead of messages. Otherwise the pattern is identical to your Gmail counter:
result = toolset.execute_action(Action.GOOGLECALENDAR_LIST_CALENDARS, {})
count = len(result.get("items", []))So every API parks its list under a different key? Gmail uses messages, Calendar uses items — do I have to memorize those keys for every new endpoint?
You skim them from the docs once per API. The defensive .get(key, []) pattern works whatever the key is — swap the string, the skeleton stands:
def count_calendars() -> int:
result = toolset.execute_action(Action.GOOGLECALENDAR_LIST_CALENDARS, {})
return len(result.get("items", []))The params dict is empty — is that a problem? Will the action reject it?
Not at all. Some actions need no parameters; listing calendars is one of them. You still pass {} so the shape of the call matches every other action. An empty dict is a parameter, not a missing one.
So everything I learned from Week 1 just works — I only look up the action name and the response key?
That is the transfer. The skeleton carries the logic. The enums carry the semantics. Different API, same muscle.
TL;DR: Every Google API puts its list under a different key — .get(key, []) handles all of them with one string swap.
Action.GOOGLECALENDAR_LIST_CALENDARS swaps for Gmail's equivalent{} means no filter, not a missing argument{"items": [...]}, one entry per calendar on the account| API | List key |
|---|---|
| Gmail | messages |
| Calendar | items |
| Tasks | items |
| Sheets | spreadsheets |
Create a free account to get started. Paid plans unlock all tracks.
Most people have more than one calendar attached to their Google account — a work one, a personal one, and the birthdays one Google auto-creates. How would you count them from Python?
Same shape as counting emails? Call an action, get a list back, use len() on whatever list comes out?
Exactly. The action is GOOGLECALENDAR_LIST_CALENDARS and the response shape is {"items": [...]} — the list lives under items instead of messages. Otherwise the pattern is identical to your Gmail counter:
result = toolset.execute_action(Action.GOOGLECALENDAR_LIST_CALENDARS, {})
count = len(result.get("items", []))So every API parks its list under a different key? Gmail uses messages, Calendar uses items — do I have to memorize those keys for every new endpoint?
You skim them from the docs once per API. The defensive .get(key, []) pattern works whatever the key is — swap the string, the skeleton stands:
def count_calendars() -> int:
result = toolset.execute_action(Action.GOOGLECALENDAR_LIST_CALENDARS, {})
return len(result.get("items", []))The params dict is empty — is that a problem? Will the action reject it?
Not at all. Some actions need no parameters; listing calendars is one of them. You still pass {} so the shape of the call matches every other action. An empty dict is a parameter, not a missing one.
So everything I learned from Week 1 just works — I only look up the action name and the response key?
That is the transfer. The skeleton carries the logic. The enums carry the semantics. Different API, same muscle.
TL;DR: Every Google API puts its list under a different key — .get(key, []) handles all of them with one string swap.
Action.GOOGLECALENDAR_LIST_CALENDARS swaps for Gmail's equivalent{} means no filter, not a missing argument{"items": [...]}, one entry per calendar on the account| API | List key |
|---|---|
| Gmail | messages |
| Calendar | items |
| Tasks | items |
| Sheets | spreadsheets |