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
Choose auth mode in config.toml.
Credential setup instructions are in docs/google-credentials.md.
Quick Start
- Install
uv. - Copy
.env.sampleto.envand fill required values. - Review
config.tomland adjust auth settings. - Install dependencies:
uv sync --dev
- 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
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.
Development
uv sync --dev
uv run pytest --cov=src/gmail_tool --cov-report=term-missing
uv run pre-commit run --all-files
Releases
PyPI publishing is handled by the GitHub Actions Publish workflow on version tags such as v0.2.1.
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.1.tar.gz.
File metadata
- Download URL: gmail_tool-0.2.1.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68d23d0f845888a304a68b1cf7bd79c363f0a86c0a9ce2279339da1c2aec4399
|
|
| MD5 |
feaa11221708ff32a25d0d749763fe62
|
|
| BLAKE2b-256 |
061729e7b3be943f4c65eef545d3945c569e480a873e3dd00582754ce28531d6
|
Provenance
The following attestation bundles were made for gmail_tool-0.2.1.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.1.tar.gz -
Subject digest:
68d23d0f845888a304a68b1cf7bd79c363f0a86c0a9ce2279339da1c2aec4399 - Sigstore transparency entry: 1435328028
- Sigstore integration time:
-
Permalink:
joelee/gmail-tool@2c60a6df79bad4b8d59fdbd3fd893a6e2fe9ea60 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/joelee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2c60a6df79bad4b8d59fdbd3fd893a6e2fe9ea60 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gmail_tool-0.2.1-py3-none-any.whl.
File metadata
- Download URL: gmail_tool-0.2.1-py3-none-any.whl
- Upload date:
- Size: 16.0 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 |
bbf3ef0c99d668ed2e928a9a57111c3d3ed2612f044494706f9b2e2cf883c4fe
|
|
| MD5 |
147340bb7672977c0e4eda7990ba09cc
|
|
| BLAKE2b-256 |
b673502422f900b5f6eb9a64582f8ea2eb86a2debf1c4e43bc0b35f3cfd26af6
|
Provenance
The following attestation bundles were made for gmail_tool-0.2.1-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.1-py3-none-any.whl -
Subject digest:
bbf3ef0c99d668ed2e928a9a57111c3d3ed2612f044494706f9b2e2cf883c4fe - Sigstore transparency entry: 1435328031
- Sigstore integration time:
-
Permalink:
joelee/gmail-tool@2c60a6df79bad4b8d59fdbd3fd893a6e2fe9ea60 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/joelee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2c60a6df79bad4b8d59fdbd3fd893a6e2fe9ea60 -
Trigger Event:
push
-
Statement type: