Skip to main content

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 label
    • list: print message headers (recipient, sender, date, subject) with --limit
  • Global filters:
    • date range via --from-date and --to-date
    • --starred true|false
  • 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

  1. Install uv.
  2. Copy .env.sample to .env and fill required values.
  3. Review config.toml and adjust auth settings.
  4. Install dependencies:
uv sync --dev
  1. 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
  1. 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.

  1. 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.

  1. 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

gmail_tool-0.2.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gmail_tool-0.2.1-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

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

Hashes for gmail_tool-0.2.1.tar.gz
Algorithm Hash digest
SHA256 68d23d0f845888a304a68b1cf7bd79c363f0a86c0a9ce2279339da1c2aec4399
MD5 feaa11221708ff32a25d0d749763fe62
BLAKE2b-256 061729e7b3be943f4c65eef545d3945c569e480a873e3dd00582754ce28531d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmail_tool-0.2.1.tar.gz:

Publisher: publish.yml on joelee/gmail-tool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for gmail_tool-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bbf3ef0c99d668ed2e928a9a57111c3d3ed2612f044494706f9b2e2cf883c4fe
MD5 147340bb7672977c0e4eda7990ba09cc
BLAKE2b-256 b673502422f900b5f6eb9a64582f8ea2eb86a2debf1c4e43bc0b35f3cfd26af6

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmail_tool-0.2.1-py3-none-any.whl:

Publisher: publish.yml on joelee/gmail-tool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page