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.1.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.1-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gmail_sdk_ldraney-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 d93f2a6b46a1916ae1d01f7ef152971fc61177e2de0779e0fdc5bec8a4c3e065
MD5 ff65e84cd312a6581994eca8e0285a10
BLAKE2b-256 8428c83ba25efb4a5b6b154a3633fb2651fb5e1755e060676e966dcf8c1c3ed1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gmail_sdk_ldraney-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d713ec43d7479cd70b4c7553de683cafbfb766ddae32b03c02132959776235fb
MD5 888608cd6140d454b22dfa66b28f0aac
BLAKE2b-256 c73475e999f078b4d99bc9582576b7b29164c561663941a6bb23d851881cc9c3

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