Python Quickstart
This quickstart demonstrates how to send messages from a Python application.
Python 3.7 or later is required.
- Make sure you have the latest version of Python installed.
- Sign up for Courier to get access to your API key.
- Add the channel(s) you wish to send your message to.
- Run
pip install trycourier
orpoetry add trycourier
to install the Courier Python SDK. - Use the
Courier
class to access all of our endpoints. - Add the following code and replace
<YOUR_TOKEN>
with your Courier API key:
import os
import courier
from courier.client import Courier
client = Courier(
authorization_token="YOUR_TOKEN" # Defaults to COURIER_AUTH_TOKEN
)
response = client.send(
message=courier.ContentMessage(
to=courier.UserRecipient(
email="marty_mcfly@email.com",
data={
name: "Marty",
}
),
content=courier.ElementalContentSugar(
title="Back to the Future",
body="Oh my {{name}}, we need 1.21 Gigawatts!",
),
routing=courier.Routing(
method=courier.RoutingMethod.ALL,
channels=["email"]
)
)
)
print(response)
Explore how to customize your notification with more properties >
- Run your code. Upon running this API call, only a requestId will be returned.
{ "requestId": "87e7c05b-4f46-fda24e356e23" }
- Monitor the status of your notification (once sent) in the logs: https://app.courier.com/logs
FAQs
-
How to add a channel?
How to: Integrate a New Notification Channel - SMS, Email, Chat, or Push
-
What's the difference between production and test API keys?
Every Courier tenant has two notification development environments: “Live” and “Test”. The two environments are isolated from one another, and all the assets within them (templates, brands, tags, subscription topics, integrations, API keys, log data, etc.) belong only to that environment.
Any changes made to a template and its associated assets are only applied within the current environment until you migrate the template and overwrite any changes to the corresponding Notification ID and assets in the other environment.
-
How can I send to multiple users or contacts?
You will need to create a list of users in Courier and
- Create a list and add users in the UI (recommended): https://app.courier.com/users?create-list=true
- Create a list and add users programmatically with the API: https://www.courier.com/docs/reference/lists/put-subscribe/
-
How can I access user profiles from Courier?
If you have your users saved in Courier's user database https://app.courier.com/users, you can replace the JSON
"email"
field in the"to"
object with:- individual profiles with
"user_id": "ADD_USER_ID"
- list of multiple users:
"list_id": "ADD_LIST_ID"
- individual profiles with
Questions?
Join our developer community on Discord and ask questions in the #ask-support channel.