Get Started

SMS Python Quickstart Tutorial

Sending Text Messages via the REST API

It's really easy to send an outgoing SMS using Twilio. To send an SMS, make an HTTP POST request to the Messages resource.

POST https://api.twilio.com/2010-04-01/Accounts/AC123456abc/SMS/Messages

Our twilio-python helper library makes this extremely easy. Open a file called send_sms.py and add the following lines:

send_sms.py
# Download the twilio-python library from http://twilio.com/docs/libraries
from twilio.rest import TwilioRestClient

# Find these values at https://twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXX"
auth_token = "YYYYYYYYYYYYYYYYYY"
client = TwilioRestClient(account_sid, auth_token)

message = client.sms.messages.create(to="+12316851234", from_="+15555555555",
                                     body="Hello there!")

The from_ number must be a valid Twilio phone number. The to number can be any outgoing number.

If you are using a Twilio Trial account for this example, you will only be able to send SMS messages to phone numbers that you have verified with Twilio. Phone numbers can be verified via your Twilio Account's Phone Numbers Page.


Next: Reply to Incoming SMS »