Archive a full year of Gmail to mbox/Maildir and remove from your account
Project description
gmailarchiver
Archive all Gmail messages from a given calendar year to an mbox or Maildir file, then permanently delete (or trash) them from your account.
Features
- Downloads every message in a year via the Gmail API (all labels, including Spam/Trash)
- Saves to standard mbox or Maildir format — importable into Thunderbird, Apple Mail, Dovecot, etc.
- Permanently deletes after archiving (or
--trashto use recoverable Trash) - Idempotent-safe: archive written to disk before deletion is issued
- Batch deletes (up to 1 000 IDs/call) to stay within Gmail API quotas
- Exponential back-off on transient 429/5xx errors
- Progress bars via
rich --dry-runto count messages without downloading
Setup
1. Google Cloud credentials
- Go to Google Cloud Console.
- Create a project → enable the Gmail API.
- Create an OAuth 2.0 Client ID → type Desktop app.
- Download
credentials.jsonand place it at:
~/.gmailarchiver/credentials.json
Or pass --credentials <path> at runtime.
2. Install
pipx install gmailarchiver # recommended
# or
pip install gmailarchiver
3. First run (OAuth consent)
The first invocation opens a browser tab for Google OAuth consent. After approval the token is cached at ~/.gmailarchiver/token.json.
Usage
gmailarchiver <year> [options]
Options
| Flag | Default | Description |
|---|---|---|
--output / -o PATH |
./<year>.mbox |
Archive destination |
--format / -f {mbox,maildir} |
mbox |
Archive format |
--no-delete |
off | Archive only; keep messages in Gmail |
--trash |
off | Move to Trash (30-day recovery) instead of permanent delete |
--dry-run |
off | Count messages, do nothing else |
--credentials PATH |
~/.gmailarchiver/credentials.json |
OAuth credentials |
--token PATH |
~/.gmailarchiver/token.json |
Cached OAuth token |
--label LABEL_ID |
all mail | Restrict to label (INBOX, SENT, custom ID); repeatable |
Examples
# Archive 2022 to mbox, permanently delete from Gmail
gmailarchiver 2022 --output ~/mail/2022.mbox
# Archive 2021 to Maildir, move to Trash instead of hard-delete
gmailarchiver 2021 --output ~/mail/2021/ --format maildir --trash
# Dry run: count 2023 messages without touching anything
gmailarchiver 2023 --dry-run
# Archive only INBOX and SENT from 2020, keep in Gmail
gmailarchiver 2020 --output ~/mail/2020.mbox --no-delete \
--label INBOX --label SENT
# Use a specific credentials file
gmailarchiver 2022 --credentials ~/secrets/gmail_oauth.json
Archive formats
| Format | Best for |
|---|---|
mbox |
Single file, easy to move/compress, Apple Mail, Thunderbird |
maildir |
Dovecot / Postfix import, per-message files, fast random access |
Both formats are RFC-standard and widely supported.
Safety notes
- Messages are written to disk before any delete call is issued.
--trashis the safer option if you want a 30-day grace period.- Permanent deletion via
batchDeleteis irreversible. - If the run is interrupted mid-way, re-run the same command — already-archived messages will be re-downloaded (mbox gets duplicates), but nothing is lost. Use
--no-deleteon a re-run if you only want to fill gaps, then delete manually.
Gmail API quota
The default Gmail API quota is 1 billion quota units/day. Each messages.get call costs 5 units; messages.batchDelete costs 50 units per call. Archiving 50 000 messages ≈ 253 000 units — well within limits. If you hit quota, the tool backs off and retries automatically.
Development
git clone https://github.com/youruser/gmailarchiver
cd gmailarchiver
pip install -e ".[dev]"
pytest
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gmail_yr_archiver-0.1.0.tar.gz.
File metadata
- Download URL: gmail_yr_archiver-0.1.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0b3ad8bf460ab8d071408c03965d53d49b648825a27a54252a3aac4912229a5
|
|
| MD5 |
7d03fbd3e6e0064326d384b581263e60
|
|
| BLAKE2b-256 |
c29c0ce33940879aec7fe4dfdbe105b83e70d088a0a8eacc0ac465ae088ca608
|
File details
Details for the file gmail_yr_archiver-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gmail_yr_archiver-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a80913b48f772ad7bc21ca1ecc29b3785bfee90cfb21478a95651b12d6f6f3e9
|
|
| MD5 |
9556a6e5a8e0af31bd8262c062ce8a0b
|
|
| BLAKE2b-256 |
797dff3385443b5869f700e13124624cf433f473a6a047991d12103a52235ece
|