twilio 9.10.4


pip install twilio

  Latest version

Released: Mar 24, 2026

Project Links

Meta
Author: Twilio
Requires Python: >=3.7.0

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Operating System
  • OS Independent

Programming Language
  • Python
  • Python :: 3.7
  • Python :: 3.8
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: Implementation :: CPython

Topic
  • Software Development :: Libraries :: Python Modules
  • Communications :: Telephony

twilio-python

Tests PyPI PyPI Learn OSS Contribution in TwilioQuest

Documentation

The documentation for the Twilio API can be found here.

The Python library documentation can be found here.

Versions

twilio-python uses a modified version of Semantic Versioning for all changes. See this document for details.

Supported Python Versions

This library supports the following Python implementations:

  • Python 3.7
  • Python 3.8
  • Python 3.9
  • Python 3.10
  • Python 3.11
  • Python 3.12
  • Python 3.13

Installation

Install from PyPi using pip, a package manager for Python.

pip3 install twilio

If pip install fails on Windows, check the path length of the directory. If it is greater 260 characters then enable Long Paths or choose other shorter location.

Don't have pip installed? Try installing it, by running this from the command line:

curl https://bootstrap.pypa.io/get-pip.py | python

Or, you can download the source code (ZIP) for twilio-python, and then run:

python3 setup.py install

Info If the command line gives you an error message that says Permission Denied, try running the above commands with sudo (e.g., sudo pip3 install twilio).

Test your installation

Try sending yourself an SMS message. Save the following code sample to your computer with a text editor. Be sure to update the account_sid, auth_token, and from_ phone number with values from your Twilio account. The to phone number will be your own mobile phone.

from twilio.rest import Client

# Your Account SID and Auth Token from console.twilio.com
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"

client = Client(account_sid, auth_token)

message = client.messages.create(
    to="+15558675309",
    from_="+15017250604",
    body="Hello from Python!")

print(message.sid)

Save the file as send_sms.py. In the terminal, cd to the directory containing the file you just saved then run:

python3 send_sms.py

After a brief delay, you will receive the text message on your phone.

Warning It's okay to hardcode your credentials when testing locally, but you should use environment variables to keep them secret before committing any code or deploying to production. Check out How to Set Environment Variables for more information.

OAuth Feature for Twilio APIs

We are introducing Client Credentials Flow-based OAuth 2.0 authentication. This feature is currently in beta and its implementation is subject to change.

API examples here

Organisation API examples here

Use the helper library

API Credentials

The Twilio client needs your Twilio credentials. You can either pass these directly to the constructor (see the code below) or via environment variables.

Authenticating with Account SID and Auth Token:

from twilio.rest import Client

account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = Client(account_sid, auth_token)

Authenticating with API Key and API Secret:

from twilio.rest import Client

api_key = "XXXXXXXXXXXXXXXXX"
api_secret = "YYYYYYYYYYYYYYYYYY"
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
client = Client(api_key, api_secret, account_sid)

Alternatively, a Client constructor without these parameters will look for TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN variables inside the current environment.

We suggest storing your credentials as environment variables. Why? You'll never have to worry about committing your credentials and accidentally posting them somewhere public.

from twilio.rest import Client
client = Client()

Specify Region and/or Edge

To take advantage of Twilio's Global Infrastructure, specify the target Region and Edge for the client:

Note: When specifying a region parameter for a helper library client, be sure to also specify the edge parameter. For backward compatibility purposes, specifying a region without specifying an edge will result in requests being routed to US1.

from twilio.rest import Client

client = Client(region='au1', edge='sydney')

A Client constructor without these parameters will also look for TWILIO_REGION and TWILIO_EDGE variables inside the current environment.

Alternatively, you may specify the edge and/or region after constructing the Twilio client:

from twilio.rest import Client

client = Client()
client.region = 'au1'
client.edge = 'sydney'

This will result in the hostname transforming from api.twilio.com to api.sydney.au1.twilio.com.

Make a Call

from twilio.rest import Client

