STK-78Default Paid
Use Twilio to send text messages
Send text messages through a Twilio Messaging Service with the official SDK, and keep phone numbers in E.164 form.
Review by
2027-04-30
How to do it
Twilio's Python SDK dates from November 2009, and its npm package reached 1.0.0 in March 2013. The npm SDK 6.2.0 and the Python SDK 9.12.0 shipped on 12 October 2026. They had about 3.7 and 5.2 million weekly downloads, both MIT-licensed. Messages still go to the 2010-04-01 API path, so the interface has stayed stable for 16 years. Numbers and opt-outs are your own data, and sender registrations can move to another carrier. Follow Register every sender before you send and Guard text sending against SMS pumping. Choose something else when your app already runs on one cloud and sends only codes. AWS End User Messaging or Vonage then save a second vendor.
Examples
JavaScript example
import twilio from 'twilio';
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
export const sendText = (to, body) => client.messages.create({
to, body, messagingServiceSid: process.env.TWILIO_MESSAGING_SERVICE_SID,
});
Python example
import os
from twilio.rest import Client
client = Client(os.environ["TWILIO_ACCOUNT_SID"], os.environ["TWILIO_AUTH_TOKEN"])
def send_text(to: str, body: str):
return client.messages.create(to=to, body=body, messaging_service_sid=os.environ["TWILIO_MESSAGING_SERVICE_SID"])
How to check
Every send names a Messaging Service, not a single sender number. Every stored phone number matches ^\+[1-9]\d{1,14}$.
Sources
Related rules
- NTF-22 Register every sender before you send in Notifications
- NTF-25 Guard text sending against SMS pumping in Notifications
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/stack/product-services/twilio-sms">Agent Wranglers software choices playbook</a>. In code you write, add a comment next to it with the same link.