Two questions, one function: how many emails are in your inbox right now, and how many events are on your calendar. You want both numbers in a single return — what shape makes that easy to read?
A dict with two keys? Something like {"emails": 3, "events": 2} so the caller knows which number is which?
Exactly that. Named keys are self-documenting — no caller ever has to remember which number came first. The two execute_action calls go back-to-back, each guarded by .get():
emails = toolset.execute_action(Action.GMAIL_FETCH_EMAILS, {"max_results": 5})
events = toolset.execute_action(Action.GOOGLECALENDAR_FIND_EVENT, {"query": ""})So Gmail returns {"messages": [...]} and Calendar returns {"items": [...]} — different keys for the same kind of data. Do I have to memorize the key per API?
One lookup per API, then the pattern sticks. .get(key, []) works no matter what the key name is — swap the string, the skeleton stands. Here's the full function:
def inbox_and_events(max_emails: int, max_events: int) -> dict:
emails = toolset.execute_action(Action.GMAIL_FETCH_EMAILS, {"max_results": max_emails})
events = toolset.execute_action(Action.GOOGLECALENDAR_FIND_EVENT, {"query": ""})
return {"emails": len(emails.get("messages", [])), "events": len(events.get("items", []))}What if Gmail is empty one morning? Does the "messages" key still show up, or does the whole response change shape?
Either the key is missing or the list is empty — both shapes are possible. .get("messages", []) handles both cleanly, and len([]) is zero. Your function returns a dict with two valid counts whether your inbox is buzzing or silent.
So I'm really looking at two live APIs at once, and the dict on my screen is a real-time snapshot of my morning?
Live inbox, live calendar, one dict. That is the shape every multi-source function in this track will take — two reads, defensive gets, one return.
TL;DR: Two execute_action calls, two .get(key, []) safeties, one dict with named keys.
messages on every fetchitems on every find{"emails": int, "events": int} so callers read by name| API | List key |
|---|---|
| Gmail | messages |
| Calendar | items |
| Tasks | items |
Named dict keys beat tuples every time: order-independent, self-documenting, and completely refactor-safe when new sources join later.
Two questions, one function: how many emails are in your inbox right now, and how many events are on your calendar. You want both numbers in a single return — what shape makes that easy to read?
A dict with two keys? Something like {"emails": 3, "events": 2} so the caller knows which number is which?
Exactly that. Named keys are self-documenting — no caller ever has to remember which number came first. The two execute_action calls go back-to-back, each guarded by .get():
emails = toolset.execute_action(Action.GMAIL_FETCH_EMAILS, {"max_results": 5})
events = toolset.execute_action(Action.GOOGLECALENDAR_FIND_EVENT, {"query": ""})So Gmail returns {"messages": [...]} and Calendar returns {"items": [...]} — different keys for the same kind of data. Do I have to memorize the key per API?
One lookup per API, then the pattern sticks. .get(key, []) works no matter what the key name is — swap the string, the skeleton stands. Here's the full function:
def inbox_and_events(max_emails: int, max_events: int) -> dict:
emails = toolset.execute_action(Action.GMAIL_FETCH_EMAILS, {"max_results": max_emails})
events = toolset.execute_action(Action.GOOGLECALENDAR_FIND_EVENT, {"query": ""})
return {"emails": len(emails.get("messages", [])), "events": len(events.get("items", []))}What if Gmail is empty one morning? Does the "messages" key still show up, or does the whole response change shape?
Either the key is missing or the list is empty — both shapes are possible. .get("messages", []) handles both cleanly, and len([]) is zero. Your function returns a dict with two valid counts whether your inbox is buzzing or silent.
So I'm really looking at two live APIs at once, and the dict on my screen is a real-time snapshot of my morning?
Live inbox, live calendar, one dict. That is the shape every multi-source function in this track will take — two reads, defensive gets, one return.
TL;DR: Two execute_action calls, two .get(key, []) safeties, one dict with named keys.
messages on every fetchitems on every find{"emails": int, "events": int} so callers read by name| API | List key |
|---|---|
| Gmail | messages |
| Calendar | items |
| Tasks | items |
Named dict keys beat tuples every time: order-independent, self-documenting, and completely refactor-safe when new sources join later.
Create a free account to get started. Paid plans unlock all tracks.