Skip to main content

alt text

Official Mailjet Python Wrapper

Build Status

API documentation

All code examples can be found on the Mailjet Documentation.

(Please refer to the Mailjet Documentation Repository to contribute to the documentation examples)

Installation

(sudo) pip install mailjet_rest

Getting Started

Grab your API and Secret Keys here. You need them for authentication when using the Email API:

export MJ_APIKEY_PUBLIC='your api key'
export MJ_APIKEY_PRIVATE='your api secret'

API Versioning

The Mailjet API is spread among three distinct versions:

  • v3 - The Email API
  • v3.1 - Email Send API v3.1, which is the latest version of our Send API
  • v4 - SMS API

Since most Email API endpoints are located under v3, it is set as the default one and does not need to be specified when making your request. For the others you need to specify the version using version. For example, if using Send API v3.1:

# import the mailjet wrapper
from mailjet_rest import Client
import os

# Get your environment Mailjet keys
API_KEY = os.environ['MJ_APIKEY_PUBLIC']
API_SECRET = os.environ['MJ_APIKEY_PRIVATE']


# Initialize the client with API URL (default is 'https://api.eu.mailjet.com/')
mailjet = Client(auth=(API_KEY, API_SECRET), version='v3', api_url='https://api.eu.mailjet.com/')

For additional information refer to our API Reference.

Make a GET request:

# get all contacts
result = mailjet.contact.get()

GET request with filters:

# get the first 2 contacts
result = mailjet.contact.get(filters={'limit': 2})

POST request

# Register a new sender email address
result = mailjet.sender.create(data={'email': 'test@mailjet.com'})

Combine a resource with an action

# Get the contacts lists of contact #2
result = mailjet.contact_getcontactslists.get(id=2)

Send an Email

from mailjet_rest import Client
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret), version='v3.1')
data = {
  'Messages': [
                {
                        "From": {
                                "Email": "pilot@mailjet.com",
                                "Name": "Mailjet Pilot"
                        },
                        "To": [
                                {
                                        "Email": "passenger1@mailjet.com",
                                        "Name": "passenger 1"
                                }
                        ],
                        "Subject": "Your email flight plan!",
                        "TextPart": "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
                        "HTMLPart": "<h3>Dear passenger 1, welcome to Mailjet!</h3><br />May the delivery force be with you!"
                }
        ]
}
result = mailjet.send.create(data=data)
print result.status_code
print result.json()

You can also use the previous version of Mailjet's Send API (v3). You can find the documentation explaining the overall differences and code samples here.

Create a new Contact

# wrapping the call inside a function
def new_contact(email):
	return mailjet.contact.create(data={'Email': email})

new_contact('mr@smith.com')

Release files for mailjet-rest 1.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mailjet-rest 1.3.3
File Size Uploaded
mailjet_rest-1.3.3.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mailjet-rest 1.3.3
File Interpreter ABI Platform
mailjet_rest-1.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 11.8 kB

Release files / mailjet_rest-1.3.3.tar.gz

Download URL mailjet_rest-1.3.3.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f14424df10c30083491dcaa5902ff9b159af82bca261af5e7b2213afdcf7a11c
BLAKE2b-256 checksum
How to use checksums
6904a92885c635ca412c8f5bdf3d11da6f619bbd4bce45c4e28189eeef10bd6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

Release files / mailjet_rest-1.3.3-py3-none-any.whl

Download URL mailjet_rest-1.3.3-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f95a44d5cef2ce003776c4f847f885790da513ec0fe78c9c4ff6f6bf15325b71
BLAKE2b-256 checksum
How to use checksums
1e5c72d9c2a3a33802b1350ea6a00115f7f49f8b43f2bb8c547616ee0eae2633
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page