Member-only story
“Sending a text message from Python using Twilio”
Twilio Messaging is an API to send and receive SMS, MMS, OTT messages globally. It uses intelligent sending features to ensure messages reliably reach end-users wherever they are.
Twilio has SMS-enabled phone numbers available in more than 180 countries.
To send text messages using python code
Step 1:- Create a folder named Pytext and add app.py file.
# install module Twilio
pipenv install Twilio# import client from Twilio rest API
from Twilio.rest import ClientStep 2:- Create a trial account on Twilio, get Project Info(eg:-account_sid,auth_token), and generate a phone number to snd text msg from Twilio.
account_sid = “…”
auth_token = “…”Step 3:- Create config.py file and store account_sid and auth_token in config.py. file.
Step 4:- Create .gitignore.py file.
# add
config.pyStep 5:- Open the app.py file and add these lines of code.
# to(whom to send msg)
# from (number generated from twilio)import config
client = Client(config.account_sid, config.auth_token)
message_info = client.messages.create(to=”….”, from_=”….”, body=”This is our first message”)print(message_info)
Step 6:- Execute app.py file in python terminal.
So, received a notification on your phone???? check the phone associated with the phone number mentioned in “to”.
Received message : “Sent from your Twilio trial account- This is our first message”.
Do clap! if find useful✌.