Retrieve Call Logs with Python

In this guide we’ll cover how to retrieve information about in progress and completed calls from your Twilio account.

We’ll use Twilio's Python module in these examples to interact with the Twilio REST APIs Calls endpoint.


First, we'll need to get our Twilio account credentials.

Retrieve your Twilio account credentials

First, you'll need to get your Twilio account credentials. They consist of your AccountSid and your Auth Token. They can be found on the home page of the console.

Retrieve Your Twilio Credentials

With our account credentials, we can then use the Twilio Python module to retrieve our call logs.

Retrieving call logs

You can use Twilio’s REST API to retrieve logs about the phone calls to and from your Twilio account. If you just want to check a couple logs, however, you should try looking at the voice logs in your Twilio console first.

To list all phone calls for your Twilio account, just call "client.calls.list()".
Loading Code Samples...
Language
SDK Version:
  • 5.x
  • 6.x
Format:
  • JSON
  • XML
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

# A list of call objects with the properties described above
calls = client.calls.list()
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

# A list of call objects with the properties described above
for call in client.calls.list():
    print(call.direction)
{
    "page": 0,
    "page_size": 50,
    "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?PageSize=1",
    "first_page_uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?PageSize=50&Page=0",
    "previous_page_uri": null,
    "next_page_uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?PageSize=50&Page=1&AfterSid=CA8d67bfc16f4b472a5b7c7bbf3c7977ae",
    "calls": [{
        "sid": "CA4c22bfc16f4b484d8b7cbe0f3c79bcc7",
        "date_created": "Tue, 12 Jun 2012 03:25:49 +0000",
        "date_updated": "Tue, 12 Jun 2012 03:27:05 +0000",
        "parent_call_sid": null,
        "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        "to": "+18085553279",
        "to_formatted": "(808) 555-3279",
        "from": "+17075559463",
        "from_formatted": "(707) 555-9463",
        "phone_number_sid": "PN907a2531e2d34c94b24b2794e73681de",
        "status": "completed",
        "start_time": "Tue, 12 Jun 2012 03:26:15 +0000",
        "end_time": "Tue, 12 Jun 2012 03:27:05 +0000",
        "duration": "50",
        "price": "-0.02000",
        "direction": "outbound-api",
        "answered_by": null,
        "api_version": "2010-04-01",
        "forwarded_from": null,
        "caller_name": null,
        "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7.json",
        "subresource_uris": {
            "notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7\/Notifications.json",
            "recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7\/Recordings.json"
        }
    }, ... ]
}
<TwilioResponse>
	<Calls page="0" pagesize="1" 
	uri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.xml?PageSize=50" 
	firstpageuri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.xml?PageSize=50&amp;Page=0" 
	previouspageuri="" 
	nextpageuri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.xml?PageSize=50&amp;Page=1&amp;AfterSid=CA8d67bfc16f4b472a5b7c7bbf3c7977ae">
		<Call>
			<Sid>CA4c22bfc16f4b484d8b7cbe0f3c79bcc7</Sid>
			<DateCreated>Tue, 12 Jun 2012 03:25:49 +0000</DateCreated>
			<DateUpdated>Tue, 12 Jun 2012 03:27:05 +0000</DateUpdated>
			<ParentCallSid/>
			<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
			<To>+18085553279</To>
			<ToFormatted>(808) 555-3279</ToFormatted>
			<From>+17075559463</From>
			<FromFormatted>(707) 555-9463</FromFormatted>
			<PhoneNumberSid>PN907a2531e2d34c94b24b2794e73681de</PhoneNumberSid>
			<Status>completed</Status>
			<StartTime>Tue, 12 Jun 2012 03:26:15 +0000</StartTime>
			<EndTime>Tue, 12 Jun 2012 03:27:05 +0000</EndTime>
			<Duration>50</Duration>
			<Price>-0.02000</Price>
			<Direction>outbound-api</Direction>
			<AnsweredBy/>
			<ApiVersion>2010-04-01</ApiVersion>
			<ForwardedFrom/>
			<CallerName/>
			<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7.xml</Uri>
			<SubresourceUris>
				<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7/Notifications.xml</Notifications>
				<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7/Recordings.xml</Recordings>
			</SubresourceUris>
		</Call>
		...
	</Calls>
</TwilioResponse>
List All Calls Example

You can also filter the results. This example only returns phone calls to the phone number "+15558675309" which had a call status of "busy" but you can filter on other call properties as well.

Loading Code Samples...
Language
SDK Version:
  • 5.x
  • 6.x
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

# A list of call objects with the properties described above
calls = client.calls.list(status="busy",
    to="+15558675309")
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

