Registry / communication / twilio

twilio

JSON →
sdk9.11.0pypypi✓ verified 27d ago

Official Python helper library for the Twilio REST API (SMS, voice, WhatsApp, email, video). v9.0 (2024) was a full OpenAPI-generated rewrite. v6.0 removed TwilioRestClient. All pre-v6 import patterns are broken. Actively maintained.

pip install twilio
INSTALL
IMPORT
SIG · TWILIO
T
twilio
communicationpythonv9.11.0
Install
7.2s avg
Import
375ms
Disk
76MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v9.11.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.382s · 72.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 7.2s · import 0.368s · 75MB
76MB installed
● package 76MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
from twilio.rest import Client client = Client('ACXXXXXXXXX', 'auth_token')
from twilio.rest import TwilioRestClient client = TwilioRestClient('ACXXXXXXXXX', 'auth_token')
TwilioRestClient was removed in v6.0.0. ImportError on all current versions. Use Client.
TwilioRestException
from twilio.base.exceptions import TwilioRestException
from twilio.rest import TwilioRestException
Exception class import path changed in v6. Old import path raises ImportError.
VoiceResponse (TwiML)
from twilio.twiml.voice_response import VoiceResponse resp = VoiceResponse() resp.say('Hello').emphasis('you')
resp.say('Hello').ssml_emphasis('you')
ssml_emphasis() was renamed to emphasis() in v9.0. Old method raises AttributeError.

Note from_= (with trailing underscore) — 'from' is a Python reserved word.

import os from twilio.rest import Client from twilio.base.exceptions import TwilioRestException client = Client( os.environ['TWILIO_ACCOUNT_SID'], os.environ['TWILIO_AUTH_TOKEN'] ) # Send SMS try: message = client.messages.create( to='+15558675309', from_='+15017250604', body='Hello from Python!' ) print(message.sid) except TwilioRestException as e: print(e) # Generate TwiML from twilio.twiml.voice_response import VoiceResponse resp = VoiceResponse() resp.say('Welcome to Twilio!') print(str(resp))
Debug
Known issues
breakingTwilioRestClient removed in v6.0.0. All pre-v6 tutorials and LLM-generated code using 'from twilio.rest import TwilioRestClient' fail with ImportError.
fix
from twilio.rest import Client (not TwilioRestClient). Client constructor is the same.
affects: < 6.0.0
breakingv9.0 (2024) was a full OpenAPI rewrite. ssml_emphasis() method on TwiML Say renamed to emphasis(). Code using say.ssml_emphasis() raises AttributeError.
fix
Replace .ssml_emphasis() with .emphasis() on TwiML Say objects.
affects: < 9.0.0
breakingv9.0: Chat API message.create() and similar methods now require body as a keyword argument, not positional. Positional args in these calls raise TypeError.
fix
Change client.chat.v2.services('IS...').channels('CH...').messages.create('body') to .messages.create(body='body')
affects: < 9.0.0
breakingtwilio.rest.api.v2010.account.available_phone_number renamed to available_phone_number_country in v9.0. Code importing the old module path fails.
fix
Update any direct module path imports to use available_phone_number_country.
affects: < 9.0.0
gotchaThe 'from' keyword is a Python reserved word. Twilio SMS create() uses from_= (with trailing underscore) as the parameter name. Passing from= causes SyntaxError.
fix
client.messages.create(to='+1...', from_='+1...', body='...')
affects: all
gotchaClient() with no arguments reads TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN from environment. If using API key auth instead, pass Client(api_key, api_secret, account_sid) — 3-argument form. Mixing up 2-arg and 3-arg forms causes authentication failures.
fix
Auth token: Client(account_sid, auth_token). API key: Client(api_key, api_secret, account_sid).
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'twilio'
The 'twilio' library is not installed in the active Python environment where your script is being executed.
fix
Run `pip install twilio` in your terminal to install the library.
AttributeError: module 'twilio.rest' has no attribute 'TwilioRestClient'
The `TwilioRestClient` class was removed in `twilio-python` version 6.0.0. The new client class is simply `Client`.
fix
Update your import statement to `from twilio.rest import Client` and instantiate it with `client = Client(account_sid, auth_token)`.
Error 20003: Authenticate
The Account SID or Auth Token provided in your client initialization are incorrect, missing, or do not match your Twilio account credentials, preventing authentication with the Twilio API.
fix
Double-check your `account_sid` and `auth_token` for correctness and ensure they are loaded securely, ideally from environment variables.
TypeError: create() missing 1 required positional argument: 'to'
The `client.messages.create()` method requires the `to`, `from_` (or `messaging_service_sid`), and `body` arguments, but one or more were omitted.
fix
Provide all required arguments to the `create()` method. Example: `client.messages.create(to='+1234567890', from_='+1123456789', body='Hello from Twilio!')`
Upgrade
Version history
9.11.0latest on PyPI · released Aug 11, 2026
Audit
Dependencies
requestsrequiredHTTP client used internally.
PyJWToptionalRequired for Access Token generation (Twilio Video, Chat, etc.).
Agent activity
39 hits · last 30 days
node
36
OpenAI (training)
1
Resources
twilio — pip install twilio · libregistry