Twilio Stubs

raw JSON →
0.2.0 verified Mon Apr 27 auth: no python

twilio-stubs is an unofficial package providing type declarations (PEP 561 stub files) for the Twilio API. Version 0.2.0 is current. The project is actively maintained, with infrequent releases.

pip install twilio-stubs
error Module 'twilio' has no attribute 'rest'
cause Missing twilio runtime dependency installed but stubs are missing types for other modules.
fix
Ensure you have twilio-stubs installed alongside twilio. Note that twilio-stubs only covers twilio.rest.
error Cannot find reference 'Client' in 'twilio.rest'
cause Type checker may not resolve stub files if package is not in site-packages or mypy cache is stale.
fix
Run 'pip install --upgrade twilio-stubs' and clear mypy cache: 'mypy --cache-dir /dev/null .'
error Unused type: ignore comment
cause Using '# type: ignore' in code that twilio-stubs now covers.
fix
Remove the '# type: ignore' comment and update mypy configuration if needed.
gotcha twilio-stubs provides types only for the REST API (twilio.rest). Other Twilio modules (e.g., TwiML, TaskRouter) may lack stubs.
fix Use inline type comments or 'Any' for uncovered parts, or contribute stubs upstream.
deprecated Types are based on the twilio Python helper library (version 6.x/7.x). If you use an older or newer major version, type mismatches may occur.
fix Pin twilio to a version compatible with the stubs (check twilio-stubs PyPI classifiers).
gotcha Twilio-stubs is a third-party package, not maintained by Twilio. Updates may lag behind the official library releases.
fix Watch for upstream twilio-stubs releases; consider contributing or using 'type: ignore' in checks.

Basic usage: type-checked Twilio client with twilio-stubs.

from twilio.rest import Client

account_sid = os.environ.get('TWILIO_ACCOUNT_SID', '')
auth_token = os.environ.get('TWILIO_AUTH_TOKEN', '')
client = Client(account_sid, auth_token)
message = client.messages.create(body='Hello from mypy!', from_='+15017122661', to='+15558675310')
print(f'Message sent: {message.sid}')