Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Twilio Best Practices

You're reading from   Twilio Best Practices Learn how to build powerful real-time voice and SMS applications with Twilio

Arrow left icon
Product type Paperback
Published in Dec 2014
Publisher
ISBN-13 9781782175896
Length 178 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (10) Chapters Close

Python


We can install the Twilio package for Python using pip, which is Python's standard package manager.

Note

If you don't have pip installed, follow the instructions at https://pip.pypa.io/en/latest/installing.html to install it.

To install the package, simply run the pip install twilio command.

In your code, you'll just need to import the library, and then you can instantiate the client (client.py) like this:

from twilio.rest import TwilioRestClient
import os
account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
auth_token = os.environ.get('TWILIO_AUTH_TOKEN')
client = TwilioRestClient(account_sid, auth_token)

Once you've set up your client, the syntax for sending an SMS is very similar to the one used in other examples, somewhere between the PHP and Ruby implementation, making use of keyword arguments (send_sms.py):

message = client.messages.create(to="+441290211999", from_="+441708300116", body="This is an SMS message.")

Here, our from_ parameter includes an underscore at the end because from...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime