mailerlite-python is an API wrapper for MailerLite, written in Python
pip install mailerlite-python
from mailerlite.client import Client
client = Client('API_KEY')
subs = client.list_subscribers(params=None)
# Optional params (dict):
# filter[status] = Must be one of the possible statuses: active, unsubscribed, unconfirmed, bounced or junk.
# limit = Defaults to 25
# page = Defaults to 1
subscriber = {
"email": "carlos@burgos.com",
"fields": {
"name": "Carlos",
"last_name": "Burgos",
"city": "Bogotá",
}
}
sub = client.create_subscriber(subscriber)
# If user email already exists, updates existing subscriber.
# Reference can be either email or ID
subscriber = client.fetch_subscriber(reference)
client.delete_subscriber(subscriber_id)
client.activate_subscriber(subscriber_id)
client.unsubscribe_subscriber(subscriber_id)
client.assign_to_group(subscriber_id, group_id)
fields = client.list_subscriber_fields()
groups = client.list_groups(params=None)
# Optional params (dict):
# filter[name] = Returns partial matches
# limit = An account can have at most a 250 groups
# page = Defaults to 1
# sort = Can be one of: name, total, open_rate, click_rate, created_at. Defaults to ascending order; prepend (-)
webhooks = client.list_webhooks()
webhook = {
"name": "first webhook",
"events": ["subscriber.created"],
"url": "http://www.cartwright.info/eligendi-soluta-corporis-in-quod-ullam"
}
webhook_created = client.create_webhook(webhook)
client.delete_webhook(webhook_id)