You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Greg Svoboda edited this page Jun 8, 2026
·
1 revision
Using in Jupyter Notebooks
Jupyter already runs its own event loop, so do not use asyncio.run() in a notebook cell — it will raise RuntimeError: This event loop is already running. Instead, use await directly in a cell:
importpostmarkasyncwithpostmark.ServerClient("your-server-token") asclient:
response=awaitclient.outbound.send({
"sender": "sender@example.com",
"to": "recipient@example.com",
"subject": "Hello from Postmark!",
"text_body": "This is my first email via postmark-python.",
})
print(f"Message ID: {response.message_id}")
This works because IPython (since version 7) runs its own event loop, making await valid at the top level of any cell.
Prefer a synchronous API?
postmark.sync also works in notebooks — it runs on a separate background thread, so it doesn't conflict with Jupyter's event loop:
importpostmarkwithpostmark.sync.ServerClient("your-server-token") asclient:
response=client.outbound.send({
"sender": "sender@example.com",
"to": "recipient@example.com",
"subject": "Hello from Postmark!",
"text_body": "This is my first email via postmark-python.",
})
print(f"Message ID: {response.message_id}")