Python Quickstart: Sending SMS and MMS Messages

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


Our twilio-python helper library makes this extremely easy. Open a file called and add the following lines:
# Download the twilio-python library from
from import TwilioRestClient

# Find these values at
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=['', ''])

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

Next: Reply to Incoming SMS »