Search tldr

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.

Share

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-sync performs a complete synchronization and identifies messages removed from Gmail.
  • Operational resilience: Multi-threaded message retrieval, automatic retry with exponential backoff, and graceful CTRL+C handling help make long-running mailbox imports reliable. A second CTRL+C forces 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

Keep reading