Get Started

Twilio SMS and MMS Python Quickstart

Sending SMS and MMS 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/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.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.

It's also easy to send an outgoing MMS using Twilio. To send an MMS, you also make an HTTP POST request to the Messages resource but this time specify one or more MediaUrl parameters.

MMS messages can only be sent and received by numbers having MMS capability. You can check the capabilities of numbers in the account portal or query the Available Phone Numbers resource to search for Twilio numbers that are MMS enabled.
message = client.messages.create(to="+12316851234", from_="+15555555555",
                                     body="Hello there!",
                                     media_url=['https://demo.twilio.com/owl.png', 'https://demo.twilio.com/logo.png'])

Note that the body argument is optional if you are sending one or more MediaUrls.


Next: Reply to Incoming SMS »