# A list of call objects with the properties described above
calls = client.calls.list(status="busy",
                          to="+15558675309")

for call in calls:
    print(call.to)
Retrieve Busy Calls To Specific Number Example

Finally, if you just want to retrieve information about a specific call you can get that CallSid directly.

Loading Code Samples...
Language
SDK Version:
  • 5.x
  • 6.x
Format:
  • JSON
  • XML
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

call = client.calls.get("CA42ed11f93dc08b952027ffbc406d0868")
print(call.to)
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls("CA42ed11f93dc08b952027ffbc406d0868").fetch()
print(call.to)
{
	"sid": "CAe1644a7eed5088b159577c5802d8be38",
	"date_created": "Tue, 10 Aug 2010 08:02:17 +0000",
	"date_updated": "Tue, 10 Aug 2010 08:02:47 +0000",
	"parent_call_sid": null,
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"to": "+14153855708",
	"from": "+14158141819",
	"phone_number_sid": null,
	"status": "completed",
	"start_time": "Tue, 10 Aug 2010 08:02:31 +0000",
	"end_time": "Tue, 10 Aug 2010 08:02:47 +0000",
	"duration": "16",
	"price": "-0.03000",
	"direction": "outbound-api",
	"answered_by": null,
	"api_version": "2008-08-01",
	"forwarded_from": null,
	"caller_name": null,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38.json",
	"subresource_uris":{
		"notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38\/Notifications.json",
		"recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38\/Recordings.json"
	}
}
<TwilioResponse>
	<Call>
		<Sid>CAe1644a7eed5088b159577c5802d8be38</Sid>
		<DateCreated>Tue, 10 Aug 2010 08:02:17 +0000</DateCreated>
		<DateUpdated>Tue, 10 Aug 2010 08:02:47 +0000</DateUpdated>
		<ParentCallSid/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<To>+14153855708</To>
		<From>+14158141819</From>
		<PhoneNumberSid></PhoneNumberSid>
		<Status>completed</Status>
		<StartTime>Tue, 10 Aug 2010 08:02:31 +0000</StartTime>
		<EndTime>Tue, 10 Aug 2010 08:02:47 +0000</EndTime>
		<Duration>16</Duration>
		<Price>-0.03000</Price>
		<Direction>outbound-api</Direction>
		<AnsweredBy/>
		<ApiVersion>2008-08-01</ApiVersion>
		<ForwardedFrom/>
		<CallerName/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAe1644a7eed5088b159577c5802d8be38</Uri>
		<SubresourceUris>
			<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAe1644a7eed5088b159577c5802d8be38/Notifications</Notifications>
			<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAe1644a7eed5088b159577c5802d8be38/Recordings</Recordings>
		</SubresourceUris>
	</Call>
</TwilioResponse>
Retrieve Call By Id Example

Where to next?

We learned how to retrieve Twilio call logs using Python. Check out our tutorials to see full implementations of Twilio Voice in Python with Flask and Django.

David Prothero
Rob Spectre
Andrew Baker
Ricky Robinett
Kevin Whinnery

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

1 / 1
Loading Code Samples...
SDK Version:
  • 5.x
  • 6.x
Format:
  • JSON
  • XML
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

# A list of call objects with the properties described above
calls = client.calls.list()
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

