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:

Learn how to quickly send SMS messages in a Python application with the Sinch SMS API.

Steps:
  1. Install the Python SDK
  2. Retrieve authentication information
  3. Set up your Python application
  4. Send your first SMS message

Install 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

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
These values can be found under the Access Keys tab of the legacy Sinch Customer Dashboard. You can also create new access key IDs and Secrets, if required.
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 named send-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

  1. Assign your values to the following parameters:
    ParameterYour value
    YOUR_key_idFind your access key on your Sinch dashboard.
    YOUR_key_secretFind your access secret on your Sinch dashboard. Note: Access secrets are only available during initial key creation.
    YOUR_project_idFind your project ID on your Sinch dashboard.
    YOUR_Sinch_numberAny 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_numberThe phone number to which you want to send the test SMS message.
  2. Save the file.

Send your first SMS message

Now you can execute the code and send your test SMS message. Run the following command:

Copy
Copied
python send-sms.py

Next steps

The code you used in the send-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

Was this page helpful?
Still have a question? Ask the community.

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)