Skip to main content

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

Metadata

Release files for mailglyph 2.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mailglyph 2.2.0
File Size Uploaded Provenance
mailglyph-2.2.0.tar.gz 38.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mailglyph 2.2.0
File Interpreter ABI Platform
mailglyph-2.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 55.8 kB

Release files / mailglyph-2.2.0.tar.gz

Download URL mailglyph-2.2.0.tar.gz
Size 38.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c7a9c446a96941afc98fb443100061fbf704d1e686b9c65fd5d839d496d9b76b
BLAKE2b-256 checksum
How to use checksums
53395479d74a8d00767e475c28f937293199c6978a53334f468b926967661049
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 19, 2026.

Transparency log

Release files / mailglyph-2.2.0-py3-none-any.whl

Download URL mailglyph-2.2.0-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
221d70f4a54c25a94ef1a622847396f8e329e32adbd6d945dc6e52139d7d28d8
BLAKE2b-256 checksum
How to use checksums
cba8c6f8c138ea6ad278d4958adce1258662e903550fcb5a9b2b8bb82a536b4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 19, 2026.

Transparency log

Security for mailglyph 2.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mailglyph-2.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page