pystmark
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'
message = Message(
sender=SENDER,
to='you@example.com',
subject='Hi',
text='A message',
tag='greeting'
)
response = send(message, api_key=API_KEY)
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)
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)
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)
try:
response.raise_for_status()
except UnauthorizedError:
print 'Use your real API key'
for m in response.messages:
if m.error_code > 0:
print m.message
Contribution
- Fork this repo
- Make your changes and write a test for them
- 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.