Skip to main content

Official MailGlyph Python SDK

Project description

MailGlyph Python SDK

CI Release Please Publish to PyPI

Official Python SDK for the MailGlyph API.

Installation

pip install mailglyph

Quick Start (Sync)

from mailglyph import MailGlyph

client = MailGlyph("sk_your_api_key")

Quick Start (Async)

from mailglyph import AsyncMailGlyph

client = AsyncMailGlyph("sk_your_api_key")

Emails

from mailglyph import MailGlyph

client = MailGlyph("sk_your_api_key")

result = client.emails.send(
    to="user@example.com",
    from_={"name": "My App", "email": "hello@myapp.com"},
    subject="Welcome!",
    body="<h1>Hello {{name}}</h1>",
    text="Hello {{name}}",
    data={"name": "John"},
)

# Omit `text` to let MailGlyph auto-generate plain text from HTML `body`.
html_only_result = client.emails.send(
    to="user@example.com",
    from_="hello@myapp.com",
    subject="HTML Only",
    body="<h1>Hello</h1><p>This will get text/plain fallback.</p>",
)

# Set text="" to opt out of text/plain generation.
opt_out_result = client.emails.send(
    to="user@example.com",
    from_="hello@myapp.com",
    subject="No Plain Text Part",
    body="<h1>Hello</h1>",
    text="",
)

verification = client.verification.validate("user@example.com")
print(verification.valid, verification.smtp_status, verification.credits_consumed)

Email Verification

from mailglyph import MailGlyph

client = MailGlyph("sk_your_api_key")

result = client.verification.validate("user@example.com")
print(result.valid, result.validation_method, result.smtp_status)

bulk_job = client.verification.create_bulk(
    "emails.txt",
    content_type="text/plain",
)

jobs = client.verification.list_bulk(limit=20, status="COMPLETED")
job = client.verification.get_bulk(bulk_job.id)

if job.status == "ACTION_REQUIRED":
    job = client.verification.continue_bulk(job.id)

if job.ready_for_download:
    csv_bytes = client.verification.download_bulk(job.id, filter="all", format="csv")

deleted = client.verification.delete_bulk(job.id)
credits = client.verification.credits()
ledger = client.verification.credit_ledger(limit=25)

Events

from mailglyph import MailGlyph

tracker = MailGlyph("pk_your_public_key")
tracker.events.track(
    email="user@example.com",
    event="purchase",
    data={"product": "Premium", "amount": 99},
)

client = MailGlyph("sk_your_api_key")
names = client.events.get_names()

Contacts

from mailglyph import MailGlyph

client = MailGlyph("sk_your_api_key")

contacts = client.contacts.list(limit=50)
contact = client.contacts.create(email="new@example.com", data={"plan": "premium"})
client.contacts.update(contact.id, subscribed=False)
client.contacts.delete(contact.id)
count = client.contacts.count()

Segments

from mailglyph import MailGlyph

client = MailGlyph("sk_your_api_key")

segment = client.segments.create(
    name="Premium Users",
    condition={
        "logic": "AND",
        "groups": [
            {
                "filters": [
                    {"field": "data.plan", "operator": "equals", "value": "premium"}
                ]
            }
        ],
    },
    track_membership=True,
)
members = client.segments.list_contacts(segment.id, page=1)
added = client.segments.add_members(segment.id, emails=["alice@example.com", "bob@example.com"])
removed = client.segments.remove_members(segment.id, emails=["bob@example.com"])

Campaigns

from mailglyph import MailGlyph

client = MailGlyph("sk_your_api_key")

campaign = client.campaigns.create(
    name="Product Launch",
    subject="Introducing our new feature!",
    body="<h1>Big news!</h1><p>Check out our latest feature.</p>",
    from_email="hello@myapp.com",
    audience_type="ALL",
)

campaigns_page = client.campaigns.list(page=1, page_size=20, status="DRAFT")
client.campaigns.send(campaign.id, scheduled_for="2026-03-01T10:00:00Z")
client.campaigns.test(campaign.id, email="preview@myapp.com")
stats = client.campaigns.stats(campaign.id)
client.campaigns.cancel(campaign.id)

Async Example

import asyncio

from mailglyph import AsyncMailGlyph


async def main() -> None:
    async with AsyncMailGlyph("sk_your_api_key") as client:
        verification = await client.verification.validate("user@example.com")
        print(verification.valid)


asyncio.run(main())

Configuration

from mailglyph import MailGlyph

client = MailGlyph(
    "sk_your_api_key",
    base_url="https://api.mailglyph.com",
    timeout=30.0,
    max_retries=3,
)

Development

pip install -e .[dev]
ruff check .
mypy src/
pytest
hatch build

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

mailglyph-2.2.0.tar.gz (38.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mailglyph-2.2.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file mailglyph-2.2.0.tar.gz.

File metadata

  • Download URL: mailglyph-2.2.0.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mailglyph-2.2.0.tar.gz
Algorithm Hash digest
SHA256 c7a9c446a96941afc98fb443100061fbf704d1e686b9c65fd5d839d496d9b76b
MD5 92f5fff9666c33534ba72582cd31d44f
BLAKE2b-256 53395479d74a8d00767e475c28f937293199c6978a53334f468b926967661049

See more details on using hashes here.

Provenance

The following attestation bundles were made for mailglyph-2.2.0.tar.gz:

Publisher: publish.yml on MailGlyph/mailglyph-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mailglyph-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: mailglyph-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mailglyph-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 221d70f4a54c25a94ef1a622847396f8e329e32adbd6d945dc6e52139d7d28d8
MD5 d4cf0c4118cc761cc0caee24f75e9385
BLAKE2b-256 cba8c6f8c138ea6ad278d4958adce1258662e903550fcb5a9b2b8bb82a536b4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mailglyph-2.2.0-py3-none-any.whl:

Publisher: publish.yml on MailGlyph/mailglyph-python

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