account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls.create(to="9991231234",
                           from_="9991231234",
                           url="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
print(call.sid)

Get data about an existing call

from twilio.rest import Client

account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls.get("CA42ed11f93dc08b952027ffbc406d0868")
print(call.to)

Iterate through records

The library automatically handles paging for you. Collections, such as calls and messages, have list and stream methods that page under the hood. With both list and stream, you can specify the number of records you want to receive (limit) and the maximum size you want each page fetch to be (page_size). The library will then handle the task for you.

list eagerly fetches all records and returns them as a list, whereas stream returns an iterator and lazily retrieves pages of records as you iterate over the collection. You can also page manually using the page method.

page_size as a parameter is used to tell how many records should we get in every page and limit parameter is used to limit the max number of records we want to fetch.

Use the list method

from twilio.rest import Client

account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

for sms in client.messages.list():
  print(sms.to)
client.messages.list(limit=20, page_size=20)

This will make 1 call that will fetch 20 records from backend service.

client.messages.list(limit=20, page_size=10)

This will make 2 calls that will fetch 10 records each from backend service.

client.messages.list(limit=20, page_size=100)

This will make 1 call which will fetch 100 records but user will get only 20 records.

Asynchronous API Requests

By default, the Twilio Client will make synchronous requests to the Twilio API. To allow for asynchronous, non-blocking requests, we've included an optional asynchronous HTTP client. When used with the Client and the accompanying *_async methods, requests made to the Twilio API will be performed asynchronously.

from twilio.http.async_http_client import AsyncTwilioHttpClient
from twilio.rest import Client

async def main():
    account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    auth_token  = "your_auth_token"
    http_client = AsyncTwilioHttpClient()
    client = Client(account_sid, auth_token, http_client=http_client)

    message = await client.messages.create_async(to="+12316851234", from_="+15555555555",
                                                 body="Hello there!")

asyncio.run(main())

Enable Debug Logging

Log the API request and response data to the console:

import logging

client = Client(account_sid, auth_token)
logging.basicConfig()
client.http_client.logger.setLevel(logging.INFO)

Log the API request and response data to a file:

import logging

client = Client(account_sid, auth_token)
logging.basicConfig(filename='./log.txt')
client.http_client.logger.setLevel(logging.INFO)

Handling Exceptions

Version 8.x of twilio-python exports an exception class to help you handle exceptions that are specific to Twilio methods. To use it, import TwilioRestException and catch exceptions as follows:

from twilio.rest import Client
from twilio.base.exceptions import TwilioRestException

account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = Client(account_sid, auth_token)

try:
  message = client.messages.create(to="+12316851234", from_="+15555555555",
                                   body="Hello there!")
except TwilioRestException as e:
  print(e)

Generating TwiML

To control phone calls, your application needs to output TwiML.

Use twilio.twiml.Response to easily create such responses.

from twilio.twiml.voice_response import VoiceResponse

r = VoiceResponse()
r.say("Welcome to twilio!")
print(str(r))
<?xml version="1.0" encoding="utf-8"?>
<Response><Say>Welcome to twilio!</Say></Response>

Other advanced examples

Docker Image

The Dockerfile present in this repository and its respective twilio/twilio-python Docker image are currently used by Twilio for testing purposes only.

Getting help

If you need help installing or using the library, please check the Twilio Support Help Center first, and file a support ticket if you don't find an answer to your question.

If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

9.10.4 Mar 24, 2026
9.10.3 Mar 10, 2026
9.10.2 Feb 18, 2026
9.10.1 Feb 05, 2026
9.10.0 Jan 22, 2026
9.9.1 Jan 07, 2026
9.9.0 Dec 17, 2025
9.8.8 Dec 03, 2025
9.8.7 Nov 20, 2025
9.8.6 Nov 11, 2025
9.8.5 Oct 28, 2025
9.8.4 Oct 14, 2025
9.8.3 Sep 30, 2025
9.8.2 Sep 25, 2025
9.8.1 Sep 18, 2025
9.8.0 Sep 04, 2025
9.7.2 Aug 28, 2025
9.7.1 Aug 18, 2025
9.7.0 Jul 24, 2025
9.6.5 Jul 10, 2025
9.6.4 Jul 03, 2025
9.6.3 Jun 12, 2025
9.6.2 May 29, 2025
9.6.1 May 13, 2025
9.6.0 May 05, 2025
9.5.2 Apr 07, 2025
9.5.1 Mar 20, 2025
9.5.0 Mar 11, 2025
9.4.6 Feb 20, 2025
9.4.5 Feb 11, 2025
9.4.4 Jan 28, 2025
9.4.3 Jan 13, 2025
9.4.2 Jan 09, 2025
9.4.1 Dec 13, 2024
9.4.0 Dec 12, 2024
9.3.8 Dec 05, 2024
9.3.7 Nov 15, 2024
9.3.6 Oct 25, 2024
9.3.5 Oct 24, 2024
9.3.4 Oct 17, 2024
9.3.3 Oct 03, 2024
9.3.2 Sep 25, 2024
9.3.1 Sep 18, 2024
9.3.0 Sep 05, 2024
9.2.4 Aug 26, 2024
9.2.3 Jul 02, 2024
9.2.2 Jun 27, 2024
9.2.1 Jun 21, 2024
9.2.0 Jun 18, 2024
9.1.1 Jun 06, 2024
9.1.0 May 24, 2024
9.0.5 Apr 18, 2024
9.0.4 Apr 04, 2024
9.0.3 Apr 01, 2024
9.0.2 Mar 15, 2024
9.0.1 Mar 12, 2024
9.0.0 Feb 27, 2024
9.0.0rc2 Feb 09, 2024
9.0.0rc1 Jan 08, 2024
8.13.0 Feb 09, 2024
8.12.0 Jan 25, 2024
8.11.1 Jan 14, 2024
8.11.0 Dec 14, 2023
8.10.3 Dec 01, 2023
8.10.2 Nov 17, 2023
8.10.1 Nov 06, 2023
8.10.0 Oct 19, 2023
8.9.1 Oct 05, 2023
8.9.0 Sep 21, 2023
8.8.0 Sep 07, 2023
8.7.0 Aug 24, 2023
8.5.0 Jul 13, 2023
8.4.0 Jun 28, 2023
8.3.0 Jun 15, 2023
8.2.2 Jun 01, 2023
8.2.1 May 18, 2023
8.2.0 May 04, 2023
8.1.0 Apr 20, 2023
8.0.0 Apr 05, 2023
8.0.0rc1 Mar 22, 2023
7.17.0 Mar 22, 2023
7.16.5 Mar 09, 2023
7.16.4 Feb 22, 2023
7.16.3 Feb 08, 2023
7.16.2 Jan 25, 2023
7.16.1 Jan 11, 2023
7.16.0 Dec 14, 2022
7.15.4 Nov 30, 2022
7.15.3 Nov 16, 2022
7.15.2 Nov 10, 2022
7.15.1 Oct 31, 2022
7.15.0 Oct 19, 2022
7.14.2 Oct 05, 2022
7.14.1 Sep 21, 2022
7.14.0 Sep 07, 2022
7.13.0 Aug 24, 2022
7.12.1 Aug 10, 2022
7.12.0 Jul 21, 2022
7.11.0 Jul 13, 2022
7.10.0 Jun 29, 2022
7.9.3 Jun 15, 2022
7.9.2 Jun 01, 2022
7.9.1 May 18, 2022
7.9.0 May 04, 2022
7.8.2 Apr 20, 2022
7.8.1 Apr 06, 2022
7.8.0 Mar 23, 2022
7.7.1 Mar 09, 2022
7.7.0 Feb 23, 2022
7.6.0 Feb 09, 2022
7.5.1 Jan 26, 2022
7.5.0 Jan 12, 2022
7.4.0 Dec 15, 2021
7.3.2 Dec 01, 2021
7.3.1 Nov 17, 2021
7.3.0 Nov 03, 2021
7.2.0 Oct 18, 2021
7.1.0 Oct 06, 2021
7.0.0 Sep 22, 2021
6.63.2 Sep 08, 2021
6.63.1 Aug 25, 2021
6.63.0 Aug 11, 2021
6.62.1 Jul 28, 2021
6.62.0 Jul 14, 2021
6.61.0 Jun 30, 2021
6.60.0 Jun 16, 2021
6.59.1 Jun 02, 2021
6.59.0 May 19, 2021
6.58.0 May 05, 2021
6.57.0 Apr 21, 2021
6.56.0 Apr 07, 2021
6.55.0 Mar 24, 2021
6.54.0 Mar 15, 2021
6.53.0 Feb 24, 2021
6.52.0 Feb 10, 2021
6.51.1 Jan 27, 2021
6.51.0 Jan 13, 2021
6.50.1 Dec 16, 2020
6.50.0 Dec 08, 2020
6.49.0 Dec 02, 2020
6.48.0 Nov 18, 2020
6.47.0 Nov 05, 2020
6.46.0 Oct 14, 2020
6.45.4 Sep 28, 2020
6.45.3 Sep 22, 2020
6.45.2 Sep 16, 2020
6.45.1 Sep 02, 2020
6.45.0 Aug 19, 2020
6.44.2 Aug 05, 2020
6.44.1 Jul 22, 2020
6.44.0 Jul 08, 2020
6.43.0 Jun 24, 2020
6.42.0 Jun 10, 2020
6.41.0 May 27, 2020
6.40.0 May 13, 2020
6.39.0 Apr 29, 2020
6.38.1 Apr 15, 2020
6.38.0 Apr 01, 2020
6.37.0 Mar 18, 2020
6.36.0 Mar 05, 2020
6.35.5 Feb 19, 2020
6.35.4 Feb 05, 2020
6.35.3 Jan 22, 2020
6.35.2 Jan 08, 2020
6.35.1 Dec 18, 2019
6.35.0 Dec 12, 2019
6.34.0 Dec 04, 2019
6.33.1 Nov 13, 2019
6.33.0 Oct 30, 2019
6.32.0 Oct 16, 2019
6.31.1 Oct 02, 2019
6.31.0 Sep 18, 2019
6.30.0 Sep 04, 2019
6.29.4 Aug 21, 2019
6.29.3 Aug 05, 2019
6.29.2 Jul 25, 2019
6.29.1 Jul 10, 2019
6.29.0 Jun 26, 2019
6.28.0 Jun 12, 2019
6.27.1 May 29, 2019
6.27.0 May 15, 2019
6.26.3 May 01, 2019
6.26.2 Apr 24, 2019
6.26.1 Apr 12, 2019
6.26.0 Mar 28, 2019
6.25.2 Mar 15, 2019
6.25.1 Mar 07, 2019
6.25.0 Mar 01, 2019
6.24.1 Feb 16, 2019
6.24.0 Feb 05, 2019
6.23.1 Jan 12, 2019
6.23.0 Jan 11, 2019
6.22.1 Jan 02, 2019
6.22.0 Dec 17, 2018
6.21.0 Nov 30, 2018
6.20.0 Nov 16, 2018
6.19.2 Oct 29, 2018
6.19.1 Oct 16, 2018
6.19.0 Oct 15, 2018
6.18.1 Oct 04, 2018
6.18.0 Sep 28, 2018
6.17.0 Sep 20, 2018
6.16.4 Aug 31, 2018
6.16.3 Aug 23, 2018
6.16.2 Aug 17, 2018
6.16.1 Aug 09, 2018
6.16.0 Aug 03, 2018
6.15.2 Jul 27, 2018
6.15.1 Jul 17, 2018
6.15.0 Jul 16, 2018
6.14.10 Jul 11, 2018
6.14.9 Jul 05, 2018
6.14.8 Jul 05, 2018
6.14.7 Jun 29, 2018
6.14.6 Jun 22, 2018
6.14.5 Jun 19, 2018
6.14.4 Jun 05, 2018
6.14.3 May 25, 2018
6.14.0 May 11, 2018
6.13.0 Apr 28, 2018
6.12.1 Apr 20, 2018
6.12.0 Apr 13, 2018
6.11.0 Mar 22, 2018
6.10.5 Mar 12, 2018
6.10.4 Feb 24, 2018
6.10.3 Feb 09, 2018
6.10.2 Jan 31, 2018
6.10.1 Jan 20, 2018
6.10.0 Dec 16, 2017
6.9.1 Dec 01, 2017
6.9.0 Nov 17, 2017
6.8.4 Nov 10, 2017
6.8.3 Nov 03, 2017
6.8.2 Oct 27, 2017
6.8.1 Oct 20, 2017
6.8.0 Oct 13, 2017
6.7.1 Oct 06, 2017
6.7.0 Sep 29, 2017
6.6.3 Sep 15, 2017
6.6.2 Sep 09, 2017
6.6.1 Sep 01, 2017
6.5.2 Aug 18, 2017
6.5.1 Aug 10, 2017
6.5.0 Jul 27, 2017
6.4.3 Jul 12, 2017
6.4.3a1 Jul 12, 2017
6.4.2 Jun 27, 2017
6.4.2a1 Jun 27, 2017
6.4.1 Jun 16, 2017
6.4.1a1 Jun 16, 2017
6.4.0 Jun 15, 2017
6.3.0 May 24, 2017
6.3.0a1 May 24, 2017
6.3.dev0 Jan 28, 2016
6.2.0 May 19, 2017
6.2.0a1 May 22, 2017
6.2.dev0 Dec 12, 2015
6.1.2 May 12, 2017
6.1.2a1 May 15, 2017
6.1.1 May 10, 2017
6.1.1a1 May 10, 2017
6.1.0 Apr 27, 2017
6.1.0a1 Apr 27, 2017
6.1.dev0 Dec 09, 2015
6.0.0 Apr 03, 2017
6.0.0rc13 Mar 08, 2017
6.0.0rc12 Sep 15, 2016
6.0.0rc11 Sep 01, 2016
6.0.0rc10 Aug 03, 2016
6.0rc9 Jul 11, 2016
6.0rc8 Jul 08, 2016
6.0rc7 Jun 10, 2016
6.0rc6 Jun 07, 2016
6.0rc5 May 27, 2016
6.0rc4 Mar 28, 2016
6.0rc3 Feb 12, 2016
6.0.0rc2 Jan 29, 2016
6.0.0a1 Apr 03, 2017
6.0.dev0 Dec 09, 2015
5.7.0 Jan 26, 2017
5.6.1 May 09, 2017
5.6.0 Sep 19, 2016
5.5.0 Sep 01, 2016
5.4.0 Feb 29, 2016
5.3.0 Jan 28, 2016
5.2.0 Dec 17, 2015
5.1.0 Dec 12, 2015
5.0.0 Dec 09, 2015
5.0.dev3 Dec 04, 2015
5.0.dev2 Nov 25, 2015
5.0.dev1 Nov 20, 2015
5.0.dev0 Nov 19, 2015
4.10.0 Dec 03, 2015
4.9.2 Nov 25, 2015
4.9.1 Nov 18, 2015
4.9.0 Nov 03, 2015
4.9.dev0 Nov 03, 2015
4.8.0 Nov 03, 2015
4.8.dev0 Nov 03, 2015
4.7.0 Oct 29, 2015
4.7.dev0 Oct 29, 2015
4.6.0 Sep 23, 2015
4.5.0 Aug 11, 2015
4.4.0 May 19, 2015
4.3.0 May 14, 2015
4.2.0 May 07, 2015
4.1.0 May 06, 2015
4.0.0 Apr 16, 2015
3.8.0 Mar 31, 2015
3.7.3 Mar 10, 2015
3.7.2 Feb 24, 2015
3.7.1 Feb 20, 2015
3.7.0 Feb 18, 2015
3.6.15 Jan 15, 2015
3.6.14 Dec 22, 2014
3.6.13 Dec 04, 2014
3.6.12 Nov 24, 2014
3.6.11 Nov 21, 2014
3.6.10 Nov 13, 2014
3.6.9 Oct 30, 2014
3.6.8 Oct 09, 2014
3.6.7 Aug 26, 2014
3.6.6 Feb 27, 2014
3.6.5 Feb 04, 2014
3.6.4 Nov 05, 2013
3.6.3 Oct 21, 2013
3.6.2 Sep 24, 2013
3.6.1 Sep 18, 2013
3.6.0 Sep 18, 2013
3.5.4 Sep 07, 2013
3.5.4rc1
3.5.3 Sep 07, 2013
3.5.2 Aug 30, 2013
3.5.1 May 22, 2013
3.5.0 May 21, 2013
3.4.5 Apr 02, 2013
3.4.4 Mar 18, 2013
3.4.3 Jan 28, 2013
3.4.2 Jan 03, 2013
3.4.1 Oct 17, 2012
3.4.0 Oct 17, 2012
3.3.11 Sep 05, 2012
3.3.10 Aug 09, 2012
3.3.9 Jul 03, 2012
3.3.7 Jun 15, 2012
3.3.6 Mar 03, 2012
3.3.5 Jan 19, 2012
3.3.3 Nov 03, 2011
3.3.2 Sep 29, 2011
3.3.1 Sep 27, 2011
3.3.0 Sep 21, 2011
3.2.3 Aug 08, 2011
3.2.2 Jul 29, 2011
3.2.1 Jul 29, 2011
3.2.0 Jul 26, 2011
3.1.0 Jul 26, 2011
3.0.2 Jul 25, 2011
3.0.1 Jul 18, 2011
3.0.0 Jul 16, 2011
2.0.10 Apr 11, 2011
2.0.9 Apr 09, 2011
2.0.6 Mar 11, 2010
2.0.1 Nov 26, 2009

Wheel compatibility matrix

Platform Python 2 Python 3
any

Files in release

Extras: None
Dependencies:
requests (>=2.0.0)
PyJWT (<3.0.0,>=2.0.0)
aiohttp (>=3.8.4)
aiohttp-retry (>=2.8.3)