Skip to main content

CLI tool to download Gmail messages matching configurable filters via OAuth2

Project description

gmailstream

📧 Download Gmail messages matching your filters to local files 📥

gmailstream is a Python CLI for downloading Gmail messages through OAuth2. It uses named profiles so each export can keep its own Gmail search query, credentials, mode, and target directory.

Use it to archive full .eml messages or save attachments from messages matched by Gmail search filters such as from:, has:attachment, after:, labels, and other Gmail query syntax.

Install

git clone https://github.com/tsilva/gmailstream.git
cd gmailstream
uv tool install . --force --no-cache

Create and authorize a profile, then run it:

gmailstream profiles init my-profile
gmailstream --profile my-profile

The init flow prompts for a Gmail filter, output directory, download mode, and a Google OAuth credentials.json file. See Creating OAuth Credentials for the Google Cloud setup.

Commands

uv sync                                           # install development dependencies
uv tool install . --force --no-cache              # install the CLI from this checkout
gmailstream --profile <profile>                   # download new matching messages
gmailstream --profile <profile> --from 2024-01-01 # limit by start date
gmailstream --profile <profile> --to 2024-12-31   # limit by end date
gmailstream --verbose --profile <profile>         # enable debug logging
gmailstream --profile-dir /path --profile <name>  # use a custom profiles directory
gmailstream profiles list                         # list profiles
gmailstream profiles init <name>                  # create and authenticate a profile
gmailstream profiles show <name>                  # print profile config

Notes

  • Requires Python 3.12+ and uv.
  • Profiles live in ~/.config/gmailstream/profiles/ by default. Override this with --profile-dir or GMAIL_STREAMER_PROFILE_DIR.
  • Environment variables are loaded from ~/.config/gmailstream/.env when present. Existing shell environment variables take priority.
  • A profile can also be passed as a direct path to an existing profile directory.
  • The legacy gmailstream run <profile> command still works.
  • Each profile contains config.yaml, user-supplied credentials.json, and auto-generated token.json.
  • mode: full saves message.eml, attachments, and metadata.json. mode: attachments_only saves attachments plus metadata.json.
  • Downloads are organized under the target directory as YYYY-MM/YYYY-MM-DD - subject - shortid/.
  • Runs are incremental by default. Explicit --from or --to date ranges search that date range and skip files already present there.
  • credentials.json, token.json, and downloaded email exports are sensitive local files. On POSIX systems, gmailstream writes them with user-only permissions, and credentials/tokens are ignored by git.

Architecture

gmailstream architecture diagram

License

MIT

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

gmailstream-0.2.2.tar.gz (10.7 MB view details)

Uploaded Source

Built Distribution

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

gmailstream-0.2.2-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file gmailstream-0.2.2.tar.gz.

File metadata

  • Download URL: gmailstream-0.2.2.tar.gz
  • Upload date:
  • Size: 10.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for gmailstream-0.2.2.tar.gz
Algorithm Hash digest
SHA256 892ceed0973244c794bb1e231cf61b01935ff4511e5f851170282d860092c769
MD5 0502afb9754970d8398425fe4ea1fd12
BLAKE2b-256 f0151c0e3c9a0a97e90ca192a2bc3c8105fb1b10ca8567a1fcdae18c3c9e00db

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmailstream-0.2.2.tar.gz:

Publisher: release.yml on tsilva/gmailstream

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

File details

Details for the file gmailstream-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: gmailstream-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for gmailstream-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f4ea378c60f845c1b68a0c39b8e1ff385197d7685374adf7445ce692f2c3ce93
MD5 1b0e594c18deb98d0a877a9647adfce5
BLAKE2b-256 6d20646095a78eed596f52e54e3c591c34f1015e6e89659bb3b278b273bcca7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmailstream-0.2.2-py3-none-any.whl:

Publisher: release.yml on tsilva/gmailstream

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