The `sparkpost` library is the official Python API client for SparkPost, an enterprise email sending and analytics platform. It provides a straightforward interface to interact with SparkPost's REST API, covering functionalities like sending transmissions, managing templates, and accessing suppression lists. It is actively maintained, with regular updates focused on bug fixes, security enhancements, and new API features. The current version is 1.3.10.
pip install sparkpostVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the SparkPost client and send a simple HTML email. Ensure your `SPARKPOST_API_KEY`, `SPARKPOST_FROM_EMAIL`, and `SPARKPOST_TEST_EMAIL` environment variables are set. The example includes basic error handling for `SparkPostAPIException`.
Consult the latest SparkPost API documentation or client examples for the recommended way to query transmission lists, typically involving query parameters within a structured call rather than direct URI parameters.
Always wrap API calls in a `try...except SparkPostAPIException as e:` block. Upgrade to version 1.3.3 or newer to ensure more reliable exception reporting from the API.
Ensure you are on version 1.3.1 or later to benefit from fixes related to emoji handling (issue #114), but note a partial revert in 1.3.2 (issue #129) that was later investigated. For robust handling, always ensure your content is UTF-8 encoded and update to the latest patch version.
Verify that the `SPARKPOST_API_KEY` environment variable or the key passed to `SparkPost()` constructor is correct and active. Ensure it has the 'Send via SMTP' and 'Transmissions: Read/Write' permissions (or similar, depending on the operation).
Ensure the `recipients` list contains dictionaries, each with at least an 'address' key and a valid email string. Example: `recipients=[{'address': 'test@example.com'}]`.First, ensure the library is installed with `pip install sparkpost`. If the problem persists, check your project directory and Python path for any files or directories named `sparkpost.py` or `sparkpost` that might be causing a conflict.