ImportError: cannot import name 'TwilioRestClient' from 'twilio.rest'
Fixes old Twilio code importing TwilioRestClient on twilio 6+. Use when the import fails after upgrading. Not for twilio 5 installs.
TL;DR: TwilioRestClient died in twilio 6.0. Replace from twilio.rest import TwilioRestClient with from twilio.rest import Client, and TwilioRestClient(accountsid, authtoken) with Client(accountsid, authtoken).
ImportError: cannot import name 'TwilioRestClient' from 'twilio.rest'Fix it
- Change the import: from twilio.rest import Client. Expected: imports cleanly.
- Change instantiation: client = Client([account sid], [auth token]). Expected: same object shape as before.
- Update method calls if old: client.messages.create(...) works on both, but check the v6 changelog for renames you use. Expected: tests pass.
- Pin twilio>=6 in requirements (or >=7/8 for current) so installs stay consistent.
When this applies
- The code imports TwilioRestClient and twilio is 6+.
When it doesn't
- twilio is 5.x: TwilioRestClient exists; reinstall if the import fails.
- The import works but API calls 401: credential problem, not this.
Compatibility
- twilio >= 6.0. Current is 8.x/9.x.
Why it happens
v6 unified the client classes and removed the legacy name. Old quickstart code copied from pre-2017 docs still shows TwilioRestClient.
Edge cases
- TaskRouter and other sub-clients moved too; check imports for the full client surface you use.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.