title: twilio export message logs to csv via python
body: <p>I'm trying to retrieve a month of message logs from twilio using python. The code below works fine when retrieving a day or two but is extremely slow when expanding the date range.  Is there a better way to do this?</p>
  
  <pre><code>import pandas as pd
  from datetime import date
  from twilio.rest import Client
  
  # Your Account Sid and Auth Token from twilio.com/user/account
  account_sid = "####"
  auth_token = "####"
  client = Client(account_sid, auth_token)
  
  
  messages = client.messages.list(
      date_sent_after=date(2017, 3, 1),
      date_sent_before=date(2017, 3, 2)
  )
  
  
  d = []
  for message in messages:
     d.append((message.from_, message.to, message.body, message.status, 
     message.date_sent, message.price))
  
  print(d)
  
  df = pd.DataFrame(d, columns=('From', 'To', 'Body', 'Status', 'Sent Date', 'Price'))
  
  
  print(df.dtypes)
  
  df.to_csv('export.csv', index=False, encoding='utf-8')
  </code></pre>