Python Wrapper for Mailerlite API v2
This client is hosted at PyPi under the name mailerlite-api-python, to install it, simply run
pip install mailerlite-api-python
or install dev version:
git clone https://github.com/skoudoro/mailerlite-api-python.git
pip install -e .
First, Grab YOUR_API_KEY from your Mailerlite account (Profile > Integrations > Developer Api).
>>> from mailerlite import MailerLiteApi
>>> api = MailerLiteApi('YOUR_API_KEY')
>>> all_campaigns = api.campaigns.all()
>>> draft = api.compaings.all(status='draft')
>>> one_campaign = all_campaigns[0]
>>> html = '<h1>Title</h1><p>Content</p><p><small><a href=\"{$unsubscribe}\">Unsubscribe</a></small></p>'
>>> plain = "Your email client does not support HTML emails. "
>>> plain += "Open newsletter here: {$url}. If you do not want"
>>> plain += " to receive emails from us, click here: {$unsubscribe}"
>>> api.campaigns.update(one_campaign.id, html=html, plain=plain)
>>> data = {"subject": "Regular campaign subject",
"groups": [2984475, 3237221],
"type": "regular"}
>>> api.campaign.create(data)
>>> api.campaign.delete(campaign_id=3971635)
>>> api.campaign.count()
>>> api.campaign.count(status='draft')
>>> api.subscribers.all()
>>> api.subscribers.all(stype='active')
>>> api.subscribers.active()
>>> api.subscribers.get(email='[email protected]')
>>> api.subscribers.get(id=1343965485)
>>> api.subscribers.search(search='[email protected]')
>>> api.subscribers.groups(id=1343965485)
>>> api.subscribers.activity(id='1343965485')
>>> data = {'name': 'John',
'email': '[email protected]',
'fields': {'company': 'MailerLite'}
}
>>> api.subscribers.create(data)
>>> data = {'name': 'John',
'fields': {'company': 'MailerLite'}
}
>>> api.subscribers.update(data, id='1343965485')
Get the total count of all subscribers in a single call.
Please, be aware that is not documented in the official API.
>>> api.subscribers.count()
Need documentation...
>>> api.segments.all()
>>> api.segments.count()
>>> api.fields.all()
>>> api.fields.get(field_id=123456)
>>> api.fields.create(title="my custom title")
>>> api.fields.update(field_id=123456, title="my new title 2")
>>> api.fields.delete(field_id=123456)
>>> api.webhooks.all()
>>> api.webhooks.get(webhook_id=123456)
>>> api.webhooks.create(url="https://yoursite/script-is-here",
... event="subscriber.create")
>>> api.webhooks.update(webhook_id=123456,
... url="https://yoursite/script-is-here",
... event="subscriber.create")
>>> api.webhooks.delete(webhook_id=123456)
# Get some info or stats
>>> api.account.info()
>>> api.account.stats()
>>> api.account.double_optin()
# Set up the double_optin
>>> api.account.set_double_optin(True)
>>> batch_requests = {"requests": [{"method":"GET",
... "path": "/api/v2/groups"
... },
... {"method":"POST",
... "path": "/api/v2/groups",
... "body": {"name": "New group"}
... }
... ]
... }
>>> api.batch(batch_requests)
We love contributions!
You've discovered a bug or something else you want to change - excellent! Create an issue!
You've worked out a way to fix it โ even better! Submit a Pull Request!
Start with the contributing guide!
Project under 3-clause BSD license, more informations here