|
| 1 | +twilio-python |
| 2 | +============= |
| 3 | + |
| 4 | +.. image:: https://secure.travis-ci.org/twilio/twilio-python.png?branch=master |
| 5 | + :target: http://travis-ci.org/twilio/twilio-python |
| 6 | +.. image:: https://img.shields.io/pypi/v/twilio.svg |
| 7 | + :target: https://pypi.python.org/pypi/twilio |
| 8 | +.. image:: https://img.shields.io/pypi/pyversions/twilio.svg |
| 9 | + :target: https://pypi.python.org/pypi/twilio |
| 10 | + |
| 11 | +A module for using the Twilio REST API and generating valid |
| 12 | +`TwiML <http://www.twilio.com/docs/api/twiml/>`__. |
| 13 | + |
| 14 | +Recent Update |
| 15 | +------------- |
| 16 | + |
| 17 | +As of release 6.5.0, Beta and Developer Preview products are now exposed |
| 18 | +via the main ``twilio-python`` artifact. Releases of the ``alpha`` |
| 19 | +branch have been discontinued. |
| 20 | + |
| 21 | +If you were using the ``alpha`` release line, you should be able to |
| 22 | +switch back to the normal release line without issue. |
| 23 | + |
| 24 | +If you were using the normal release line, you should now see several |
| 25 | +new product lines that were historically hidden from you due to their |
| 26 | +Beta or Developer Preview status. Such products are explicitly |
| 27 | +documented as Beta/Developer Preview both in the Twilio docs and |
| 28 | +console, as well as through in-line code documentation here in the |
| 29 | +library. |
| 30 | + |
| 31 | +Installation |
| 32 | +------------ |
| 33 | + |
| 34 | +Install from PyPi using |
| 35 | +`pip <http://www.pip-installer.org/en/latest/>`__, a package manager for |
| 36 | +Python. |
| 37 | + |
| 38 | +:: |
| 39 | + |
| 40 | + pip install twilio |
| 41 | + |
| 42 | +Don't have pip installed? Try installing it, by running this from the |
| 43 | +command line: |
| 44 | + |
| 45 | +:: |
| 46 | + |
| 47 | + $ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python |
| 48 | + |
| 49 | +Or, you can `download the source code |
| 50 | +(ZIP) <https://github.com/twilio/twilio-python/zipball/master>`__ for |
| 51 | +``twilio-python``, and then run: |
| 52 | + |
| 53 | +:: |
| 54 | + |
| 55 | + python setup.py install |
| 56 | + |
| 57 | +You may need to run the above commands with ``sudo``. |
| 58 | + |
| 59 | +Migrate from 5.x |
| 60 | +~~~~~~~~~~~~~~~~ |
| 61 | + |
| 62 | +Please consult the `official migration |
| 63 | +guide <https://www.twilio.com/docs/libraries/python/migration-guide>`__ |
| 64 | +for information on upgrading your application using twilio-python 5.x to |
| 65 | +6.x |
| 66 | + |
| 67 | +Feedback |
| 68 | +-------- |
| 69 | + |
| 70 | +Report any feedback or problems with this Release Candidate to the |
| 71 | +`Github Issues <https://github.com/twilio/twilio-python/issues>`__ for |
| 72 | +twilio-python. |
| 73 | + |
| 74 | +Getting Started |
| 75 | +--------------- |
| 76 | + |
| 77 | +Getting started with the Twilio API couldn't be easier. Create a |
| 78 | +``Client`` and you're ready to go. |
| 79 | + |
| 80 | +API Credentials |
| 81 | +~~~~~~~~~~~~~~~ |
| 82 | + |
| 83 | +The ``Twilio`` needs your Twilio credentials. You can either pass these |
| 84 | +directly to the constructor (see the code below) or via environment |
| 85 | +variables. |
| 86 | + |
| 87 | +.. code:: python |
| 88 | +
|
| 89 | + from twilio.rest import Client |
| 90 | +
|
| 91 | + account = "ACXXXXXXXXXXXXXXXXX" |
| 92 | + token = "YYYYYYYYYYYYYYYYYY" |
| 93 | + client = Client(account, token) |
| 94 | +
|
| 95 | +Alternately, a ``Client`` constructor without these parameters will look |
| 96 | +for ``TWILIO_ACCOUNT_SID`` and ``TWILIO_AUTH_TOKEN`` variables inside |
| 97 | +the current environment. |
| 98 | + |
| 99 | +We suggest storing your credentials as environment variables. Why? |
| 100 | +You'll never have to worry about committing your credentials and |
| 101 | +accidentally posting them somewhere public. |
| 102 | + |
| 103 | +.. code:: python |
| 104 | +
|
| 105 | + from twilio.rest import Client |
| 106 | + client = Client() |
| 107 | +
|
| 108 | +Make a Call |
| 109 | +~~~~~~~~~~~ |
| 110 | + |
| 111 | +.. code:: python |
| 112 | +
|
| 113 | + from twilio.rest import Client |
| 114 | +
|
| 115 | + account = "ACXXXXXXXXXXXXXXXXX" |
| 116 | + token = "YYYYYYYYYYYYYYYYYY" |
| 117 | + client = Client(account, token) |
| 118 | +
|
| 119 | + call = client.calls.create(to="9991231234", |
| 120 | + from_="9991231234", |
| 121 | + url="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient") |
| 122 | + print(call.sid) |
| 123 | +
|
| 124 | +Send an SMS |
| 125 | +~~~~~~~~~~~ |
| 126 | + |
| 127 | +.. code:: python |
| 128 | +
|
| 129 | + from twilio.rest import Client |
| 130 | +
|
| 131 | + account = "ACXXXXXXXXXXXXXXXXX" |
| 132 | + token = "YYYYYYYYYYYYYYYYYY" | <
741A
/tr>
| 133 | + client = Client(account, token) |
| 134 | +
|
| 135 | + message = client.messages.create(to="+12316851234", from_="+15555555555", |
| 136 | + body="Hello there!") |
| 137 | +
|
| 138 | +Handling a call using TwiML |
| 139 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 140 | + |
| 141 | +To control phone calls, your application needs to output |
| 142 | +`TwiML <http://www.twilio.com/docs/api/twiml/>`__. Use |
| 143 | +``twilio.twiml.Response`` to easily create such responses. |
| 144 | + |
| 145 | +.. code:: python |
| 146 | +
|
| 147 | + from twilio.twiml.voice_response import VoiceResponse |
| 148 | +
|
| 149 | + r = VoiceResponse() |
| 150 | + r.say("Welcome to twilio!") |
| 151 | + print(str(r)) |
| 152 | +
|
FA13
| 153 | +.. code:: xml |
| 154 | +
|
| 155 | + <?xml version="1.0" encoding="utf-8"?> |
| 156 | + <Response><Say>Welcome to twilio!</Say></Response> |
0 commit comments