Skip to main content

Simple MessageMedia API wrapper

PyPI CircleCI Python Versions

Simple and easy to use module for sending SMS and MMS messages through MessageMedia API.

Installation

The easiest way is to install the package from Python Package Index:

pip3 install messagemedia-simple

Note that messagemedia-simple is only available for Python 3.6 and newer. Installation for older Python versions will fail.

Usage - sending a SMS message

The module interface pretty much mirrors the MessageMedia Mesages API. Refer to the API documentation for details about all the possible settings.

from messagemedia_simple import MessagesAPI

API_KEY = "ABCDEFGH1234567890XX"
API_SECRET = "1234567890asdfghjkl1234567890x"

# MessageMedia API object
mm = MessagesAPI(API_KEY, API_SECRET, hmac_auth=True)

# Send a SMS message and print `message_id`
send_response = mm.send_message("Some content", "+1234567890")
print(f"message_id: {send_response['message_id']})

Now we can check the message delivery status as it progresses from enroute through submitted to delivered:

status_response = mm.get_message_status(send_response["message_id"])
print(f"status: {status_response['status']})

And finally we can retrieve Message Replies. Unfortunately through the API we can only retrieve all queued, unconfirmed replies rather than just those for a given message_id. The filtering has to be done locally after all the replies are retrieved.

# Retrieve all replies from MessageMedia
replies_response = mm.get_replies()

# Filter only the relevant replies
my_replies = [r for r in replies_response["replies"] if r["message_id"]==send_response["message_id"]]

# Process the replies
for reply in my_replies:
  print(f"{reply['content']}")

MessageMedia API has a concept of confirming a reply - as soon as a reply is confirmed it is no longer returned from get_replies() call. That means only confirm a reply after it's successfully processed, for example written to a local database. Multiple replies can be confirmed at once if needed.

for reply in my_replies:
  print(f"{reply['content']}")
  mm.confirm_replies(reply["reply_id"])

Likewise we can retrieve and confirm the delivery reports using get_delivery_reports() and confirm_delivery_reports(). The logic of the operation is the same as with replies.

Sending a MMS and specifying additional parameters

For MMS messages we can specify a few more options, for example Subject, embedded images, links, etc.

The send_message() function doesn't have named parameters for all the possible options. However we can pass any valid option as documented in the Send Message API. The extra parameters are not validated in any way and it's the caller responsibility to ensure that they are valid for the API.

response = mm.send_message(
    format = "MMS",
    subject = "Happy new year!",
    content = "All the best in 2020",
    media = [
        "https://images.pexels.com/photos/2526105/pexels-photo-2526105.jpeg?cs=srgb&dl=fireworks-display-2526105.jpg&h=853&w=1280"
    ],
    destination_number = "+123456789",
    scheduled = "2020-01-01T00:00:00.000Z",
    message_expiry_timestamp = "2020-01-01T01:23:45.678Z",
    metadata = { "new_year": 2020 },
)

Note that MMS sending has to be enabled first by MessageMedia support.

Author

Michael Ludvig @ enterprise IT

Metadata

Release files for messagemedia-simple 1.0.1

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

Source distribution (sdist)

Source distribution for messagemedia-simple 1.0.1
File Size Uploaded Provenance
messagemedia-simple-1.0.1.tar.gz 4.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for messagemedia-simple 1.0.1
File Interpreter ABI Platform
messagemedia_simple-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / messagemedia-simple-1.0.1.tar.gz

Download URL messagemedia-simple-1.0.1.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ab2420d5272f7109ff992c078016f81a16d9e9107ef43e589f0e30c7a7248041
BLAKE2b-256 checksum
How to use checksums
3b664c0d0781b236b82f269434ac7e25ff48319bda3b2cd8f7319962548af0da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.0 CPython/3.6.10 Linux/4.15.0-1052-aws

Release files / messagemedia_simple-1.0.1-py3-none-any.whl

Download URL messagemedia_simple-1.0.1-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
65007153036c31dc358e728dd4d360b563014c9e0af2adce09542b16c098fc04
BLAKE2b-256 checksum
How to use checksums
d6592a492f0eed4d4bf61f01af5c2dc6882c6485a66510c3e0107f21f5d19dc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.0 CPython/3.6.10 Linux/4.15.0-1052-aws

Security for messagemedia-simple 1.0.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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