Skip to main content

Official Mailrify Python SDK

Project description

Mailrify Python SDK

Official Python SDK for the Mailrify API.

Installation

pip install mailrify

Quick Start (Sync)

from mailrify import Mailrify

client = Mailrify("sk_your_api_key")

Quick Start (Async)

from mailrify import AsyncMailrify

client = AsyncMailrify("sk_your_api_key")

Emails

from mailrify import Mailrify

client = Mailrify("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>",
    data={"name": "John"},
)

verification = client.emails.verify("user@example.com")
print(verification.valid, verification.is_random_input)

Events

from mailrify import Mailrify

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

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

Contacts

from mailrify import Mailrify

client = Mailrify("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 mailrify import Mailrify

client = Mailrify("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)

Campaigns

from mailrify import Mailrify

client = Mailrify("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 mailrify import AsyncMailrify


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


asyncio.run(main())

Configuration

from mailrify import Mailrify

client = Mailrify(
    "sk_your_api_key",
    base_url="https://api.mailrify.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

mailrify-1.0.0.tar.gz (33.5 kB view details)

Uploaded Source

Built Distribution

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

mailrify-1.0.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file mailrify-1.0.0.tar.gz.

File metadata

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

File hashes

Hashes for mailrify-1.0.0.tar.gz
Algorithm Hash digest
SHA256 12fcc1c75e0fd76ad507f5490254e4185ff460409a4426c99cbeef758b34a4e8
MD5 324623128a6fa6076b14b11128c3f432
BLAKE2b-256 4823bf01a0345a657af721bfae751e4e57d389738e36fe4fefaf03e9fa9bf0b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for mailrify-1.0.0.tar.gz:

Publisher: publish.yml on Mailrify/mailrify-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 mailrify-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mailrify-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mailrify-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8308172429be6aeed04a297202bd023f2ee0c05e8da15a85af91f6c44e5bd6c5
MD5 97d29ddfbfe687f67cb8ff9fb176da1d
BLAKE2b-256 6c905c1efdc7c35a89feba62cd2492a00d1d55fbce1317c7c1ceca109ebd4842

See more details on using hashes here.

Provenance

The following attestation bundles were made for mailrify-1.0.0-py3-none-any.whl:

Publisher: publish.yml on Mailrify/mailrify-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