Skip to content

Repository files navigation

MailerLite Python SDK

MIT licensed

Getting started

For more information about MailerLite API, please visit the following link:

Authentication

API keys are a quick way to implement machine-to-machine authentication without any direct inputs from a human beyond initial setup.

For more information how to obtain an API key visit the following link

Table of Contents

Installation

Please run the following command:

python -m pip install mailerlite

Usage

MailerLite Client

The first thing that you need to do is to import mailerlite into your project and to instantiate the client by passing your API key:

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})

MailerLite API supports versioning, so you can pass additional argument to specify the API version:

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key',
'api_version': '2038-01-19'
})

Subscribers

List all subscribers

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.subscribers.list(limit=10, page=1, filter={'status': 'active'})

Create a subscriber

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.subscribers.create('some@email.com', fields={'name': 'John', 'last_name': 'Doe'}, ip_address='1.2.3.4', optin_ip='1.2.3.4')

Update a subscriber

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.subscribers.update('some@email.com', fields={'name': 'New', 'last_name': 'Name'}, ip_address='1.2.3.5', optin_ip='1.2.3.5')

Get a subscriber

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.subscribers.get('some@email.com')

Delete a subscriber

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
subscriber_id=1234567890response=client.subscribers.delete(subscriber_id)

Groups

List all groups

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.groups.list(limit=10, page=1, filter={'name': 'My'}, sort='name')

Create a group

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
group_name='My Group'response=client.groups.create(group_name)

Update a group

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
group_id=1234567group_name='My New Group'response=client.groups.update(group_id, group_name)

Delete a group

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
group_id=1234567response=client.groups.delete(group_id)

Get subscribers belonging to a group

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
group_id=1234567response=client.groups.get_group_subscribers(group_id, page=1, limit=10, filter={'status': 'active'})

Assign subscriber to a group

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
subscriber_id=111222group_id=1234567response=client.subscribers.assign_subscriber_to_group(subscriber_id, group_id)

Unassign subscriber from a group

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
subscriber_id=111222group_id=1234567response=client.subscribers.unassign_subscriber_from_group(subscriber_id, group_id)

Segments

List all segments

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.segments.list(limit=10, page=1)

Update a segment

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
segment_id=123456name="My New Segment Name"response=client.segments.update(segment_id, name)

Delete a segment

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
segment_id=123456response=client.segments.delete(segment_id)

Get subscribers belonging to a segment

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
segment_id=123456response=client.segments.get_subscribers(segment_id, limit=10, filter={'status': 'active'})

Fields

List all fields

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.fields.list(limit=10, page=1, sort='name', filter={'keyword': 'abc', 'type': 'text'})

Create a field

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
name='My Field'type= 'textresponse=client.fields.create(name, type)

Update a field

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
field_id=123456name='My New Field'response=client.fields.update(field_id, name)

Delete a field

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
field_id=123456response=client.fields.delete(field_id)

Automations

List all automations

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.automations.list(limit=10, page=1, filter={'status': true, 'name': 'some name', 'group': 123456})

Get an automation

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
automation_id=123456response=client.automations.get(automation_id)

Get subscribers activity for an automation

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
automation_id=123456response=client.automations.activity(automation_id, page=1, limit=10, filter={'status': 'active', 'date_from': '2022-12-20', 'date_to': '2022-12-31'})

Campaigns

List all campaigns

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.campaigns.list(limit=10, page=1, filter={'status': 'ready', 'type': 'regular'})

Get a campaign

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id=123456response=client.campaigns.get(campaign_id)

Create a campaign

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
params= {
"name": "Test Campaign",
"language_id": 1,
"type": "regular",
"emails": [{
"subject": "This is a test campaign",
"from_name": "Test Man",
"from": "testuser@mailerlite.com",
"content": "Hi there, this is a test campaign!"
}]
}
response=client.campaigns.create(params)

Update a campaign

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id=123456params= {
"name": "New Campaign Name",
"language_id": 2,
"emails": [{
"subject": "This is a test campaign",
"from_name": "Test Man",
"from": "testuser@mailerlite.com",
"content": "Hi there, this is a test campaign!"
}]
}
response=client.campaigns.update(campaign_id, params)

Schedule a campaign

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id=123456params= {
"delivery": "scheduled",
"schedule": {
"date": "2022-12-31",
"hours": "22",
"minutes": "00"
}
}
response=client.campaigns.schedule(campaign_id, params)

Cancel a campaign

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id=123456response=client.campaigns.cancel(campaign_id)

Delete a campaign

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id=123456response=client.campaigns.delete(campaign_id)

Get subscribers activity for a campaign

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
campaign_id=123456response=client.campaigns.activity(campaign_id)

Forms

List all forms

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.forms.list(limit=10, page=1, sort='name', filter={'name': 'form name'})

Get a form

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
form_id=123456response=client.forms.get(form_id)

Update a form

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
form_id=123456name='New Form Name'response=client.forms.update(form_id, name)

Delete a form

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
form_id=123456response=client.forms.delete(form_id)

Get subscribers who signed up to a specific form

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
form_id=123456response=client.forms.get_subscribers(form_id, page=1, limit=10, filter={'status': 'active'})

Batching

Create a new batch

Webhooks

List all webhooks

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.webhooks.list()

Get a webhook

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
webhook_id=123456response=client.webhooks.get(webhook_id)

Create a webhook

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
events= [
'subscriber.created',
'subscriber.updated',
'subscriber.unsubscribed'
]
url='https://my-url.com'name='Webhook name'response=client.webhooks.create(events, url, name)

Update a webhook

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
webhook_id=123456events= [
'subscriber.created',
'subscriber.updated',
'subscriber.unsubscribed'
]
url='https://my-url.com'name='Webhook name'enabled=Falseresponse=client.webhooks.update(webhook_id, events, url, name, enabled)

Delete a webhook

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
webhook_id=123456response=client.webhooks.delete(webhook_id)

Timezones

Get a list of timezones

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.timezone.list()

Campaign languages

Get a list of languages

importmailerliteasMailerLiteclient=MailerLite.Client({
'api_key': 'your-api-key'
})
response=client.campaigns.languages()

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages