Twilio

Overview

Twilio is a messaging platform that allows you to programmatically send and receive SMS messages, send and receive voice calls, and perform other communication functions. This Parsons integration provides methods for fetching messages, accounts, and account usage data.

Note

Authentication

Twilio requires an account SID and an authorization token, which can be found in the Admin Console.

For more information about authentication, see the Twilio API documentation.

Quick Start

Get Account Usage

To instantiate the Twilio class, you can either store your Twilio account SID and authorization token as environmental variables (TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN, respectively) or pass them in as arguments:

from parsons import Twilio

# First approach: Use API credentials via environmental variables
twilio = Twilio()

# Second approach: Pass API credentials as arguments
twilio = Twilio(account_sid='account_sid', auth_token='my_auth_token')

# Get usage last month
twilio.get_account_usage(time_period='last_month')

# Get usage for a specific date period
twilio.get_account_usage(start_date='2019-10-01', end_date='2019-10-05')

# Get usage for a specific resource
twilio.get_account_usage(category='sms-inbound')

     # Get messages from a specific day
     twilio.get_messages(date_sent='10-01-2019')

     # Get messages sent to a specific phone number
     twilio.get_messages(to='9995675309')

API

class parsons.Twilio(account_sid=None, auth_token=None)[source]

Instantiate the Twilio class

Args:
account_sid: str
The Twilio account sid. Not required if TWILIO_ACCOUNT_SID env variable is passed.
auth_token: str
The Twilio auth token. Not required if TWILIO_AUTH_TOKEN env variable is passed.
Returns:
Twilio class
get_account(account_sid)[source]

Get Twilio account

Args:
account_sid: str
The Twilio account sid
Returns:
dict
get_accounts(name=None, status=None)[source]

Get Twilio accounts including subaccounts.

Args:
name: str
Filter to name of the account
status: str
Filter to an account status of active, closed or suspended.
Returns:
Parsons Table
See Parsons Table for output options.
get_account_usage(category=None, start_date=None, end_date=None, time_period=None, group_by=None, exclude_null=False)[source]

Get Twilio account usage.

Args:
category: str
Filter to a specific type of usage category. The list of possibilities can be found here.
start_date: str
Filter to usage from a specific start date (ex. 2019-01-01).
end_date: str
Filter to usage from a specific end date (ex. 2019-01-01).
time_period: str
A convenience method to filter usage. Can be one of today, yesterday, this_month, last_month.
group_by: str
The time interval to group usage by. Can be one of daily, monthly or yearly.
exclude_null: boolean
Exclude rows that have no usage.
Returns:
Parsons Table
See Parsons Table for output options.
get_messages(to=None, from_=None, date_sent=None, date_sent_before=None, date_sent_after=None)[source]

Get Twilio messages.

Args:
to: str
Filter to messages only sent to the specified phone number.
from_: str
Filter to messages only sent from the specified phone number.
date_sent: str
Filter to messages only sent on the specified date (ex. 2019-01-01).
date_sent_before: str
Filter to messages only sent before the specified date (ex. 2019-01-01).
date_sent_after: str
Filter to messages only sent after the specified date (ex. 2019-01-01).
Returns:
Parsons Table
See Parsons Table for output options.