Skip to main content

Typed Python client for the Mailisk API

Project description

Mailisk Python Client

Typed Python client for the Mailisk REST API.

Mailisk is an email, SMS, outbound email, and TOTP testing platform. This package mirrors the Mailisk Node client API surface in a Python-friendly shape: methods use snake_case, response bodies stay as normal dictionaries, and the package ships TypedDict/Literal types plus py.typed.

Installation

pip install mailisk

Create A Client

Get your API key from Mailisk and pass it directly when creating a client:

from mailisk import MailiskClient

mailisk = MailiskClient(api_key="YOUR_API_KEY")

The library does not read .env files or environment variables by itself. Applications should load configuration however they prefer, then pass values to the client:

from mailisk import MailiskClient

api_key = load_api_key_from_your_config()
mailisk = MailiskClient(api_key=api_key)

Quick Start

from mailisk import MailiskClient

mailisk = MailiskClient(api_key="YOUR_API_KEY")

result = mailisk.search_inbox("mynamespace")
print(result["data"])

The client exposes Python method names such as search_inbox and list_namespaces. CamelCase aliases such as searchInbox and listNamespaces are also available for developers porting from the Node client.

Defaults

search_inbox and search_sms_messages match the Node client defaults:

  • wait for at least one matching message unless wait is False
  • ignore messages older than 15 minutes unless a lower bound is provided
  • use a 5 minute timeout while waiting
  • allow a high redirect count for wait endpoints

Timeouts are in seconds because the client uses requests:

mailisk.search_inbox(
    "mynamespace",
    {"to_addr_prefix": "john@mynamespace.mailisk.net"},
    {"timeout": 60},
)

Email

Search inbox:

response = mailisk.search_inbox(
    "mynamespace",
    {
        "to_addr_prefix": "john@mynamespace.mailisk.net",
        "subject_includes": "password",
    },
)

emails = response["data"]

List namespaces:

namespaces = mailisk.list_namespaces()
print([item["namespace"] for item in namespaces["data"]])

Download an attachment:

attachment_id = emails[0]["attachments"][0]["id"]
content = mailisk.download_attachment(attachment_id)

Outbound Email

Send an outbound email:

email = mailisk.send_email(
    "mynamespace",
    {
        "from": {"email": "support@mynamespace.mailisk.net", "name": "Support"},
        "to": ["verified@example.com"],
        "subject": "Hello from Mailisk",
        "text": "Plain text body",
        "html": "<p>HTML body</p>",
    },
)

print(email["id"], email["status"])

Send with an attachment:

import base64
from pathlib import Path

content = Path("report.txt").read_bytes()

mailisk.send_email(
    "mynamespace",
    {
        "to": ["verified@example.com"],
        "subject": "Report",
        "text": "Attached.",
        "attachments": [
            {
                "filename": "report.txt",
                "content_type": "application/octet-stream",
                "content_base64": base64.b64encode(content).decode("ascii"),
            }
        ],
    },
)

Fetch delivery details:

detail = mailisk.get_outbound_email(email["id"])
print(detail["delivery_summary"])

Reply to an inbound email:

reply = mailisk.reply_to_email(
    emails[0]["id"],
    {
        "subject": "Re: Thanks",
        "text": "We received your message.",
    },
)

Forward an inbound email:

forwarded = mailisk.forward_email(
    emails[0]["id"],
    {
        "to": ["verified@example.com"],
        "subject": "Fwd: Support request",
        "text": "Forwarding this along.",
    },
)

SMS

Search SMS messages:

messages = mailisk.search_sms_messages(
    "+15551234567",
    {"from_number": "+1800555", "body": "Your code"},
)

List SMS numbers:

numbers = mailisk.list_sms_numbers()

Send a virtual SMS:

mailisk.send_virtual_sms(
    {
        "from_number": "+15550000001",
        "to_number": "+15550000002",
        "body": "Test message",
    }
)

TOTP

Create a saved TOTP device:

device = mailisk.create_totp_device(
    {
        "name": "GitHub staging",
        "shared_secret": "JBSWY3DPEHPK3PXP",
    }
)

Generate a TOTP code from a shared secret:

otp = mailisk.get_totp_otp_by_shared_secret(
    "JBSWY3DPEHPK3PXP",
    {"min_seconds_until_expire": 10},
)

print(otp["code"])

Generate a TOTP code for a saved device:

otp = mailisk.get_totp_otp_by_device_id(device["id"])

Delete a saved TOTP device:

mailisk.delete_totp_device(device["id"])

Development Checks

See DEVELOPMENT.md for local setup, .env configuration, and the live outbound smoke test.

python -m pytest
python -m mypy src tests
python -m build

Typing

The package includes py.typed and exports TypedDict/Literal types for API parameters and responses:

from mailisk import MailiskClient, SearchInboxResponse

client = MailiskClient(api_key="YOUR_API_KEY")
response: SearchInboxResponse = client.search_inbox("mynamespace")

You can import request and response types from mailisk directly, for example SendEmailParams, SearchInboxResponse, OutboundEmailResponse, OutboundEmailDetailResponse, and TotpOtpResponse.

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

mailisk-0.9.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

mailisk-0.9.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file mailisk-0.9.0.tar.gz.

File metadata

  • Download URL: mailisk-0.9.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for mailisk-0.9.0.tar.gz
Algorithm Hash digest
SHA256 fa3c6cf6e85ce187909bd9bd91d9e3937d346eeec5e72fdf14dda2b94a774b00
MD5 c2ac77aa6c2d400560ad87143422e50c
BLAKE2b-256 3106824c520c82f441bd8cfc95c068b7c18549fab4fd0030ec33d50d31b14cfa

See more details on using hashes here.

File details

Details for the file mailisk-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: mailisk-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for mailisk-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36d9aa2064f339bb6c20acf90dfefeaed3e70faa55f5d9f4dc404db9d4dcb86c
MD5 737fe94f0fa2001220a97bf8f8de0e99
BLAKE2b-256 095f2cd93b93f3610ce6aa3d38f196ae22e568b65648260906343a1ed25aab6a

See more details on using hashes here.

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