A Python script to analyze your Gmail inbox and identify which senders are flooding your Primary, Social, and Promotions categories. Perfect for deciding who to unsubscribe from or whose emails to delete.
- 📊 Analyzes Primary, Social, and Promotions inboxes
- 🔍 Counts emails per sender without reading email content
- 📝 Generates detailed reports showing top senders
- 🔒 Preserves read/unread status - only accesses email headers
- 📈 Provides breakdown by Gmail category
- Uses official Gmail API (secure, won't get you banned)
- Respects Gmail's rate limits and authentication
- Works with 2FA enabled accounts
- Exports results to text file for easy reference
- Go to Google Cloud Console
- Create a new project or select existing one
- Navigate to APIs & Services → Library
- Search for "Gmail API" and enable it
- Go to APIs & Services → OAuth consent screen
- Choose "External" user type
- Fill in app name (e.g., "Gmail Analyzer")
- Add your email as a test user
- Go to APIs & Services → Credentials
- Create credentials → OAuth 2.0 Client ID
- Select "Desktop application"
- Download the JSON file and rename it to
credentials.json
# Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txtpython script.pyOn first run, it will:
- Open your browser for Google authentication
- Save credentials for future runs
- Analyze your inbox and generate reports
The script generates:
- Console output: Top 20 senders with email counts
- gmail_analysis.txt: Detailed breakdown by category
- token.pickle: Authentication token (auto-generated)
gmail-inbox-analyzer/
├── script.py # Main analyzer script
├── credentials.json # OAuth credentials (keep private)
├── requirements.txt # Python dependencies
├── token.pickle # Auth token (auto-generated, keep private)
├── gmail_analysis.txt # Results (auto-generated)
└── .gitignore # Git ignore file
credentials.jsonandtoken.picklecontain sensitive data - never commit to version control- Script only reads email headers, not content
- Uses read-only Gmail API permissions
- Your email password is never stored or required
GMAIL INBOX ANALYSIS RESULTS
=====================================
EMAILS BY CATEGORY:
Primary: 245 emails
Social: 89 emails
Promotions: 412 emails
TOP 20 SENDERS (Total emails):
[email protected]: 45 emails
└─ Promotions: 45
[email protected]: 32 emails
└─ Social: 32
[email protected]: 28 emails
└─ Primary: 28
- "Access blocked" error: Add your email as a test user in OAuth consent screen
- "Credentials not found": Ensure
credentials.jsonis in the same folder as script - "Gmail API not enabled": Enable Gmail API in Google Cloud Console
- Python 3.7+
- Gmail account with API access
- Google Cloud project with Gmail API enabled
This tool helps you identify email senders flooding your inbox so you can make informed decisions about unsubscribing or deleting emails.