Unified Google Workspace SDK - Gmail, Calendar, Drive, Sheets
Project description
Google Suite
Unified Python SDK for Google Workspace APIs with Clean Architecture.
Features
- 🔐 Unified Auth - Single OAuth flow for all Google APIs
- 📧 Gmail - Send, receive, search, labels, attachments
- 📅 Calendar - Events, calendars, scheduling
- 📁 Drive - Files, folders, sharing, upload/download
- 📊 Sheets - Read, write, append, format, batch operations
- 🚀 REST API - Single FastAPI gateway for all services
- 💻 CLI - Unified command-line interface
Installation
pip install gsuite-sdk
Optional extras:
pip install gsuite-sdk[cloudrun] # Google Cloud Secret Manager support
pip install gsuite-sdk[all] # All optional dependencies (FastAPI, CLI)
Quick Start
Prerequisites
You need OAuth credentials from Google Cloud Console. See Getting Credentials for a step-by-step guide.
Authentication
from gsuite_core import GoogleAuth
# OAuth (interactive, opens browser)
auth = GoogleAuth()
auth.authenticate()
# Or with service account
auth = GoogleAuth.from_service_account("service-account.json")
Gmail
from gsuite_gmail import Gmail, query
gmail = Gmail(auth)
# Get unread messages with fluent API
for message in gmail.get_unread():
print(f"{message.sender}: {message.subject}")
message.mark_as_read().archive() # Fluent chaining!
# Send email with signature
gmail.send(
to=["recipient@example.com"],
subject="Hello",
body="World",
signature=True, # Appends your Gmail signature
)
# Search with query builder (inspired by simplegmail)
messages = gmail.search(
query.newer_than(days=7) & query.has_attachment() & query.from_("boss@company.com")
)
# Or use construct_query for dict-style
messages = gmail.search(query.construct_query(
unread=True,
newer_than=(7, "day"),
labels=["Work"],
))
Drive
from gsuite_drive import Drive
drive = Drive(auth)
# List files
for file in drive.list_files():
print(f"{file.name} ({file.mime_type})")
# Upload
uploaded = drive.upload("document.pdf")
print(f"Uploaded: {uploaded.web_view_link}")
# Download
file = drive.get("file_id")
file.download("local_copy.pdf")
# Create folder and upload into it
folder = drive.create_folder("My Folder")
drive.upload("file.txt", parent_id=folder.id)
Calendar
from gsuite_calendar import Calendar
calendar = Calendar(auth)
# Get upcoming events
events = calendar.get_upcoming(days=7)
for event in events:
print(f"{event.start}: {event.summary}")
# Create event
calendar.create_event(
summary="Meeting",
start="2026-01-30T10:00:00",
end="2026-01-30T11:00:00",
)
REST API
# Start unified API server
gsuite serve --port 8080
# Or with Docker
docker run -p 8080:8080 gsuite-api
# All services under one roof
curl http://localhost:8080/gmail/messages/unread
curl http://localhost:8080/calendar/events/upcoming
curl http://localhost:8080/drive/files
Interactive API docs available at /docs when server is running. See API Documentation section below for details.
CLI
# Authentication
gsuite auth login # Opens browser for OAuth
gsuite auth status # Check auth status
gsuite auth export # Export token for Cloud Run
# Gmail
gsuite gmail list --unread # List unread messages
gsuite gmail read MSG_ID # Read specific message
gsuite gmail send --to user@example.com --subject "Hi" --body "Hello"
gsuite gmail search "from:boss has:attachment"
gsuite gmail labels # List all labels
# Calendar
gsuite calendar list --days 7 # Upcoming events
gsuite calendar today # Today's events
gsuite calendar week # Week view
gsuite calendar create "Meeting" --start "2026-01-30 10:00"
gsuite calendar calendars # List calendars
# Server
gsuite serve --port 8080 # Start REST API
gsuite status # Overall status
Architecture
google-suite/
├── packages/
│ ├── core/ # Shared auth, config, token storage
│ ├── gmail/ # Gmail client + query builder
│ ├── calendar/ # Calendar client
│ ├── drive/ # Drive client (upload, download, share)
│ └── sheets/ # Sheets client (planned)
├── api/ # Unified FastAPI REST gateway
├── cli/ # Unified CLI (Typer + Rich)
├── skill/ # AI agent skill (OpenClaw compatible)
└── tests/ # Integration tests
Design Principles
- Clean Architecture - Domain entities, interfaces, infrastructure separation
- Provider Agnostic - Swap implementations via interfaces
- Shared Auth - One OAuth flow grants access to all services
- Independent Packages - Install only what you need
- Unified Gateway - Single API/CLI for all services
AI Agent Skill
This repo includes an OpenClaw-compatible skill for AI agents:
skill/
├── SKILL.md # Usage documentation for agents
└── skill.json # Skill metadata
Agents can use this skill to interact with Google Workspace on behalf of users.
Standalone Repos
This monorepo consolidates and extends these standalone projects:
- Gmail-API - Standalone Gmail API
- Calendar-API - Standalone Calendar API
The standalone repos remain functional for existing deployments.
Configuration
Environment variables (prefix GSUITE_):
| Variable | Description |
|---|---|
GSUITE_CREDENTIALS_FILE |
OAuth credentials JSON path |
GSUITE_TOKEN_STORAGE |
sqlite or secretmanager |
GSUITE_TOKEN_DB_PATH |
SQLite token database path |
GSUITE_GCP_PROJECT_ID |
GCP project (for Secret Manager) |
GSUITE_API_KEY |
API key for REST endpoints |
Development
# Clone
git clone https://github.com/PabloAlaniz/google-suite.git
cd google-suite
# Install all packages in dev mode
pip install -e "packages/core[dev]"
pip install -e "packages/gmail[dev]"
pip install -e "packages/calendar[dev]"
pip install -e "api[dev]"
pip install -e "cli[dev]"
# Run tests
pytest
# Lint
ruff check packages api cli
Deployment
Cloud Run (GCP)
Deploy the REST API to Cloud Run with Secret Manager for token storage:
# Build and push Docker image
gcloud builds submit --tag gcr.io/YOUR_PROJECT/gsuite-api
# Deploy to Cloud Run
gcloud run deploy gsuite-api \
--image gcr.io/YOUR_PROJECT/gsuite-api \
--platform managed \
--region us-central1 \
--set-env-vars GSUITE_TOKEN_STORAGE=secretmanager \
--set-env-vars GSUITE_GCP_PROJECT_ID=YOUR_PROJECT \
--allow-unauthenticated # or use --no-allow-unauthenticated + IAM
Note: For Secret Manager token storage, ensure your Cloud Run service account has secretmanager.versions.access permission.
Docker Compose
For local development or self-hosted deployment:
version: '3.8'
services:
gsuite-api:
build: .
ports:
- "8080:8080"
environment:
GSUITE_CREDENTIALS_FILE: /secrets/credentials.json
GSUITE_TOKEN_DB_PATH: /data/tokens.db
GSUITE_API_KEY: your-api-key-here
volumes:
- ./credentials.json:/secrets/credentials.json:ro
- ./data:/data
API Documentation
When running the REST API server, interactive API docs are available at:
- Swagger UI:
http://localhost:8080/docs - ReDoc:
http://localhost:8080/redoc
Troubleshooting
Token refresh failed
Problem: TokenRefreshError: Failed to refresh token
Solution:
- Delete the token database:
rm ~/.gsuite/tokens.db(or your configured path) - Re-authenticate:
gsuite auth login - For service accounts, verify the JSON file hasn't expired
Missing scopes
Problem: HttpError 403: Insufficient Permission
Solution:
- Check required scopes in error message
- Re-authenticate with additional scopes:
gsuite auth login --scopes gmail.readonly,calendar,drive
- Or update
GSUITE_DEFAULT_SCOPESenvironment variable
Credentials not found
Problem: CredentialsNotFoundError: OAuth credentials file not found
Solution:
- Download OAuth credentials from Google Cloud Console
- Save as
credentials.jsonin working directory - Or set
GSUITE_CREDENTIALS_FILEenvironment variable
Import errors
Problem: ModuleNotFoundError: No module named 'gsuite_gmail'
Solution:
- Install the package:
pip install gsuite-gmail - Or for development:
pip install -e "packages/gmail[dev]"
License
MIT - see LICENSE
Author
Pablo Alaniz (@PabloAlaniz)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gsuite_sdk-0.1.2.tar.gz.
File metadata
- Download URL: gsuite_sdk-0.1.2.tar.gz
- Upload date:
- Size: 44.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41d1432f43b1d99570ebad91fa11011cc26e5f7dc62efb70aff044479db49d80
|
|
| MD5 |
803e1cff689bbe062967b1913ca064bb
|
|
| BLAKE2b-256 |
37068998cf3114b699596ca34e03d21de99590082279e93b15cd4f34d1747afe
|
Provenance
The following attestation bundles were made for gsuite_sdk-0.1.2.tar.gz:
Publisher:
publish.yml on PabloAlaniz/google-suite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gsuite_sdk-0.1.2.tar.gz -
Subject digest:
41d1432f43b1d99570ebad91fa11011cc26e5f7dc62efb70aff044479db49d80 - Sigstore transparency entry: 909310070
- Sigstore integration time:
-
Permalink:
PabloAlaniz/google-suite@20350b45fab1fae64324c33928b7850c87abb52e -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/PabloAlaniz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@20350b45fab1fae64324c33928b7850c87abb52e -
Trigger Event:
release
-
Statement type:
File details
Details for the file gsuite_sdk-0.1.2-py3-none-any.whl.
File metadata
- Download URL: gsuite_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 52.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
736e9831e4234ebad888b0b46ab3ed79ae90bef93b27993b2e47aaad45c01b61
|
|
| MD5 |
d1530e98a203302d637ceaea64d3385b
|
|
| BLAKE2b-256 |
5b959600e4c8f4481cb95d38a616ed05098d46fcd2c32a3dfb37f7e0baf58218
|
Provenance
The following attestation bundles were made for gsuite_sdk-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on PabloAlaniz/google-suite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gsuite_sdk-0.1.2-py3-none-any.whl -
Subject digest:
736e9831e4234ebad888b0b46ab3ed79ae90bef93b27993b2e47aaad45c01b61 - Sigstore transparency entry: 909310072
- Sigstore integration time:
-
Permalink:
PabloAlaniz/google-suite@20350b45fab1fae64324c33928b7850c87abb52e -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/PabloAlaniz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@20350b45fab1fae64324c33928b7850c87abb52e -
Trigger Event:
release
-
Statement type: