This SDK is currently available for preview purposes only. It should not be used in production environments.
Send an SMS Message with Python SDK
Note:
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.
Learn how to quickly send SMS messages in a Python application with the Sinch SMS API.
Steps:
Install the SDK
The easiest way to install the SDK is usingpip
:- Open a command prompt or terminal to the local repository folder.
- Execute the following command:
pip install sinch
Retrieve authentication information
In order to initialize a client using this SDK, you'll need three pieces of information:
- Your Project ID
- An access key ID
- An access key Secret
Note:
If you have trouble accessing the above link, ensure you are using the legacy version of the Sinch Customer Dashboard. If you still have trouble, ensure that you have gained access to the Conversation API by accepting the corresponding terms and conditions.
Set up your Python application
Now you can start setting up your application.
Create your file
Create a new file namedsend-sms.py
and paste the provided "Send an SMS message" code into the file.Send an SMS message
from sinch import Client
sinch_client = Client(
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)
Fill in your parameters
- Assign your values to the following parameters:
Parameter Your value YOUR_key_id
Find your access key on your Sinch dashboard. YOUR_key_secret
Find your access secret on your Sinch dashboard. Note: Access secrets are only available during initial key creation. YOUR_project_id
Find your project ID on your Sinch dashboard. 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. - Save the file.
Send your first SMS message
Now you can execute the code and send your test SMS message. Run the following command:
python send-sms.py
Next steps
The code you used in thesend-sms.py
file uses the Sinch SDK batches
endpoint to send the SMS message. Click here to read more about the batches
endpoint.Additional resources
- Visit our API specification to test more endpoints.