Skip to main content

Python Wrapper for Mailerlite API

Project description

Mailerlite-api-python

Python Wrapper for Mailerlite API v2

Deployment pypi mailerlite
Build Status
Metrics codacy mailerlite python codecov mailerlite python
License bsd
Community

Getting Started

Installation

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 .

Method reference

For complete reference, visit the official MailerLite API reference.

Examples

Initialization

First, Grab YOUR_API_KEY from your Mailerlite account (Profile > Integrations > Developer Api).

>>> from mailerlite import MailerLiteApi
>>> api = MailerLiteApi('YOUR_API_KEY')

Campaigns

Get all campaigns or a specific one

>>> all_campaigns = api.campaigns.all()
>>> draft = api.compaings.all(status='draft')

Modify a campaign

>>> 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)

Create / Delete a campaign

>>> data = {"subject": "Regular campaign subject",
                       "groups": [2984475, 3237221],
                       "type": "regular"}
>>> api.campaign.create(data)
>>> api.campaign.delete(campaign_id=3971635)

count campaign

>>> api.campaign.count()
>>> api.campaign.count(status='draft')

Subscribers

Get all subscribers

>>> api.subscribers.all()
>>> api.subscribers.all(stype='active')
>>> api.subscribers.active()

Get one subscriber

>>> api.subscribers.get(email='demo@mailerlite.com')
>>> api.subscribers.get(id=1343965485)

search

>>> api.subscribers.search(search='demo@mailerlite.com')

subscribers groups

>>> api.subscribers.groups(id=1343965485)

subscribers activity

>>> api.subscribers.activity(id='1343965485')

Create subscriber

>>> data = {'name': 'John',
            'email': 'demo-678@mailerlite.com',
            'fields': {'company': 'MailerLite'}
            }
>>> api.subscribers.create(data)

Update subscriber

>>> data = {'name': 'John',
            'fields': {'company': 'MailerLite'}
            }
>>> api.subscribers.update(data, id='1343965485')

Count subscribers

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()

Groups

Get all Groups

>>> api.groups.all()
>>> api.groups.all(limit=50)
>>> api.groups.all(offset=10)
>>> api.groups.all(gfilters='My Group')
>>> api.groups.all(group_id=12345)

Create a Group

>>> api.groups.create(group_id=12345, name='My New Group')

Rename a Group

>>> api.groups.update(group_id=12345, name='New Name')

Get a Group

>>> api.groups.get(group_id=12345)

Delete a Group

>>> api.groups.delete()
>>> api.groups.delete(group_id=12345)

Get all subscribers in a Group

>>> api.groups.subscribers(group_id=12345)
>>> api.groups.subscribers(group_id=12345, limit=50, offset=1)
>>> api.groups.subscribers(group_id=12345, stype='active')

Get one subscriber from a Group

>>> api.groups.subscriber(group_id=12345, subscriber_id=54321)

Delete one subscriber from a Group

>>> api.groups.delete_subscriber(group_id=12345, subscriber_id=54321)

Segments

Get list of Segments

>>> api.segments.all()

Get count of Segments

>>> api.segments.count()

Fields

Get list of Fields

>>> api.fields.all()

Get one Field

>>> api.fields.get(field_id=123456)

Create / update / delete one Field

>>> api.fields.create(title="my custom title")
>>> api.fields.update(field_id=123456, title="my new title 2")
>>> api.fields.delete(field_id=123456)

Webhooks

Get list of Webhooks

>>> api.webhooks.all()

Get one webhook

>>> api.webhooks.get(webhook_id=123456)

Create/update/delete one webhook

>>> 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)

Account

# 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

>>> batch_requests = {"requests": [{"method":"GET",
...                                 "path": "/api/v2/groups"
...                                 },
...                                 {"method":"POST",
...                                  "path": "/api/v2/groups",
...                                  "body": {"name": "New group"}
...                                 }
...                                 ]
...                    }
>>> api.batch(batch_requests)

Tests

  • Step 1: Install pytest
  pip install pytest
  • Step 2: Run the tests
  pytest -svv mailerlite

Contribute

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!

License

Project under 3-clause BSD license, more informations here

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

mailerlite-api-python-0.3.0.tar.gz (40.3 kB view details)

Uploaded Source

Built Distribution

mailerlite_api_python-0.3.0-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file mailerlite-api-python-0.3.0.tar.gz.

File metadata

  • Download URL: mailerlite-api-python-0.3.0.tar.gz
  • Upload date:
  • Size: 40.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.0

File hashes

Hashes for mailerlite-api-python-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4d530e02ff8262653cd0fe16d3a59197a567f407f8402e2246384335a7ef4a64
MD5 39ed2e591c2c123f4c80d41ccc14876e
BLAKE2b-256 ddd8333602e426a92f562027834d3d08fcffb0a640a94390d5cc3e3928e672f0

See more details on using hashes here.

Provenance

File details

Details for the file mailerlite_api_python-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: mailerlite_api_python-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.0

File hashes

Hashes for mailerlite_api_python-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7850686a163685f01b8555b6f17462f083fe1d0fb6884373127232a868203fd
MD5 32038db59d628d3a3b03629720845ec4
BLAKE2b-256 7c0f1e329d9ddfd02751bc57b707258689b4c187a6f621a8151779fb77f0f9e1

See more details on using hashes here.

Provenance

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