Python库,用于Postmark API(http://developer.postmarkapp.com/)。
项目描述
pystmark
为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
贡献
- Fork此存储库
- 对它们进行更改并编写测试
- 将自己添加到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 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 4d73827f0b00dc03fade324ab682fb4af7039c53e7f648a453eafec836d12018 |
|
MD5 | fe42f426f8e4895b062d48c93d78a7b7 |
|
BLAKE2b-256 | 0c0b49a1d54577062c41a20744f5c656dc6b91c0452d887220487fd3583c6ec9 |