Skip to main content

Twilio API client and TwiML generator

Project description

https://secure.travis-ci.org/twilio/twilio-python.png?branch=master https://img.shields.io/pypi/v/twilio.svg https://img.shields.io/pypi/pyversions/twilio.svg

A module for using the Twilio REST API and generating valid TwiML.

Recent Update

As of release 6.5.0, Beta and Developer Preview products are now exposed via the main twilio-python artifact. Releases of the alpha branch have been discontinued.

If you were using the alpha release line, you should be able to switch back to the normal release line without issue.

If you were using the normal release line, you should now see several new product lines that were historically hidden from you due to their Beta or Developer Preview status. Such products are explicitly documented as Beta/Developer Preview both in the Twilio docs and console, as well as through in-line code documentation here in the library.

Installation

Install from PyPi using pip, a package manager for Python.

pip install twilio

Don’t have pip installed? Try installing it, by running this from the command line:

$ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python

Or, you can download the source code (ZIP) for twilio-python, and then run:

python setup.py install

You may need to run the above commands with sudo.

Migrate from 5.x

Please consult the official migration guide for information on upgrading your application using twilio-python 5.x to 6.x

Getting Started

Getting started with the Twilio API couldn’t be easier. Create a Client and you’re ready to go.

API Credentials

The Twilio needs your Twilio credentials. You can either pass these directly to the constructor (see the code below) or via environment variables.

from twilio.rest import Client

account = "ACXXXXXXXXXXXXXXXXX"
token = "YYYYYYYYYYYYYYYYYY"
client = Client(account, token)

Alternately, a Client constructor without these parameters will look for TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN variables inside the current environment.

We suggest storing your credentials as environment variables. Why? You’ll never have to worry about committing your credentials and accidentally posting them somewhere public.

from twilio.rest import Client
client = Client()

Make a Call

from twilio.rest import Client

account = "ACXXXXXXXXXXXXXXXXX"
token = "YYYYYYYYYYYYYYYYYY"
client = Client(account, token)

call = client.calls.create(to="9991231234",
                           from_="9991231234",
                           url="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
print(call.sid)

Send an SMS

from twilio.rest import Client

account = "ACXXXXXXXXXXXXXXXXX"
token = "YYYYYYYYYYYYYYYYYY"
client = Client(account, token)

message = client.messages.create(to="+12316851234", from_="+15555555555",
                                 body="Hello there!")

Handling a call using TwiML

To control phone calls, your application needs to output TwiML. Use twilio.twiml.Response to easily create such responses.

from twilio.twiml.voice_response import VoiceResponse

r = VoiceResponse()
r.say("Welcome to twilio!")
print(str(r))
<?xml version="1.0" encoding="utf-8"?>
<Response><Say>Welcome to twilio!</Say></Response>

Docker Image

The Dockerfile present in this repository and its respective twilio/twilio-python Docker image are currently used by Twilio for testing purposes only.

Getting help

If you need help installing or using the library, please check the Twilio Support Help Center first, and file a support ticket if you don’t find an answer to your question.

If you’ve instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twilio-6.25.2.tar.gz (364.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twilio-6.25.2-py2.py3-none-any.whl (943.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file twilio-6.25.2.tar.gz.

File metadata

  • Download URL: twilio-6.25.2.tar.gz
  • Upload date:
  • Size: 364.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.16

File hashes

Hashes for twilio-6.25.2.tar.gz
Algorithm Hash digest
SHA256 c45dc64f947db5dcfb7d43798d0572f20558e2497f61db0bc63d82c6f71d8637
MD5 6560f642dfceded3467f88f211daf1a3
BLAKE2b-256 61efdc3ecba91d9e8014b0ca46e38381e83c6ab2fc459fef8cb4b90c10a95681

See more details on using hashes here.

File details

Details for the file twilio-6.25.2-py2.py3-none-any.whl.

File metadata

  • Download URL: twilio-6.25.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 943.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.16

File hashes

Hashes for twilio-6.25.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cd26f860108f2eaf0eb0ea22cb501664a92c2ef308246a964d3aa9aa26d21fb0
MD5 0e948ed939a7a30b87320a96e1030bef
BLAKE2b-256 362fcbe1c967722486ba08eb11fecc6daeb83720cb06def3f99d9f624b1651ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page