Sign up for a SparkPost account and visit our Developer Hub for even more content.
SparkPost Python API client
The official Python package for using the SparkPost API.
Documentation
Documentation for python-sparkpost
Installation
Install from PyPI using pip:
$ pip install sparkpost
Python 2.7 or later is required.
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')
For SparkPost EU and Enterprise accounts, pass in a second parameter to set the API host.
from sparkpost import SparkPost
sp = SparkPost('YOUR API KEY', 'https://api.eu.sparkpost.com')
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(
use_sandbox=True,
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'
SPARKPOST_BASE_URI = 'api.sparkpost.com'
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.
If you are using an EU account, set SPARKPOST_BASE_URI to api.eu.sparkpost.com. The default value is api.sparkpost.com.
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.
Contribute
Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
Fork the repository on GitHub and make your changes in a branch on your fork
Write a test which shows that the bug was fixed or that the feature works as expected.
Send a pull request. Make sure to add yourself to AUTHORS.
Metadata
Release files for sparkpost 1.3.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sparkpost-1.3.10.tar.gz | 23.0 kB | Without provenance | Details for sparkpost-1.3.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sparkpost-1.3.10-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for sparkpost-1.3.10-py2.py3-none-any.whl |
Total release size: 54.4 kB
Release files / sparkpost-1.3.10.tar.gz
| Download URL | sparkpost-1.3.10.tar.gz |
|---|---|
| Size | 23.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a151261d514923e2d3055d122bba86c4d2c7c806419ae1c10ba689cacc3aa3a3
|
|
BLAKE2b-256 checksum How to use checksums |
216c0c268eec81553ba95c6b98815c5bd377392738204e5a7c20a3b2567d4c95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.20.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
|
Release files / sparkpost-1.3.10-py2.py3-none-any.whl
| Download URL | sparkpost-1.3.10-py2.py3-none-any.whl |
|---|---|
| Size | 31.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
fcb10063371f3c126a860ae780a3324d3b740e02dc343e0fc6bd1fecc89f6995
|
|
BLAKE2b-256 checksum How to use checksums |
26ea2fbd26f036eeb3e0bf9e0f93a31788f86c9db00533610207c833ab761d19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.20.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
|
Security for sparkpost 1.3.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.