Before you can get started, you need the following already set up:
Set all SMS 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.
Learn how to quickly send SMS messages in a Python application with the Sinch SMS API.
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
Now you can start setting up your application.
Create a new file named send-sms.py
and paste the provided "Send an SMS message" code into the file.
from sinch import SinchClient
sinch_client = SinchClient(
key_id="YOUR_key_id",
key_secret="YOUR_key_secret",
project_id="YOUR_project_id"
)
send_batch_response = sinch_client.sms.batches.send(
body="Hello from Sinch!",
to=["YOUR_to_number"],
from_="YOUR_Sinch_number",
delivery_report="none"
)
print(send_batch_response)
This code initalizes the Sinch Client and then sends a message using the batches
class.
The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values.
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 <b>Access Keys</b> page of the Sinch Build Dashboard. You can also create new access key IDs and Secrets, if required.
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.
Assign your values to the following parameters:
Parameter | Your value |
---|---|
YOUR_Sinch_number | Any number you've assigned to your Sinch account. Find the number on your Customer Dashboard by clicking the service plan ID link and scrolling to the bottom of the page. |
YOUR_to_number | The phone number to which you want to send the test SMS message. |
Ensure that you save the file.
Now you can execute the code and send your test SMS message. Run the following command:
python send-sms.py
The code you used in the send-sms.py
file uses the Sinch SDK batches
endpoint to send the SMS message.
- Visit our API specification to test more endpoints.