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.
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.
Quickstart¶
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
twilio = Twilio()
from parsons import Twilio
twilio = Twilio(account_sid='account_sid', auth_token='my_auth_token')
You can then call class methods:
twilio.get_account_usage(time_period='last_month')
twilio.get_account_usage(start_date='2019-10-01', end_date='2019-10-05')
twilio.get_account_usage(category='sms-inbound')
twilio.get_messages(date_sent='10-01-2019')
twilio.get_messages(to='9995675309')
API¶
- class parsons.twilio.twilio.Twilio(account_sid=None, auth_token=None)[source]¶
Instantiate the Twilio class
- Parameters:
account_sid – str The Twilio account sid. Not required if
TWILIO_ACCOUNT_SIDenv variable is passed.auth_token – str The Twilio auth token. Not required if
TWILIO_AUTH_TOKENenv variable is passed.
- Returns:
Twilio class
- get_account(account_sid)[source]¶
Get Twilio account
- Parameters:
account_sid – str The Twilio account sid
- Returns:
dict
- get_accounts(name=None, status=None)[source]¶
Get Twilio accounts including subaccounts.
- Parameters:
name – str Filter to name of the account
status – str Filter to an account status of
active,closedorsuspended.
- Returns:
- Table
See Table for output options.
- get_account_usage(category=None, start_date=None, end_date=None, time_period: Literal['today', 'yesterday', 'this_month', 'last_month'] | None = None, group_by: Literal['daily', 'monthly', 'yearly'] | None = None, exclude_null=False)[source]¶
Get Twilio account usage.
- Parameters:
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 (Literal['today', 'yesterday', 'this_month', 'last_month'] | None) – str A convenience method to filter usage. Can be one of
today,yesterday,this_month,last_month.group_by (Literal['daily', 'monthly', 'yearly'] | None) – str The time interval to group usage by. Can be one of
daily,monthlyoryearly.exclude_null – boolean Exclude rows that have no usage.
- Returns:
- Table
See 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.
- Parameters:
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:
- Table
See Table for output options.