Courier (trycourier)
Python SDK for Courier notification API (multi-channel: email, SMS, push, in-app). Current version is 7.9.0. Install name is trycourier (pip install trycourier) but import name changed to courier in v5+ (from courier.client import Courier). The SDK was completely rewritten with Fern code generation in v5, breaking all v4 code.
Warnings
- breaking Install name (trycourier) and import name (courier) differ since v5. pip install trycourier then from courier.client import Courier. LLMs frequently generate from trycourier import Courier which raises ImportError on v5+.
- breaking Complete API rewrite in v5 using Fern code generation. v4 API (Courier(auth_token=), client.send(event=, recipient=, data=)) is completely gone. All v4 code raises ImportError or AttributeError on v5+.
- breaking auth_token= parameter renamed to authorization_token= in v5. Passing auth_token= raises TypeError.
- breaking Resource-scoped methods introduced in v5. Old flat methods like courier.deleteBrands() replaced with courier.brands.delete(). All flat method calls raise AttributeError.
- gotcha The COURIER_AUTH_TOKEN environment variable is read automatically if authorization_token= is not passed. Useful for 12-factor apps but can cause silent auth failures if the wrong env var is set.
Install
-
pip install trycourier
Imports
- Courier
# Current v5+ API (import from courier, not trycourier) from courier.client import Courier import courier client = Courier(authorization_token='YOUR_COURIER_AUTH_TOKEN') response = client.send( message=courier.ContentMessage( to=courier.UserRecipient(email='user@example.com'), content=courier.ElementalContent( version='2020-01-01', elements=[courier.ElementalNode_Text(content='Hello!')] ), routing=courier.Routing(method='all', channels=['email']) ) ) print(response.request_id)
Quickstart
# pip install trycourier
from courier.client import Courier
import courier
client = Courier(
authorization_token='YOUR_COURIER_AUTH_TOKEN'
# or set env var COURIER_AUTH_TOKEN
)
# Send using a template (workflow)
response = client.send(
message=courier.TemplateMessage(
template='your-template-id', # template ID from Courier dashboard
to=courier.UserRecipient(
email='user@example.com',
user_id='user-123'
),
data={
'name': 'Alice',
'action_url': 'https://yourapp.com'
}
)
)
print('Request ID:', response.request_id)
# Async client
from courier.client import AsyncCourier
import asyncio
async def send():
async with AsyncCourier(authorization_token='YOUR_TOKEN') as client:
await client.send(message=courier.TemplateMessage(
template='your-template-id',
to=courier.UserRecipient(email='user@example.com')
))
asyncio.run(send())