CLI for Gmail labels and message queries
Project description
gmail-tool
CLI application for exploring Gmail labels and querying messages by label with configurable auth, actions, and filters.
Initial Features
- List Gmail labels
- Run actions against a label
- Actions:
count: print the number of messages in the labellist: print message headers (recipient,sender,date,subject) with--limit
- Global filters:
- date range via
--from-dateand--to-date --starred true|false
- date range via
- Config-driven behavior via
config.toml - Secrets loaded from
.env - Docker packaging, pre-commit hooks, and GitHub Actions
Authentication
Supported auth modes:
- OAuth desktop flow
- Service account flow for Google Workspace domain-wide delegation
For the normal OAuth desktop flow, config.toml is optional.
Quick start:
- Place your Desktop OAuth client JSON at
~/.config/gmail-tool/client_secret.json - Run
gmail-tool auth login - Run
gmail-tool auth check
Useful helpers:
gmail-tool auth pathsgmail-tool auth logoutgmail-tool auth login --no-browser
Credential setup instructions are in docs/google-credentials.md.
Quick Start
- Install
uv. - For OAuth, place your Desktop OAuth client JSON at
~/.config/gmail-tool/client_secret.json. - Install dependencies:
uv sync --dev
- Log in:
uv run gmail-tool auth login
uv run gmail-tool auth check
uv run gmail-tool auth paths
- List labels:
uv run gmail-tool labels
Show the CLI version:
uv run gmail-tool --version
Enable debug output to stderr:
uv run gmail-tool --verbose labels
Or as JSON:
uv run gmail-tool labels -f json
Auth diagnostics:
uv run gmail-tool auth-check
uv run gmail-tool auth check
Read a full message by identifier:
uv run gmail-tool read <MESSAGE_ID>
Search with a raw Gmail query:
uv run gmail-tool search from:bob@example.com has:attachment
Count search matches:
uv run gmail-tool search -a count from:bob@example.com
Add a label to all search matches:
uv run gmail-tool search -a label-add:FollowUp from:bob@example.com
List built-in search examples:
uv run gmail-tool search --list-query-examples
Print a Gmail search operator cheat sheet:
uv run gmail-tool search --cheat-sheet
Run a saved query from config.toml:
uv run gmail-tool search --saved-query recent_attachments
Back up matching messages as .eml files:
uv run gmail-tool search -a backup from:bob@example.com
uv run gmail-tool search -a backup --backup-path /tmp/gmail-backups from:bob@example.com
- Count messages in a label:
uv run gmail-tool label INBOX -a count
gmail-tool label <LABEL> accepts either an exact Gmail label name such as @Later or an exact label ID such as Label_66.
- List messages in a label:
uv run gmail-tool label IMPORTANT -l 10 --starred true
Or export them as CSV:
uv run gmail-tool label IMPORTANT -l 10 -f csv
Plain-text list output includes message_id values that can be passed to read.
The search command returns the same message list structure as label ... list.
Both label and search default to the list action. Use --action or -a to switch to count, backup, label-add:<name>, or label-remove:<name>.
The label command defaults to the list action. Use --action count or -a count to switch actions.
- List supported actions:
uv run gmail-tool label --list-actions
uv run gmail-tool search --list-actions
Configuration
See config.toml, .env.sample, and docs/configuration.md.
All commands accept --config <path> or -c <path>. If omitted, config discovery falls back through environment, XDG, home config, /etc, and the project directory. If no config file is found, built-in OAuth defaults are used.
Development
uv sync --dev
uv run pytest --cov=src/gmail_tool --cov-report=term-missing --cov-report=xml --cov-report=json
./scripts/update-coverage-badge.sh coverage.json
uv run pre-commit run --all-files
Coverage artifacts produced by CI:
coverage.jsoncoverage.xml.github/badges/coverage.json
Releases
PyPI publishing is handled by the GitHub Actions Publish workflow on version tags such as v0.2.2.
Release packaging steps are documented in docs/release/packaging.md.
Live Gmail Integration Tests
Live Gmail tests are opt-in and use your local .env and config.toml.
Run them with an existing OAuth token:
ENABLE_LIVE_GMAIL_TESTS=true uv run pytest -m live_gmail
If this is your first OAuth run and no token exists yet, allow browser authentication explicitly:
ENABLE_LIVE_GMAIL_TESTS=true ALLOW_GMAIL_OAUTH_BROWSER=true uv run pytest -m live_gmail -s
These tests verify Gmail API access against your real mailbox and are skipped unless explicitly enabled.
Documentation
Project details
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_tool-0.2.2.tar.gz.
File metadata
- Download URL: gmail_tool-0.2.2.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30d09852d08790f3f32ca5d25626fe86be39aeef822f1ae3eadb38972e8de37b
|
|
| MD5 |
abcbb7576aca4b91d7794c35ece59d9b
|
|
| BLAKE2b-256 |
901c3dd09be0942cdf4f29ae5b6b8b6a29e30474d47573aa04dd200e86602e2d
|
Provenance
The following attestation bundles were made for gmail_tool-0.2.2.tar.gz:
Publisher:
publish.yml on joelee/gmail-tool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gmail_tool-0.2.2.tar.gz -
Subject digest:
30d09852d08790f3f32ca5d25626fe86be39aeef822f1ae3eadb38972e8de37b - Sigstore transparency entry: 1437298994
- Sigstore integration time:
-
Permalink:
joelee/gmail-tool@456857e1a4d6c5ed5788f96d757c055fbce9d501 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/joelee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@456857e1a4d6c5ed5788f96d757c055fbce9d501 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gmail_tool-0.2.2-py3-none-any.whl.
File metadata
- Download URL: gmail_tool-0.2.2-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
210b9f849186faf781911e0a4ca53ac105cf3b3d9a7704ba028fa40879a64cbd
|
|
| MD5 |
9e6c8f677bb68c6431762687a3df4372
|
|
| BLAKE2b-256 |
b139e68205629e2146511214881f22cc34714b208f0c76a42225f476214e3467
|
Provenance
The following attestation bundles were made for gmail_tool-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on joelee/gmail-tool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gmail_tool-0.2.2-py3-none-any.whl -
Subject digest:
210b9f849186faf781911e0a4ca53ac105cf3b3d9a7704ba028fa40879a64cbd - Sigstore transparency entry: 1437298995
- Sigstore integration time:
-
Permalink:
joelee/gmail-tool@456857e1a4d6c5ed5788f96d757c055fbce9d501 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/joelee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@456857e1a4d6c5ed5788f96d757c055fbce9d501 -
Trigger Event:
push
-
Statement type: