Send a message with the Sinch Python SDK
Note:
Before you can get started, you need to do the following:
- Set all Conversation API configuration settings.
- Python and a familiarity with how to create a new app.
- PIP (package installer for Python) and a familiarity with how to install Python modules.
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.
Installing the SDK
The easiest way to install the SDK is using pip
:
- Open a command prompt or terminal to the local repository folder.
- Execute the following command:
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 namedsend-message.py
and paste the provided "send-message.py" code found on this page into the file. This code sends a text message.Note:
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
Note:
Fill in remaining parameters
Assign your values to the following parameters:
Placeholder value | Your value |
---|---|
YOUR_app_id | Find your app ID on your Sinch dashboard. |
YOUR_channel | The 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:
|
RECIPIENT_number | The 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_sender | Your 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:
python send-message.py
You should receive a message in your configured messaging platform.
Additional resources
Read the links below to learn more: