Skip to main content

Listmonk Email API Client for Python

Project description

Listmonk Email API Client for Python

Client for the for open source, self-hosted Listmonk email platform based on httpx and pydantic.

listmonk is intended for integrating your Listmonk instance into your web app. The Listmonk API is extensive but this only covers the subset that most developers will need for common SaaS actions such as subscribe, unsubscribe, and segmentate users (into separate lists).

So while it doesn't currently cover every endpoint (for example you cannot create a list programatically nor can you edit HTML templates for campaigns over APIs) it will likely work for you. That said, PRs are weclome.

🔀 Async is currently planned but not yet implemented. With the httpx-base, it should be trivial if needed.

Core Features

  • Add a subscriber to your subscribed users.
  • 🙎 Get subscriber details by email, ID, UUID, and more.
  • 📝 Modify subscriber details (including custom attribute collection).
  • 🔍 Search your users based on app and custom attributes.
  • 🏥 Check the health and connectivity of your instance.
  • 👥 Retrieve your segmentation lists, list details, and subscribers.
  • 🙅 Unsubscribe and block users who don't want to be contacted further.
  • 💥 Completely delete a subscriber from your instance.
  • 📧 Send transactional email with template data (e.g. password reset emails).

Installation

Just pip install listmonk

Usage

import pathlib
import listmonk

listmonk.set_url_base('https://yourlistmonkurl.com')

listmonk.login('sammy_z', '1234')
valid: bool = listmonk.verify_login()

# Is it alive and working?
up: bool = listmonk.is_healthy()

# Read data about your lists
lists: list[] = listmonk.lists()
the_list: MailingList = listmonk.list_by_id(list_id=7)

# Various ways to access existing subscribers
subscribers: list[] = listmonk.subscribers(list_id=9)

subscriber: Subscriber = listmonk.subscriber_by_email('testuser@some.domain')
subscriber: Subscriber = listmonk.subscriber_by_id(2001)
subscriber: Subscriber = listmonk.subscriber_by_uuid('f6668cf0-1c...')

# Create a new subscriber
new_subscriber = listmonk.create_subscriber(
           'testuser@some.domain', 'Jane Doe',
            {1, 7, 9}, pre_confirm=True, attribs={...} )

# Change the email, custom rating, and add to lists 4 & 6, remove from 5.
subscriber.email = 'newemail@some.domain'
subscriber.attribs['rating'] = 7
subscriber = listmonk.update_subscriber(subscriber, {4, 6}, {5})

# Confirm single-opt-ins via the API (e.g. for when you manage that on your platform)
listmonk.confirm_optin(subscriber.uuid, the_list.uuid)

# Disable then re-enable a subscriber
subscriber = listmonk.disable_subscriber(subscriber)
subscriber = listmonk.enable_subscriber(subscriber)

# Block (unsubscribe) them
listmonk.block_subscriber(subscriber)

# Fully delete them from your system
listmonk.delete_subscriber(subscriber.email)

# Send an individual, transactional email (e.g. password reset)
to_email = 'testuser@some.domain'
from_email = 'app@your.domain'
template_id = 3  # *TX* template ID from listmonk
template_data = {'full_name': 'Test User', 'reset_code': 'abc123'}

status: bool = listmonk.send_transactional_email(
                     to_email, template_id, from_email=from_email, 
                     template_data=template_data, content_type='html')

# You can also add one or multiple attachments with transactional mails
attachments = [
    pathlib.Path("/path/to/your/file1.pdf"),
    pathlib.Path("/path/to/your/file2.png")
]

status: bool = listmonk.send_transactional_email(
    to_email,
    template_id,
    from_email=from_email,
    template_data=template_data,
    attachments=attachments,
    content_type='html'
)

Want to contribute?

PRs are welcome. But please open an issue first to see if the proposed feature fits with the direction of this library.

Enjoy.

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

listmonk-0.2.0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

listmonk-0.2.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file listmonk-0.2.0.tar.gz.

File metadata

  • Download URL: listmonk-0.2.0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for listmonk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 72840cb7d2c4b82daabb6e534bc44dfcada21cfc85dae7d852512faa4bddff04
MD5 fd2178e2043effe49ad27548466dcaeb
BLAKE2b-256 ebf630f994672894ffc73869a062984a1750989359b9ee4c090e95f8c663d4cb

See more details on using hashes here.

File details

Details for the file listmonk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: listmonk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for listmonk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2733c0bb1c108308797c255bb7716e8974e519bea2cd07f1a891613d93c99a0e
MD5 07365946830d0de34de327ab59d5108a
BLAKE2b-256 974b0271e14851efaff6ae066bb86e56ff944eebe20ff73c096145485b3c5fb2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page