Skip to main content

A Python library for the Postmark API (http://developer.postmarkapp.com/).

Project description

pystmark

PyPI version Build Status Coverage Status

Postmark API library for python 2.7, 3.6 and pypy. Built on top of the requests library.

Web Framework Integration

Documentation

The full Sphinx-compiled documentation is available here: https://readthedocs.org/docs/pystmark/en/latest/

Example Usage

from pystmark import (
    Message,
    send,
    send_with_template,
    send_batch,
    send_batch_with_templates,
    UnauthorizedError
)

API_KEY = 'my_api_key'
SENDER = 'me@example.com'

# Send a single message
message = Message(
    sender=SENDER,
    to='you@example.com',
    subject='Hi',
    text='A message',
    tag='greeting'
)

response = send(message, api_key=API_KEY)

# Send a template message
model = {
    'user_name': 'John Smith',
    'company': {
      'name': 'ACME'
    }

message = Message(
    sender=SENDER,
    to='you@example.com',
    template_id=11111,
    template_model=model,
    tag='welcome',
)

response = send_with_template(message, api_key=API_KEY)

# Send multiple messages
messages = [
    Message(
        sender=SENDER,
        to='you@example.com',
        subject='Hi',
        text='A message',
        tag='greeting',
        message_stream='broadcasts',
    )
]

response = send_batch(messages, api_key=API_KEY)

# Send multiple messages with templates
messages = [
    Message(
        sender=SENDER,
        to='you@example.com',
        template_id=11111,
        template_model=model,
        tag='greeting',
        message_stream='broadcasts',
    )
]

response = send_batch_with_templates(messages, api_key=API_KEY)

# Check API response error
try:
    response.raise_for_status()
except UnauthorizedError:
    print 'Use your real API key'

# Check for errors in each message when sending batch emails:
for m in response.messages:
    if m.error_code > 0:
        print m.message

Contribution

  1. Fork this repo
  2. Make your changes and write a test for them
  3. Add yourself to the AUTHORS.md file and submit a pull request

Please run the tests with ./setup.py test --with-integration, with at least python2.7, before you make a pull request. Requirements for running the tests are in tests/requirements.txt. The other versions will be handled by travis-ci.

The pep8 tests may fail if using pypy due to this bug, so that test is disabled if pypy is detected.

Copyright and License

pystmark is licensed under the MIT license. See the LICENSE file for full details.

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

pystmark-0.5.3.tar.gz (23.4 kB view details)

Uploaded Source

File details

Details for the file pystmark-0.5.3.tar.gz.

File metadata

  • Download URL: pystmark-0.5.3.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for pystmark-0.5.3.tar.gz
Algorithm Hash digest
SHA256 4d73827f0b00dc03fade324ab682fb4af7039c53e7f648a453eafec836d12018
MD5 fe42f426f8e4895b062d48c93d78a7b7
BLAKE2b-256 0c0b49a1d54577062c41a20744f5c656dc6b91c0452d887220487fd3583c6ec9

See more details on using hashes here.

Supported by

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