GitHub - marcboeker/gmail-to-sqlite: Index your Gmail account to a SQLite DB and play with the data. · GitHub
A Python CLI that synchronizes Gmail messages into a local SQLite database for private archival and SQL-based analysis. It supports incremental and full syncs, deletion detection, parallel fetching, and resilient interruption handling.
GitHub - marcboeker/gmail-to-sqlite: Index your Gmail account to a SQLite DB and play with the data. · GitHub
Author: marcboeker | Published: Unknown | Generated: 2025-05-10 | Domain: github.com
Tags: ‘#gmail’ ‘#sqlite’ ‘#python’ ‘#email-archiving’ ‘#data-analysis’
TLDR
Gmail to SQLite is a Python application that copies Gmail messages into a local SQLite database, making an inbox queryable for analysis and archival without relying on Gmail’s interface. It supports efficient incremental syncing by default, optional complete reconciliation that flags deleted messages, and multi-threaded fetching with retries and exponential backoff. The resulting database stores message metadata, bodies, JSON-encoded participants and labels, plus sync state for custom SQL exploration.
Key Takeaways
- Sync modes: The default incremental sync downloads only new messages;
--full-syncperforms a complete synchronization and identifies messages removed from Gmail. - Operational resilience: Multi-threaded message retrieval, automatic retry with exponential backoff, and graceful
CTRL+Chandling help make long-running mailbox imports reliable. A secondCTRL+Cforces an immediate exit. - Requirements and setup: Requires Python 3.8+, a Google Cloud project with the Gmail API enabled, and Desktop OAuth 2.0 credentials saved as
credentials.json. - Queryable local schema: Each message records Gmail and thread IDs, sender and recipient JSON, labels, subject, plaintext body, byte size, timestamp, read/outgoing/deleted flags, and
last_indexed. - Analysis examples: Included SQL queries identify prolific or unread-email senders, message volume by time period, newsletter-like messages, largest senders by total storage, self-sent mail, and deleted messages.
Images & Media
- Gmail to SQLite header illustration — Repository header image for the Gmail-to-SQLite project.
Referenced Links
- Gmail to SQLite repository — Source code, installation instructions, CLI documentation, and example SQLite queries.
- Google Cloud Console — Used to create a project, enable the Gmail API, and create OAuth 2.0 Desktop credentials.
- Repository commit history — Project change history.