The Twilio Python Helper Library

Deprecation notice: New functionality will only be added to the new library (Python Helper Library 6.x). The old library (5.x) will be officially supported until 7/3/2017. After that day, Twilio will stop providing bug fixes and Support might ask you to upgrade before debugging issues. Learn how to migrate your existing application..

The Twilio Python Helper Library makes it easy to interact with the Twilio API from your Python application. The most recent version of the library can be found on PyPi. The Twilio Python Helper Library supports Python applications written in Python 2.7 and above. If you are interested in migrating to the newer 6.x version of the Twilio Python Helper Library from the 5.x version, check out this guide.

Install the Library

The easiest way to install the library is from PyPi using pip, a package manager for Python. Simply run this in the terminal:

pip install twilio

If you get a pip: command not found error, you can also use easy_install. Run this in your terminal:

easy_install twilio

Manual Installation

Or, you can download the source code (ZIP) for twilio-python, and then install the library by running:

python setup.py install

in the folder containing the twilio-python library.

"Permission Denied"

If the command line gives you a big long error message that says Permission Denied in the middle of it, try running the above commands with sudo (e.g. sudo pip install twilio).

Test Your Installation

Try sending yourself an SMS message. Save the following code in a plain text editor on your computer. Be sure to update the account_sid, auth_token, and from_ phone number with values from your Twilio account. The to phone number can be your own mobile phone.

Loading Code Samples...
Language
from twilio.rest import Client

# Your Account SID from twilio.com/console
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# Your Auth Token from twilio.com/console
auth_token  = "your_auth_token"

client = Client(account_sid, auth_token)

message = client.messages.create(
    to="+15558675309", 
    from_="+15017250604",
    body="Hello from Python!")

print(message.sid)
Python Helper Library SMS Test

Save the file as send-sms.py. In the terminal, cd to the directory containing the file you just saved then run:

python send_sms.py

You should receive the text message on your phone.

More Documentation

Once you're up and running with the Python helper library, you'll find code samples using the latest version in our REST API docs and in the documentation for every Twilio product. You can also find auto-generated library docs for the latest SDK here.

Accessing Preview Twilio Features

Pre-release products are only available in the "alpha" release of the Python SDK (version 6.x or higher). Whenever a new version of the SDK is released, a corresponding "alpha" version will also be released and installable. For example, if the current production version of the SDK were "6.1.0", you could install the "alpha" version with the following command:

pip install twilio==6.1.0a1

Accessing the 5.x Version of the Helper Library

The most recent version of the Python Helper Library is not API compatible with the previous 5.x version you may have used in previous Twilio applications. The older version will continue to work, and you will continue to find sample code for this version throughout our documentation. Should you need to install this version you can do so with the following command:

pip install twilio==5.7.0

Getting Help

We'd love to hear your feedback on the Twilio Python Helper Library and help you past any issues you may encounter. Feel free to drop us a line, and we'll make sure to get you sorted!

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

1 / 1
Loading Code Samples...
from twilio.rest import Client

# Your Account SID from twilio.com/console
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# Your Auth Token from twilio.com/console
auth_token  = "your_auth_token"

client = Client(account_sid, auth_token)

message = client.messages.create(
    to="+15558675309", 
    from_="+15017250604",
    body="Hello from Python!")

print(message.sid)