Documentation Index
Fetch the complete documentation index at: https://docs.mailglyph.com/llms.txt
Use this file to discover all available pages before exploring further.
Use the official Python SDK to call the MailGlyph API from server-side apps.
Prerequisites
Before you start, make sure you have:
- A MailGlyph secret API key (
sk_...) for server-side API requests
- A MailGlyph public API key (
pk_...) for event tracking (/v1/track)
- At least one verified sending domain for email sending
Setup links:
Install
Initialize clients
Create one SDK client for your secret key and one for your public key:
from mailglyph import AsyncMailGlyph, MailGlyph
secret_client = MailGlyph("sk_your_secret_key")
public_client = MailGlyph("pk_your_public_key")
async_secret_client = AsyncMailGlyph("sk_your_secret_key")
async_public_client = AsyncMailGlyph("pk_your_public_key")
Set environment variables:
export MAILGLYPH_SECRET_KEY="sk_your_secret_key"
export MAILGLYPH_PUBLIC_KEY="pk_your_public_key"
Use this when testing against staging or local environments:
from mailglyph import MailGlyph
client = MailGlyph(
"sk_your_secret_key",
base_url="https://api.mailglyph.com",
timeout=30.0,
max_retries=3,
)
Key usage rules
The Python SDK enforces key restrictions automatically:
pk_* keys can only call events.track
sk_* keys can call all non-track endpoints, including events.get_names
from mailglyph import MailGlyph
from mailglyph.exceptions import AuthenticationError
secret_client = MailGlyph("sk_your_secret_key")
try:
secret_client.events.track(email="[email protected]", event="purchase")
except AuthenticationError as error:
print(error.message)
finally:
secret_client.close()
Close clients
Use context managers or call close() / await close() explicitly:
from mailglyph import AsyncMailGlyph, MailGlyph
with MailGlyph("sk_your_secret_key") as client:
verification = client.emails.verify("[email protected]")
print(verification.valid)
async def run_async() -> None:
async with AsyncMailGlyph("sk_your_secret_key") as client:
verification = await client.emails.verify("[email protected]")
print(verification.valid)
Next pages