Skip to main content

mailjet is a django app to implement the mailjet REST API

Project description


Mailjet is a real-time Cloud Emailing platform and this is a python library to access the Mailjet Web API.

NOTE It should be noted that Mailjet has since wrote a separate mailjet library which uses a newer API and is incompatible with this package. I have not tried their library so I cannot say if it is better or worse, but it is at the very least newer:


  • Clone this repository:

git clone

  • cd into the cloned directory and execute:

python install.

The settings can be configured from a Django settings file through MAILJET_API_KEY and MAILJET_SECRET_KEY, or through environment variables with the same name.



Alternatively, you can just pass the API key and Secret key as parameters when initializing the mailjet API as follows:

import mailjet

mailjet_api = mailjet.Api(api_key='YOUR_API_KEY', secret_key='YOUR_SECRET_KEY')


  • To get your account and profile information:
import mailjet

mailjet_api = mailjet.Api(api_key='YOUR_API_KEY', secret_key='YOUR_SECRET_KEY')
account_info = mailjet_api.user.infos()

acount_info would now be assigned the following python dict:

    'status': 'OK',
    'infos': {
        'username': '',
        'firstname': 'firstname',
        'locale': 'en_US',
        'lastname': 'lastname',
        'company_name': 'company_name',
        'contact_phone': None,
  • Create a new list of contacts, following on from the previous example:
contact_list = mailjet_api.lists.create(
    name='testlist',  # Only alphanumeric characters are allowed!

contact_list will now contain a dictionary with the status and list id as below:

    'status': 'OK',
    'contact_id': 000000000
  • You can now add contacts to your list using the contact_id:


How do I give reserved python keywords as parameters?

Methods such as creating a campaign require you to use reserved python keywords, such as from - hence, in order to overcome this, do the following:

params = dict()
params['method'] ='POST'
params['subject'] = 'My first campaign'
params['list_id'] = contact_list['list_id']
params['lang'] = 'en'
params['from'] = ''
params['from_name'] = 'Your name'
params['footer'] = 'default'
campaign = api.message.createcampaign(**params)

How do I debug errors?

The errors produced by the mailjet library (or actually, produced by the urllib2 library) are still normal http responses. So if you wish to read the actual response, do something like this:

    contact_list = api.lists.create(
        name='Test list',  # Incorrect because of the space in the name
except Exception, e:
    print 'Mailjet response: %r, %r' % (e,

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

mailjet-1.4.0.tar.gz (9.5 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page