Some features of this SDK are still in development. Consult with our online support team if you run into issues using this SDK in a production environment.

Send a message with the Sinch Python SDK

Note:

Before you can get started, you need to do the following:

Using the Conversation API, you can send messages to any channel you have configured. This tutorial shows you how to set up and send a message in a Python application.

Steps:
  1. Install the Sinch Python SDK.
  2. Set up your Python application
  3. Send your first message

Installing the SDK

The easiest way to install the SDK is using pip:

  1. Open a command prompt or terminal to the local repository folder.
  2. Execute the following command:
    Copy
    Copied
    pip install sinch

Set up your Python application

Now you can start setting up your application.

Note:

This tutorial uses basic authentication for testing purposes. We recommend OAuth 2.0 authentication in a production environment. Read more about authentication methods here.

Create your file

Create a new file named send-message.py and paste the provided "send-message.py" code found on this page into the file. This code sends a text message.
Note:
This sample code is configured for the US region. If your Conversation API app wasn't created in the US region, update sinch_client.configuration.conversation_region to eu.

Modify your application

The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values.

Initialize the client

Before initializing a client using this SDK, you'll need three pieces of information:

  • Your Project ID
  • An access key ID
  • An access key Secret
These values can be found on the Access Keys page of the Customer Dashboard. You can also create new access key IDs and Secrets, if required.
Note:
If you have trouble accessing the above link, ensure that you have gained access to the Conversation API by accepting the corresponding terms and conditions.

Fill in remaining parameters

Assign your values to the following parameters:

Placeholder valueYour value
YOUR_app_idFind your app ID on your Sinch dashboard.
YOUR_channelThe channel you want to use to send the message. This guide presets this channel property to SMS, but you may update it to any channel that's already configured on your Conversation API app. You may add the following channels to your app from the Sinch Customer Dashboard:
  • SMS
  • MESSENGER
  • MMS
  • RCS
  • WHATSAPP
  • VIBER
  • VIBERBM
  • INSTAGRAM
  • TELEGRAM
  • KAKAOTALK
  • APPLEBC
  • LINE
  • WECHAT
RECIPIENT_numberThe channel identity of the recipient to which you want to send the message. When using the SMS channel, this will be a phone number.
YOUR_sms_senderYour Sinch virtual phone number, available on the customer dashboard. This is only required if you are using the SMS channel.

Ensure that you save the file.

Send your first message

Now you can execute the code and send your test message. Open a command prompt or terminal to the location where your Python file is saved and run the following command:

Copy
Copied
python send-message.py

You should receive a message in your configured messaging platform.

Additional resources

Read the links below to learn more:

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.