twilio.base package

Submodules

twilio.base.deserialize module

twilio.base.deserialize.decimal(d)[source]

Parses a decimal string into a Decimal :param d: decimal string :return: Decimal

twilio.base.deserialize.integer(i)[source]

Parses an integer string into an int :param i: integer string :return: int

twilio.base.deserialize.iso8601_date(s)[source]

Parses an ISO 8601 date string and returns a UTC date object or the string if the parsing failed. :param s: ISO 8601-formatted date string (2015-01-25) :return:

twilio.base.deserialize.iso8601_datetime(s)[source]

Parses an ISO 8601 datetime string and returns a UTC datetime object, or the string if parsing failed. :param s: ISO 8601-formatted datetime string (2015-01-25T12:34:56Z) :return: datetime or str

twilio.base.deserialize.rfc2822_datetime(s)[source]

Parses an RFC 2822 date string and returns a UTC datetime object, or the string if parsing failed. :param s: RFC 2822-formatted string date :return: datetime or str

twilio.base.domain module

class twilio.base.domain.Domain(twilio)[source]

Bases: object

This represents at Twilio API subdomain.

Like, api.twilio.com or `lookups.twilio.com’.

absolute_url(uri)[source]

Converts a relative uri to an absolute url. :param string uri: The relative uri to make absolute. :return: An absolute url (based off this domain)

request(method, uri, params=None, data=None, headers=None, auth=None, timeout=None, allow_redirects=False)[source]

Makes an HTTP request to this domain. :param string method: The HTTP method. :param string uri: The HTTP uri. :param dict params: Query parameters. :param object data: The request body. :param dict headers: The HTTP headers. :param tuple auth: Basic auth tuple of (username, password) :param float timeout: The request timeout. :param bool allow_redirects: True if the client should follow HTTP redirects.

twilio.base.exceptions module

exception twilio.base.exceptions.TwilioException[source]

Bases: Exception

exception twilio.base.exceptions.TwilioRestException(status, uri, msg='', code=None, method='GET', details=None)[source]

Bases: twilio.base.exceptions.TwilioException

A generic 400 or 500 level exception from the Twilio API

Parameters:
  • status (int) – the HTTP status that was returned for the exception
  • uri (str) – The URI that caused the exception
  • msg (str) – A human-readable message for the error
  • method (str) – The HTTP method used to make the request
  • code (int|None) – A Twilio-specific error code for the error. This is not available for all errors.
  • details (dictionary|None) – Additional error details returned for the exception

twilio.base.instance_context module

class twilio.base.instance_context.InstanceContext(version)[source]

Bases: object

twilio.base.instance_resource module

class twilio.base.instance_resource.InstanceResource(version)[source]

Bases: object

twilio.base.list_resource module

class twilio.base.list_resource.ListResource(version)[source]

Bases: object

twilio.base.obsolete module

exception twilio.base.obsolete.ObsoleteException[source]

Bases: Exception

Base class for warnings about obsolete features.

twilio.base.obsolete.deprecated_method(new_func=None)[source]

This is a decorator which can be used to mark deprecated methods. It will report in a DeprecationWarning being emitted to stderr when the deprecated method is used.

twilio.base.obsolete.obsolete_client(func)[source]

This is a decorator which can be used to mark Client classes as obsolete. It will result in an error being emitted when the class is instantiated.

twilio.base.page module

class twilio.base.page.Page(version, response)[source]

Bases: object

Represents a page of records in a collection.

A Page lets you iterate over its records and fetch the next and previous pages in the collection.

META_KEYS = {'end', 'first_page_uri', 'last_page_uri', 'next_page_uri', 'num_pages', 'page', 'page_size', 'previous_page_uri', 'start', 'total', 'uri'}
get_instance(payload)[source]
Parameters:payload (dict) – A JSON-loaded representation of an instance record.
Returns:A rich, resource-dependent object.
load_page(payload)[source]

Parses the collection of records out of a list payload.

Parameters:payload (dict) – The JSON-loaded content.
Return list:The list of records.
next()[source]

Returns the next record in the Page.

next_page()[source]

Return the Page after this one. :return Page: The next page.

next_page_url
Return str:Returns a link to the next_page_url or None if doesn’t exist.
previous_page()[source]

Return the Page before this one. :return Page: The previous page.

previous_page_url
Return str:Returns a link to the previous_page_url or None if doesn’t exist.
classmethod process_response(response)[source]

Load a JSON response.

Parameters:response (Response) – The HTTP response.
Return dict:The JSON-loaded content.

twilio.base.serialize module

twilio.base.serialize.iso8601_date(d)[source]

Return a string representation of a date that the Twilio API understands Format is YYYY-MM-DD. Returns None if d is not a string, datetime, or date

twilio.base.serialize.iso8601_datetime(d)[source]

Return a string representation of a date that the Twilio API understands Format is YYYY-MM-DD. Returns None if d is not a string, datetime, or date

twilio.base.serialize.map(lst, serialize_func)[source]

Applies serialize_func to every element in lst

twilio.base.serialize.object(obj)[source]

Return a jsonified string represenation of obj if obj is jsonifiable else return obj untouched

twilio.base.serialize.prefixed_collapsible_map(m, prefix)[source]

Return a dict of params corresponding to those in m with the added prefix

twilio.base.values module

twilio.base.values.of(d)[source]

Remove unset values from a dict.

Parameters:d (dict) – A dict to strip.
Return dict:A dict with unset values removed.

twilio.base.version module

class twilio.base.version.Version(domain)[source]

Bases: object

Represents an API version.

absolute_url(uri)[source]

Turns a relative uri into an absolute url.

create(method, uri, params=None, data=None, headers=None, auth=None, timeout=None, allow_redirects=False)[source]

Create a resource instance.

delete(method, uri, params=None, data=None, headers=None, auth=None, timeout=None, allow_redirects=False)[source]

Delete a resource.

classmethod exception(method, uri, response, message)[source]

Wraps an exceptional response in a TwilioRestException.

fetch(method, uri, params=None, data=None, headers=None, auth=None, timeout=None, allow_redirects=False)[source]

Fetch a resource instance.

page(method, uri, params=None, data=None, headers=None, auth=None, timeout=None, allow_redirects=False)[source]

Makes an HTTP request.

read_limits(limit=None, page_size=None)[source]

Takes a limit on the max number of records to read and a max page_size and calculates the max number of pages to read.

Parameters:
  • limit (int) – Max number of records to read.
  • page_size (int) – Max page size.
Return dict:

A dictionary of paging limits.

relative_uri(uri)[source]

Turns a relative uri into a versioned relative uri.

request(method, uri, params=None, data=None, headers=None, auth=None, timeout=None, allow_redirects=False)[source]

Make an HTTP request.

stream(page, limit=None, page_limit=None)[source]

Generates records one a time from a page, stopping at prescribed limits.

Parameters:
  • page (Page) – The page to stream.
  • limit (int) – The max number of records to read.
  • page_limit (int) – The max number of pages to read.
update(method, uri, params=None, data=None, headers=None, auth=None, timeout=None, allow_redirects=False)[source]

Update a resource instance.

Module contents