Skip to main content

Python SDK for the Gmail REST API

Project description

PyPI License: MIT Python 3.10+

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.3.tar.gz (19.9 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.3-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gmail_sdk_ldraney-0.1.3.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gmail_sdk_ldraney-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a1378d36c0a3421575794feeaaf0eeb864e919e053497d3fa9c2092c0bf5b303
MD5 c9ada68d3329fd6cee46b8a43eb13f8e
BLAKE2b-256 829b81cdf50aa0b0078fbebdcdcafc434cd40b786b318bebaa1dd50f2f0cab62

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmail_sdk_ldraney-0.1.3.tar.gz:

Publisher: publish.yml on ldraney/gmail-sdk

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_sdk_ldraney-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for gmail_sdk_ldraney-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 28f05437930a21c34ef9808d1edc26b04282a463246713375646ae4569a7ffd3
MD5 fbc360a8305c4aae777d9dc93ef0b199
BLAKE2b-256 7b0c7fb424dd7b36b270bc3be5fc5f026d2467d865ec5b7997855eb8c96119ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmail_sdk_ldraney-0.1.3-py3-none-any.whl:

Publisher: publish.yml on ldraney/gmail-sdk

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