Google Workspace
Access Google Workspace APIs via service account with domain-wide delegation.
Prerequisites
- Python 3.8+
google-authandgoogle-api-python-clientpackages- A Google Cloud service account with domain-wide delegation
- Service account JSON key file
pip install google-auth google-api-python-client
Environment Variables
| Variable | Required | Description |
|---|---|---|
GOOGLE_SERVICE_ACCOUNT_FILE | Yes | Path to service account JSON key file |
GOOGLE_WORKSPACE_USER | Yes | Email to impersonate (e.g., user@domain.com) |
Usage
python scripts/gw.py cal-today # Today's events
python scripts/gw.py cal-today --brief # Today's events (no attendees)
python scripts/gw.py cal-upcoming --days 3 # Next 3 days
python scripts/gw.py drive-shared-list # List shared drives
python scripts/gw.py drive-shared-recent --limit 10 # Recent files in shared drives
Available Commands
Calendar
cal-today [--brief]— Today's calendar events.--briefhides attendees.cal-upcoming [--days N]— Events in the next N days (default: 3).
Drive (Shared Drives)
drive-shared-list— List all shared drives visible to the service account.drive-shared-recent [--limit N]— Recently modified files across shared drives.drive-customer --name "Name"— Search for a customer folder in shared drives and list contents.
Scopes
The script requests only readonly scopes:
https://www.googleapis.com/auth/calendar.readonlyhttps://www.googleapis.com/auth/drive.readonly
Setup Guide
- Create a service account in Google Cloud Console
- Enable domain-wide delegation
- Grant scopes in Google Workspace Admin → Security → API Controls → Domain-wide Delegation
- Download the JSON key file
- Set environment variables and run