跳转到主要内容

Python库,用于Postmark API(http://developer.postmarkapp.com/)。

项目描述

pystmark

PyPI version Build Status Coverage Status

为python 2.7, 3.6 和 pypy 编写的Postmark API 库。基于requests 库构建。

Web框架集成

文档

完整的Sphinx编译文档可在此处找到:https://readthedocs.org/docs/pystmark/en/latest/

示例用法

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

贡献

  1. Fork此存储库
  2. 对它们进行更改并编写测试
  3. 将自己添加到AUTHORS.md 文件中并提交拉取请求

在您提交 pull request 之前,请使用 ./setup.py test --with-integration 运行测试,至少需要 python2.7。运行测试的要求在 tests/requirements.txt 文件中。其他版本将由 travis-ci 处理。

如果使用 pypy,则 pep8 测试可能会失败,因为存在 此错误,所以如果检测到 pypy,则禁用此测试。

版权和许可

pystmark 采用 MIT 许可证。有关详细信息,请参阅 LICENSE 文件。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

pystmark-0.5.3.tar.gz (23.4 kB 查看散列)

上传时间 源代码

支持者