Skip to main content

trycourier

This Python Package helps you send notifications through Courier, the smartest way to design & deliver notifications. Design your notifications once using our drag & drop editor, then deliver to any channel through one API. Email, mobile push, SMS, Slack — you name it!

Installation

Install from PyPI using pip:

$ pip install trycourier

Python 3.5 or later is required.

Usage

Using Token Auth

from trycourier import Courier

client = Courier(auth_token="your-auth-token") #or set via COURIER_AUTH_TOKEN env var

resp = client.send(
    event="your-event-id",
    recipient="your-recipient-id",
    profile={
        "email": "example@example.com",
        "phone_number": "555-867-5309"
    },
    data={
      "world": "Python!"
    }
)
print(resp['messageId'])

Using Basic Auth

from trycourier import Courier

client = Courier(username="your-username", password="your-password")

resp = client.send(
    event="your-event-id",
    recipient="your-recipient-id",
    profile={
        "email": "example@example.com",
        "phone_number": "555-867-5309"
    },
    data={
      "world": "Python!"
    }
)
print(resp['messageId'])

Timeouts

As of v1.4.0, the timeout is defaulted to 5 seconds. This is configurable using the timeout parameter when creating a client. You can specify the time in seconds using a float value for both Connect and Read or use a tuple to set them for each individual one (Connect, Read).

client = Courier(auth_token="your-auth-token",
                 timeout=3.5)

client = Courier(auth_token="your-auth-token",
                 timeout=(3.2, 3.3))

Advanced Usage

from trycourier import Courier

client = Courier(auth_token="your-auth-token")

"""
Example: send a message
"""
resp = client.send(
    event="your-event-id",
    recipient="your-recipient-id",
    profile={}, # optional
    brand="your-brand-id", # optional
    data={}, # optional
    preferences={}, # optional
    override={} # optional
)
print(resp['messageId'])

"""
Example: replace or create a recipient's profile
"""
resp = client.replace_profile(
  recipient_id,
  {
    "email": "example@example.com"
  }
)
print(resp['status'])

"""
Example: merge or create a recipient's profile
"""
resp = client.merge_profile(
  recipient_id,
  {
    "phone_number": "+15555555555"
  }
)
print(resp['status'])

"""
Example: get a recipient's profile
"""
resp = client.get_profile(recipient_id)
print(resp)

"""
Example: fetch the statuses of messages you've previously sent.
"""
resp = client.get_messages(
  cursor="MTU4OTQ5NTI1ODY4NywxLTVlYmRjNWRhLTEwODZlYWFjMWRmMjEwMTNjM2I0ZjVhMA", # optional
  recipient=recipient_id, # optional
)
print(resp)

"""
Example: fetch the status of a message you've previously sent
"""
resp = client.get_message(message_id)
print(resp)

"""
Example: fetch the list of events
"""
resp = client.get_events()
print(resp)

"""
Example: fetch a specific event by event ID
"""
resp = client.get_event(event_id)
print(resp)

"""
Example: create or replace an event
"""
resp = client.replace_event(
  event_id,
  notification_id="GRPVB5P0BHMEZSNY6TP2X7TQHEBF",
  type="notificaton" ## optional, defaults to notification
)
print(resp)

"""
Example: get all brands
"""
resp = client.get_brands(
  cursor="MTU4OTQ5NTI1ODY4NywxLTVlYmRjNWRhLTEwODZlYWFjMWRmMjEwMTNjM2I0ZjVhMA", # optional
)
print(resp)

"""
Example: get a specific brand
"""
resp = client.get_brand(brand_id)
print(resp)

"""
Example: create a brand
"""
resp = client.create_brand({
  name="My Brand",
  settings={
    "color": {
      "primary": "#0000FF",
      "secondary": "#FF0000",
      "tertiary": "#00FF00"
    }
  }
})
print resp

"""
Example: replace a brand
"""
resp = client.replace_brand(
  brand_id,
  name="My New Brand",
  settings={
    "color": {
      "primary": "#FF0000",
      "secondary": "#00FF00",
      "tertiary": "#0000FF"
    }
  }
)
print resp

"""
Example: delete a brand
"""
client.delete_brand(brand_id)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/trycourier/courier-python. See CONTRIBUTING.md for more info.

License

The package is available as open source under the terms of the MIT License.

Metadata

Release files for trycourier 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trycourier 1.4.0
File Size Uploaded
trycourier-1.4.0.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trycourier 1.4.0
File Interpreter ABI Platform
trycourier-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.0 kB

Release files / trycourier-1.4.0.tar.gz

Download URL trycourier-1.4.0.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a1e4d00ab25ccb07b004a8d0dd38aad673f102d1f6f230af55c328abf538c28f
BLAKE2b-256 checksum
How to use checksums
2f4468dfb2f74ddb03a786ad80ff4abbf0cdbfb8760d9459fe768e56f4161b11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / trycourier-1.4.0-py3-none-any.whl

Download URL trycourier-1.4.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e27f855f4f9964d8060fcb8f10e12d8a59808c2057acd62f4ce3ce8029bb426
BLAKE2b-256 checksum
How to use checksums
884467ab87d3d703d15d7c55cfbd8f30922e7b660aaa8bf8c394a4906bf305bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release history Release notifications | RSS feed

9.11.0

2 release files

9.10.0

2 release files

9.9.0

2 release files

9.8.0

2 release files

9.7.0

2 release files

9.6.0

2 release files

9.5.0

2 release files

9.4.4

2 release files

9.4.3

2 release files

9.4.2

2 release files

9.4.1

2 release files

9.4.0

2 release files

9.3.0

2 release files

9.2.0

2 release files

9.1.0

2 release files

9.0.0

2 release files

8.0.0

2 release files

7.26.2

2 release files

7.26.1

2 release files

7.26.0

2 release files

7.25.0

2 release files

7.23.0

2 release files

7.22.0

2 release files

7.21.0

2 release files

7.20.0

2 release files

7.19.2

2 release files

7.17.1

2 release files

7.17.0

2 release files

7.16.0

2 release files

7.15.0

2 release files

7.14.0

2 release files

7.13.0

2 release files

7.12.0

2 release files

7.11.2

2 release files

7.11.1

2 release files

7.9.0

2 release files

7.8.0

2 release files

7.7.1

2 release files

7.7.0

2 release files

7.6.1

2 release files

7.6.0

2 release files

7.5.0

2 release files

7.4.0

2 release files

7.3.0

2 release files

7.2.0

2 release files

7.1.1

2 release files

7.1.0

2 release files

7.0.1

2 release files

7.0.0

2 release files

6.2.1

2 release files

6.2.0

2 release files

6.1.0

2 release files

6.0.5

2 release files

6.0.4

2 release files

6.0.3

2 release files

6.0.2

2 release files

6.0.1

2 release files

6.0.0

2 release files

5.0.0

2 release files

4.7.0

2 release files

4.6.0

2 release files

4.5.0

2 release files

4.4.0

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.9.0

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

This release

1.4.0 This release

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page