Skip to main content

SparkPost Python API client

Project description

https://www.sparkpost.com/sites/default/files/attachments/SparkPost_Logo_2-Color_Gray-Orange_RGB.svg

Sign up for a SparkPost account and visit our Developer Hub for even more content.

SparkPost Python API client

Build Status Documentation Status Coverage Status Slack Community

The super-mega-official Python package for using the SparkPost API.

Installation

Install from PyPI using pip:

$ pip install sparkpost

Get a key

Go to API & SMTP in the SparkPost app and create an API key. We recommend using the SPARKPOST_API_KEY environment variable:

from sparkpost import SparkPost
sp = SparkPost() # uses environment variable

Alternatively, you can pass the API key to the SparkPost class:

from sparkpost import SparkPost
sp = SparkPost('YOUR API KEY')

Send a message

Here at SparkPost, our messages are known as transmissions. Let’s use the underlying transmissions API to send a friendly test message:

from sparkpost import SparkPost

sp = SparkPost()

response = sp.transmissions.send(
    recipients=['someone@somedomain.com'],
    html='<p>Hello world</p>',
    from_email='test@sparkpostbox.com',
    subject='Hello from python-sparkpost'
)

print(response)
# outputs {u'total_accepted_recipients': 1, u'id': u'47960765679942446', u'total_rejected_recipients': 0}

Django Integration

The SparkPost python library comes with an email backend for Django. Put the following configuration in settings.py file.

SPARKPOST_API_KEY = 'API_KEY'
EMAIL_BACKEND = 'sparkpost.django.email_backend.SparkPostEmailBackend'

Replace API_KEY with an actual API key that you’ve generated in Get a Key section. Check out the full documentation on the Django email backend.

Using with Google Cloud

There are a few simple modifications necessary to enable the use of the underlying requests library that python-sparkpost uses. First, add the requests and requests-toolbelt to your project’s requirements.txt:

requests
requests-toolbelt

Then create or update your appengine_config.py file to include the following:

import requests
import requests_toolbelt.adapters.appengine

requests_toolbelt.adapters.appengine.monkeypatch()

Then deploy your app and you should be able to send using python-sparkpost on Google Cloud.

Documentation

Contribute

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.

  2. Fork the repository on GitHub and make your changes in a branch on your fork

  3. Write a test which shows that the bug was fixed or that the feature works as expected.

  4. Send a pull request. Make sure to add yourself to AUTHORS.

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

sparkpost-1.3.4.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sparkpost-1.3.4-py2.py3-none-any.whl (30.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sparkpost-1.3.4.tar.gz.

File metadata

  • Download URL: sparkpost-1.3.4.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sparkpost-1.3.4.tar.gz
Algorithm Hash digest
SHA256 accae62dcb8f669ba0ea497ce716c1468dc650a1c5131943f2acfca186b79623
MD5 3bc35318f133f74731d03472034dd504
BLAKE2b-256 3320da72586b4b8d33430824e560a1cd7d78d37bad79a88fb689e50e4396d001

See more details on using hashes here.

File details

Details for the file sparkpost-1.3.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sparkpost-1.3.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 74ba052826af7f0e08cab2d2b007b43b613a1be2a6e18d9426b5eb92901d4e22
MD5 aa17f4a48017003e84dee7ac7e15460d
BLAKE2b-256 c14c23cfc74cc18d028b68233008b95c3e4b4ba08bf9be85dda17c0e92cd588a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page