Skip to main content

Python SDK for the Gmail REST API

Project description

gmail-sdk

Python SDK for the Gmail REST API. Uses httpx directly — no google-api-python-client.

Install

pip install ldraney-gmail-sdk

Quick Start

from gmail_sdk import GmailClient

# Load token from ~/secrets/google-oauth/gmail-draneylucas.json
client = GmailClient(account="draneylucas")
print(client.get_profile())

# List unread messages
messages = client.list_messages(query="is:unread", max_results=5)

# Send an email
client.send_message(to="someone@example.com", subject="Hello", body="Hi there!")

# Reply to a message
client.reply(message_id="abc123", body="Thanks!")

# Send an HTML email
client.send_message(
    to="someone@example.com",
    subject="Hello",
    body="Plain text fallback",
    html_body="<h1>Hello!</h1><p>This is <b>HTML</b>.</p>",
)

# Reply-all, mark as read/unread
client.reply_all(message_id="abc123", body="Thanks everyone!")
client.mark_as_read(message_id="abc123")
client.mark_as_unread(message_id="abc123")

# List mailbox changes since a history ID (for incremental sync)
profile = client.get_profile()
changes = client.list_history(start_history_id=profile["historyId"])

First-Time Setup

Run the OAuth flow to authorize an account:

from gmail_sdk import GmailClient

client = GmailClient.authorize(account="draneylucas")
print(client.get_profile())

This opens a browser for Google sign-in and saves the token for future use.

Multi-Account

personal = GmailClient(account="draneylucas")
work = GmailClient(account="lucastoddraney")
dev = GmailClient(account="devopsphilosopher")

Configuration

  • Secrets directory: ~/secrets/google-oauth/ (override with secrets_dir= or GMAIL_SECRETS_DIR env var)
  • Credentials file: {secrets_dir}/credentials.json
  • Token files: {secrets_dir}/gmail-{account}.json

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_sdk_ldraney-0.1.2.tar.gz (18.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_sdk_ldraney-0.1.2-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file gmail_sdk_ldraney-0.1.2.tar.gz.

File metadata

  • Download URL: gmail_sdk_ldraney-0.1.2.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for gmail_sdk_ldraney-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f7790a6da7b039936b820a15e559f9b6731724494390badbc8242dc483919e07
MD5 8bfc620177178d088d579c250ebcd062
BLAKE2b-256 6b1763a59512ab915ff04476cd9a3b70c27061dc6f39c21e8b49360518b7ae23

See more details on using hashes here.

File details

Details for the file gmail_sdk_ldraney-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for gmail_sdk_ldraney-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1cb34e6890c93cbbf0e2ff47e68f182a95100f72e6ae72810bb45dd4bea60a0f
MD5 7c91c9f3b360ee0154b3a004088f2eb5
BLAKE2b-256 f8c3e5a152c1857f9400c9be8b8be2952a719b7b9d11518527f81b1e05055c9d

See more details on using hashes here.

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