Published on

Send SMS Messages with Python and Twilio via their API


This post will guide you through the steps on how to send SMS messages with Python and Twilio. We will use API to get a random quote that we will include in the body of the sms.

Signup for a Trail Account:

Sign up for a trail account at Twilio then create a number, which I will refer to as the sender number, take note of your accountid and token.

Create the Config:

Create the config, that will keep the accountid, token, sender number and recipient number:
secrets = {
    'account': 'xxxxxxxx',
    'token': 'xxxxxxx',
    'sender': '+1234567890',
    'receiver': '+0987654321'

Create the Client:

We will get a random quote via's API which we will be using for the body of our text message, and then use twilio's API to send the text message:
from config import secrets
from import Client
import requests

twilio_acountid = secrets['account']
twilio_token = secrets['token']
twilio_receiver = secrets['receiver']
twilio_sender = secrets['sender']

quote_response = requests.get('').json()

client = Client(

message = client.messages.create(

Message Preview:

Then within a couple of seconds your message should look something more or less like this:

For more info, have a look at their docs:

Thank You

Thanks for reading, feel free to check out my website, and subscrube to my newsletter or follow me at @ruanbekker on Twitter.