gmaillm
LLM-friendly Gmail API wrapper with CLI and progressive disclosure patterns.
Installation
Recommended: Using Makefile (Easiest)
For the simplest installation with automatic setup:
cd /path/to/gmaillm
# Install globally and setup shell completion
make install
make verify
make install-completion
See make help for all available targets.
Alternative: Manual Installation
cd /path/to/gmaillm
pip3 install --break-system-packages -e .
With Shell Completion (Recommended)
For faster typing with tab-completion support:
# 1. Install the package
pip3 install --break-system-packages -e .
# 2. Install shell completions
gmail --install-completion
# 3. Restart your shell
exec $SHELL
Note: After running --install-completion, you'll see a message confirming the completion script was installed. Restart your shell to activate it.
Supported Shells
- bash - Uses
~/.bash_completion.d/or~/.bashrc - zsh - Uses
~/.zshrcor completion directory - fish - Uses
~/.config/fish/completions/ - PowerShell - Uses profile completion directory
Setup & Authentication
Configuration Locations
gmaillm automatically detects whether it's running as a plugin or standalone:
-
Plugin mode (when
CLAUDE_PLUGIN_ROOTis set):- Config:
${CLAUDE_PLUGIN_ROOT}/credentials/ - OAuth keys:
${CLAUDE_PLUGIN_ROOT}/credentials/oauth-keys.json - Credentials:
${CLAUDE_PLUGIN_ROOT}/credentials/credentials.json
- Config:
-
Standalone mode (default):
- Config:
~/.gmaillm/ - OAuth keys:
~/.gmaillm/oauth-keys.json - Credentials:
~/.gmaillm/credentials.json
- Config:
First Time Setup
-
Obtain OAuth2 credentials from Google Cloud Console:
- Go to Google Cloud Console
- Create OAuth2 Client ID (Application type: Desktop app)
- Download the credentials as
oauth-keys.json - Save to one of these locations:
~/.gmaillm/oauth-keys.json(recommended for standalone)${CLAUDE_PLUGIN_ROOT}/credentials/oauth-keys.json(for plugin use)~/Desktop/OAuth2/gcp-oauth.keys.json(fallback)
-
Authenticate with Gmail:
gmail setup-authThis will:
- Open your browser for Google authentication
- Save credentials to the appropriate location (plugin or standalone)
- Configure Gmail API access
-
Verify setup:
gmail verify
Troubleshooting
If you see "Credentials file is empty" error:
# Run authentication setup
python3 -m gmaillm.setup_auth
# If port 8080 is in use, specify a different port
python3 -m gmaillm.setup_auth --port 8081
If you see "Address already in use" error:
# Kill any existing auth processes
pkill -f "gmaillm.setup_auth"
# Try a different port
python3 -m gmaillm.setup_auth --port 9999
Quick Start
CLI Usage
# Verify setup
gmail verify
# List emails
gmail list
gmail list --folder SENT --max 5
# Read email
gmail read <message_id>
gmail read <message_id> --full
# View thread
gmail thread <message_id>
# Search
gmail search "from:example@gmail.com has:attachment"
# Reply
gmail reply <message_id> --body "Thanks for the update!"
# Send
gmail send --to user@example.com --subject "Test" --body "Hello"
# List folders
gmail folders
# Manage labels
gmail label list # List all labels (system and custom)
gmail label create MyLabel # Create a new label
# Manage email styles
gmail styles list # List all email styles
gmail styles show professional-formal # View a specific style
gmail styles create my-style # Create a new style
gmail styles validate my-style # Validate style format
gmail styles validate-all --fix # Validate and auto-fix all styles
Email Styles
gmaillm supports a flexible email style system that allows you to define different writing styles for various contexts. Each style includes templates, formatting guidelines, and usage patterns.
Style Commands
# List all styles
gmail styles list
# View a specific style
gmail styles show professional-formal
# Create a new style (opens editor)
gmail styles create my-new-style
# Edit an existing style (opens editor)
gmail styles edit casual-friend
# Delete a style
gmail styles delete old-style
gmail styles delete old-style --force # Skip confirmation
# Validate style format
gmail styles validate my-style
gmail styles validate my-style --fix # Auto-fix formatting issues
# Validate all styles
gmail styles validate-all
gmail styles validate-all --fix # Auto-fix all styles
Style Format
Each style file uses YAML frontmatter and XML-like sections:
---
name: "Style Name"
description: "When to use: Context description with usage guidance."
---
<examples>
Example email 1
---
Example email 2
</examples>
<greeting>
- "Hi [Name],"
- "Hello [Name],"
</greeting>
<body>
- Writing guideline 1
- Writing guideline 2
</body>
<closing>
- "Best,"
- "Thanks,"
</closing>
<do>
- What to do
- Best practices
</do>
<dont>
- What to avoid
- Common mistakes
</dont>
Required sections (in strict order):
examples- Example emails showing the style in actiongreeting- Greeting patterns and guidelinesbody- Body content guidelinesclosing- Closing patternsdo- Best practicesdont- Things to avoid
See STYLES.md for complete style guide documentation.
Workflows
Interactive Workflows
Process emails interactively with prompts for each action:
# Run named workflow
gmail workflows run clear
# Run with custom query
gmail workflows run --query "is:unread from:boss@example.com"
LLM-Friendly Workflows (Programmatic)
Process emails programmatically with continuation tokens for automation:
# Start workflow (returns JSON with token + first email)
gmail workflows start clear
# Continue with actions (returns next email + same token)
gmail workflows continue <token> archive
gmail workflows continue <token> skip
gmail workflows continue <token> reply --reply-body "Thanks!"
gmail workflows continue <token> view # View full body
gmail workflows continue <token> quit # End workflow
JSON Response:
{
"success": true,
"token": "abc123...",
"email": { /* full email data */ },
"message": "Archived",
"progress": {"total": 10, "processed": 3, "remaining": 7, "current": 4},
"completed": false
}
Automation Example:
# Archive all unread emails
TOKEN=$(gmail workflows start clear | jq -r '.token')
while [ "$TOKEN" != "null" ]; do
RESULT=$(gmail workflows continue "$TOKEN" archive)
TOKEN=$(echo "$RESULT" | jq -r '.token')
done
Workflow Management
gmail workflows list # List configured workflows
gmail workflows show clear # View workflow details
gmail workflows create daily \
--query "is:unread" \
--auto-mark-read # Create new workflow
gmail workflows cleanup # Remove expired states
Python Library
from gmaillm import GmailClient
client = GmailClient()
# List emails
result = client.list_emails(folder='INBOX', max_results=10)
print(result.to_markdown())
# Read email
email = client.read_email(message_id, format="summary")
print(email.to_markdown())
Tips & Tricks
Speed Up Typing with Completions
Once you've installed shell completions (gmail --install-completion), you can:
- Type
gmail land press<TAB>→ expands to available commands - Type
gmail send --to userand press<TAB>→ shows field completions - Type
gmailand press<TAB>→ shows all available commands
Quick Command Reference
# Most common commands
gmail verify # Check if setup is working
gmail status # See your inbox status
gmail list # Show recent emails
gmail search "from:someone@example.com" # Find specific emails
gmail send --to user@example.com \
--subject "Hello" --body "Hi there" # Send an email
Help for Any Command
# Get help for a specific command
gmail send --help
gmail search --help
Documentation
User Guides
- Email Styles Guide - Creating and managing email writing styles
- Email Groups Guide - Managing email distribution groups
Technical Documentation
- Testing Guide - Running and writing tests
- API Reference - Complete API documentation
- Changelog - Version history and changes
Testing
make test # Run full test suite with coverage
uv run pytest tests/ # Run tests directly
Metadata
Release files for gmaillm 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gmaillm-1.0.0.tar.gz | 131.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gmaillm-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 219.4 kB
Release files / gmaillm-1.0.0.tar.gz
| Download URL | gmaillm-1.0.0.tar.gz |
|---|---|
| Size | 131.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30f87dcc7a0372c9e90950616af2a0beee819916331d6e42e70efb739be452bf
|
|
BLAKE2b-256 checksum How to use checksums |
1e710b7e6316fc9e5746d74830d75c1830d99be1b88299394093f091aecb2992
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / gmaillm-1.0.0-py3-none-any.whl
| Download URL | gmaillm-1.0.0-py3-none-any.whl |
|---|---|
| Size | 87.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
577f0277d684497978ebe9df3e6b3898e455b18d34f669adb6df4004039fe531
|
|
BLAKE2b-256 checksum How to use checksums |
14185d16eb7acd4d230b5540fc10373bc232b6468a95e570faa2b55a5d13a324
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|