A CLI tool for syncing Gmail to a local SQLite database, optimized for agent workflows. Enables fast local search and reads without hitting the Gmail API on every query.
pip install -e .-
Authenticate with Gmail:
gmail-cli auth oauth
Follow the wizard to set up OAuth2 credentials from Google Cloud Console.
-
Sync your Gmail:
gmail-cli sync full
This will download all your Gmail messages to a local SQLite database.
-
Search your messages:
gmail-cli search "invoice" -
Read a message:
gmail-cli read <message-id>
The tool uses OAuth2 to authenticate with Gmail. You'll need to:
- Create a Google Cloud project
- Enable the Gmail API
- Create OAuth2 credentials (Desktop app)
- Download and save the credentials to
~/.gmail-cli/credentials.json
Run gmail-cli auth oauth for a step-by-step wizard.
All data is stored in ~/.gmail-cli/:
credentials.json- Your OAuth credentialstoken.json- Auto-generated OAuth tokensgmail.db- SQLite database (created after first sync)attachments/- Downloaded attachments
gmail-cli auth oauth- Set up OAuth2 authenticationgmail-cli auth status- Show authentication statusgmail-cli auth logout- Clear stored credentials
gmail-cli status- Show overall status (auth, database, sync state)
gmail-cli sync full- Full sync of all Gmail messages (resumes if interrupted)gmail-cli sync full --force- Force fresh sync from scratchgmail-cli sync full --workers 2- Adjust concurrent workers (1-10)gmail-cli sync incremental- Only sync changes since last sync
gmail-cli search "query"- Search messages using FTS5 full-text searchgmail-cli search "query" --limit 100- Limit number of resultsgmail-cli search "query" --json- Output as JSON for agents
Supports FTS5 syntax:
- Simple:
gmail-cli search "invoice" - Phrase:
gmail-cli search '"quarterly report"' - Boolean OR:
gmail-cli search "invoice OR receipt" - Boolean NOT:
gmail-cli search "meeting NOT cancelled"
gmail-cli read <message-id>- View a messagegmail-cli read <message-id> --raw- Show raw headers and bodygmail-cli read <message-id> --json- Output as JSON
gmail-cli thread <thread-id>- View all messages in a threadgmail-cli thread <thread-id> --json- Output as JSON
gmail-cli attachments list <message-id>- List message attachmentsgmail-cli attachments download <attachment-id>- Download attachmentgmail-cli attachments download <attachment-id> -o path- Download to specific path
See PLAN.md for the full implementation plan.
- Python 3.12+
- Typer + rich-toolkit for CLI
- SQLite + FTS5 for storage and search
- Google APIs for Gmail access
- SQLModel for database models