Skip to content

Repository files navigation

Courier Python SDK

The Courier Python SDK provides typed access to the Courier REST API from any Python 3.9+ application. It includes synchronous and asynchronous clients, Pydantic response models, TypedDict request params, and automatic retries.

Installation

pip install trycourier

Also available via poetry add trycourier and pipenv install trycourier.

Quick Start

fromcourierimportCourierclient=Courier()
response=client.send.message(
message={
"to": {"email": "you@example.com"},
"content": {
"title": "Hello from Courier!",
"body": "Your first notification, sent with the Python SDK.",
},
},
)
print(response.request_id)

The client reads COURIER_API_KEY from your environment automatically. You can also pass it explicitly: Courier(api_key='your-key').

Async usage

Import AsyncCourier instead of Courier and use await:

importasynciofromcourierimportAsyncCourierclient=AsyncCourier()
asyncdefmain():
response=awaitclient.send.message(
message={
"to": {"email": "you@example.com"},
"content": {
"title": "Hello from Courier!",
"body": "Sent from the async Python client.",
},
},
)
print(response.request_id)
asyncio.run(main())

Common Operations

# Check message delivery statusmessage=client.messages.retrieve("message-id")
print(message.status)
# Create or update a user profileclient.profiles.create("user_123", profile={
"email": "jane@example.com",
"name": "Jane Doe",
})
# Issue a JWT for client-side SDK authresult=client.auth.issue_token(
scope="user_id:user_123 inbox:read:messages inbox:write:events",
expires_in="2 days",
)

Documentation

Full documentation: courier.com/docs/sdk-libraries/python

About

A Python Package for communicating with the Courier REST API.

Resources

Contributing

Security policy

Stars

30 stars

Watchers

16 watching

Forks

Releases

Packages

Used by

Contributors

Languages