Skip to main content

Listmonk Email App API Client for Python

Project description

Listmonk Email App 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 (i.e. password reset emails).

Installation

Just pip install listmonk

Usage

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

listmonk.login('sammyz', '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()
list: MailingList = listmonk.list(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
updated_subscriber = listmonk.update_subscriber(new_subscriber, {4, 6}, {5})

# 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, transacational 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')

Want to contribute?

PRs are welcome. 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.1.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

listmonk-0.1.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for listmonk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 65e9d84c94716b1c30848aa911270e3b371d6320d5b76db2eb2c998b5fa38ca1
MD5 354c4e8c613bb8bbb572765204ec0e17
BLAKE2b-256 ed17450e97b3003f4d87e9af9bb42fb708c811d5e5248685d75828e4cb3470ea

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for listmonk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5437ed9035c0055ce78fe29d386f6626318adcc9ca90a6608ef034d9d47c5b9d
MD5 7052cbcb6fc0480245af464038260319
BLAKE2b-256 91f9b0a3ec61b97449e574b2d3b56713d6a06ba8018914c6db7f0f458e103c66

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