Skip to main content

msgine

Python client for the MsGine messaging API: SMS, WhatsApp, email, push, workflows and webhooks.

Documentation: https://docs.msgine.net

Install

pip install msgine

Requires Python 3.10 or newer. The only dependency is httpx.

Quick start

from msgine import MsGine

with MsGine("msg_<kid>_<secret>") as client:
    message = client.sms.send(to="+256700000001", message="Your code is 4821")
    print(message["id"], message["status"])

Async:

import asyncio
from msgine import AsyncMsGine

async def main() -> None:
    async with AsyncMsGine("msg_<kid>_<secret>") as client:
        page = await client.sms.list(page=1, limit=20)
        print(page.total, len(page.items))

asyncio.run(main())

Both clients expose the same resources and methods. Parameters are keyword-only and snake_case (scheduled_for, idempotency_key, from_); they are sent under their API names. Nested data such as payload, definition or android is sent as given. Responses are plain dicts with the API's camelCase keys. List calls return Page(items, total, page, pages).

Configuration

MsGine(
    api_key,
    signing_secret=None,
    base_url="https://api.msgine.net/api/v1",
    timeout=30.0,
    max_retries=2,
    http_client=None,
)

http_client takes an httpx.Client (httpx.AsyncClient for AsyncMsGine) to share a connection pool or set proxies. A client you pass in is not closed by close().

Sending

client.sms.send(to=["+256700000001", "+256700000002"], message="Hello", scheduled_for="2026-12-25T09:00:00Z")

client.whatsapp.send(to="+256700000001", template_id="order_update", template_language="en",
                     template_params=["A-1042"])

client.email.send(from_="hello@example.com", to="user@example.com", subject="Receipt", html="<p>Thanks</p>")

client.push.send(title="Order shipped", body="On its way", external_user_ids=["user-42"])

client.events.send(name="order.created", payload={"orderId": "A-1042"}, phone="+256700000001")

Email is transactional only. Recipients may be a string or a list. Every send carries an idempotency key: yours (idempotency_key=) or a generated one that is reused across retries.

Other resources: messages, webhooks, workflows (runs, launches, hooks, secrets, messaging_policy), opt_outs, contact_fields, analytics, push.devices, push.config.

Webhooks

Verify the raw request body, not re-serialised JSON.

from fastapi import FastAPI, HTTPException, Request
from msgine import WebhookVerificationError, verify_webhook

app = FastAPI()

@app.post("/msgine")
async def receive(request: Request) -> dict[str, bool]:
    try:
        event = verify_webhook(
            await request.body(),
            request.headers.get("x-msgine-signature"),
            "whsec_...",
        )
    except WebhookVerificationError:
        raise HTTPException(status_code=400)
    print(event["event"], event["data"])
    return {"ok": True}

Signatures older than 300 seconds are refused; change it with tolerance=. Several v1 signatures are accepted, so a rotated secret can overlap.

Errors and retries

API errors raise MsGineError with status, code, message, details, retry_after and body. Network failures and timeouts raise MsGineConnectionError (status 0, code connection_error or timeout).

from msgine import MsGineError

try:
    client.sms.send(to="x", message="Hi")
except MsGineError as error:
    print(error.status, error.code, error.details)

Up to max_retries retries (default 2). A 429 is always retried. Network errors, 408 and 5xx are retried only for requests that are safe to repeat: GET, PUT and DELETE, and sends, which carry an idempotency key. The wait follows Retry-After (1 to 60 seconds) or backs off exponentially from 1 second.

Sandbox keys

A key created with the sandbox environment validates and records requests but sends nothing and charges nothing. Use one in tests and CI.

Request signing

Pass signing_secret to sign every request with x-timestamp and x-signature headers (HMAC-SHA256 of method, path and query, timestamp and body hash). A fresh signature is computed for each attempt.

client = MsGine("msg_<kid>_<secret>", signing_secret="sk_...")

Metadata

Release files for msgine 1.0.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 msgine 1.0.0
File Size Uploaded Provenance Actions
msgine-1.0.0.tar.gz 12.4 kB With provenance Details for msgine-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 25.1 kB

Release files / msgine-1.0.0.tar.gz

Download URL msgine-1.0.0.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
07bb3575e90d29d72abcb9d8841a6a740a58f8e1d5f5eed17af93a473b40ab55
BLAKE2b-256 checksum
How to use checksums
87a0840d32d4cb00dc16b39d24671f61ed726a7336eeeb184382d67e2704bde7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 2, 2026.

Transparency log

Release files / msgine-1.0.0-py3-none-any.whl

Download URL msgine-1.0.0-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29b16a23e77a1db509b070c484c761f33b651cea515d753113b2b52584b10b55
BLAKE2b-256 checksum
How to use checksums
47973751e5cef43a7f045bb79d6862a6dad801de1aefc7d1e96281357aa7e854
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 2, 2026.

Transparency log

Security for msgine 1.0.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for msgine-1.0.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 Dec 2, 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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

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