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

ldraney_gmail_sdk-0.1.0.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.

ldraney_gmail_sdk-0.1.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file ldraney_gmail_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: ldraney_gmail_sdk-0.1.0.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 ldraney_gmail_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6f450945804105b3d91e6b18911e511f25336a44a5eaa3d3157928fb19e341ff
MD5 d1a29285e1255172038d8b77ecdd5a72
BLAKE2b-256 4816fe41bd3e87e591e4f28b30ed6c09ff57c5616c067fe21f7314f1ddd48df4

See more details on using hashes here.

File details

Details for the file ldraney_gmail_sdk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ldraney_gmail_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4defcaaa223d7dda8ab83f026a2138461a159a60905e623a5a7e20f9d72f7736
MD5 a282824e6dd272c223c022eb3507c75d
BLAKE2b-256 4fbacad1996ac18aa46c02c42220c988207018f78722fb042a3676d81734c5c4

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