# A list of call objects with the properties described above
for call in client.calls.list():
    print(call.direction)
{
    "page": 0,
    "page_size": 50,
    "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?PageSize=1",
    "first_page_uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?PageSize=50&Page=0",
    "previous_page_uri": null,
    "next_page_uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?PageSize=50&Page=1&AfterSid=CA8d67bfc16f4b472a5b7c7bbf3c7977ae",
    "calls": [{
        "sid": "CA4c22bfc16f4b484d8b7cbe0f3c79bcc7",
        "date_created": "Tue, 12 Jun 2012 03:25:49 +0000",
        "date_updated": "Tue, 12 Jun 2012 03:27:05 +0000",
        "parent_call_sid": null,
        "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        "to": "+18085553279",
        "to_formatted": "(808) 555-3279",
        "from": "+17075559463",
        "from_formatted": "(707) 555-9463",
        "phone_number_sid": "PN907a2531e2d34c94b24b2794e73681de",
        "status": "completed",
        "start_time": "Tue, 12 Jun 2012 03:26:15 +0000",
        "end_time": "Tue, 12 Jun 2012 03:27:05 +0000",
        "duration": "50",
        "price": "-0.02000",
        "direction": "outbound-api",
        "answered_by": null,
        "api_version": "2010-04-01",
        "forwarded_from": null,
        "caller_name": null,
        "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7.json",
        "subresource_uris": {
            "notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7\/Notifications.json",
            "recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7\/Recordings.json"
        }
    }, ... ]
}
<TwilioResponse>
	<Calls page="0" pagesize="1" 
	uri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.xml?PageSize=50" 
	firstpageuri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.xml?PageSize=50&amp;Page=0" 
	previouspageuri="" 
	nextpageuri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.xml?PageSize=50&amp;Page=1&amp;AfterSid=CA8d67bfc16f4b472a5b7c7bbf3c7977ae">
		<Call>
			<Sid>CA4c22bfc16f4b484d8b7cbe0f3c79bcc7</Sid>
			<DateCreated>Tue, 12 Jun 2012 03:25:49 +0000</DateCreated>
			<DateUpdated>Tue, 12 Jun 2012 03:27:05 +0000</DateUpdated>
			<ParentCallSid/>
			<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
			<To>+18085553279</To>
			<ToFormatted>(808) 555-3279</ToFormatted>
			<From>+17075559463</From>
			<FromFormatted>(707) 555-9463</FromFormatted>
			<PhoneNumberSid>PN907a2531e2d34c94b24b2794e73681de</PhoneNumberSid>
			<Status>completed</Status>
			<StartTime>Tue, 12 Jun 2012 03:26:15 +0000</StartTime>
			<EndTime>Tue, 12 Jun 2012 03:27:05 +0000</EndTime>
			<Duration>50</Duration>
			<Price>-0.02000</Price>
			<Direction>outbound-api</Direction>
			<AnsweredBy/>
			<ApiVersion>2010-04-01</ApiVersion>
			<ForwardedFrom/>
			<CallerName/>
			<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7.xml</Uri>
			<SubresourceUris>
				<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7/Notifications.xml</Notifications>
				<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7/Recordings.xml</Recordings>
			</SubresourceUris>
		</Call>
		...
	</Calls>
</TwilioResponse>
SDK Version:
  • 5.x
  • 6.x
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

# A list of call objects with the properties described above
calls = client.calls.list(status="busy",
    to="+15558675309")
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

# A list of call objects with the properties described above
calls = client.calls.list(status="busy",
                          to="+15558675309")

for call in calls:
    print(call.to)
SDK Version:
  • 5.x
  • 6.x
Format:
  • JSON
  • XML
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

call = client.calls.get("CA42ed11f93dc08b952027ffbc406d0868")
print(call.to)
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls("CA42ed11f93dc08b952027ffbc406d0868").fetch()
print(call.to)
{
	"sid": "CAe1644a7eed5088b159577c5802d8be38",
	"date_created": "Tue, 10 Aug 2010 08:02:17 +0000",
	"date_updated": "Tue, 10 Aug 2010 08:02:47 +0000",
	"parent_call_sid": null,
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"to": "+14153855708",
	"from": "+14158141819",
	"phone_number_sid": null,
	"status": "completed",
	"start_time": "Tue, 10 Aug 2010 08:02:31 +0000",
	"end_time": "Tue, 10 Aug 2010 08:02:47 +0000",
	"duration": "16",
	"price": "-0.03000",
	"direction": "outbound-api",
	"answered_by": null,
	"api_version": "2008-08-01",
	"forwarded_from": null,
	"caller_name": null,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38.json",
	"subresource_uris":{
		"notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38\/Notifications.json",
		"recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38\/Recordings.json"
	}
}
<TwilioResponse>
	<Call>
		<Sid>CAe1644a7eed5088b159577c5802d8be38</Sid>
		<DateCreated>Tue, 10 Aug 2010 08:02:17 +0000</DateCreated>
		<DateUpdated>Tue, 10 Aug 2010 08:02:47 +0000</DateUpdated>
		<ParentCallSid/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<To>+14153855708</To>
		<From>+14158141819</From>
		<PhoneNumberSid></PhoneNumberSid>
		<Status>completed</Status>
		<StartTime>Tue, 10 Aug 2010 08:02:31 +0000</StartTime>
		<EndTime>Tue, 10 Aug 2010 08:02:47 +0000</EndTime>
		<Duration>16</Duration>
		<Price>-0.03000</Price>
		<Direction>outbound-api</Direction>
		<AnsweredBy/>
		<ApiVersion>2008-08-01</ApiVersion>
		<ForwardedFrom/>
		<CallerName/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAe1644a7eed5088b159577c5802d8be38</Uri>
		<SubresourceUris>
			<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAe1644a7eed5088b159577c5802d8be38/Notifications</Notifications>
			<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAe1644a7eed5088b159577c5802d8be38/Recordings</Recordings>
		</SubresourceUris>
	</Call>
</TwilioResponse>