Twilio

Twilio is a messaging platform that allows you to send SMS messages, voice calls and variety of other tools.

Quick Start

Get Account Usage

from parsons import Twilio

twilio = Twilio()

# 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 Inbound and Outbound Messages

from parsons import Twilio

twilio = Twilio()

# 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]
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.