• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

twilio/H15-Dec-2021-198,337158,227

twilio.egg-info/H03-May-2022-244167

AUTHORS.mdH A D15-Dec-20211.4 KiB4139

LICENSEH A D15-Dec-20211.1 KiB2217

MANIFEST.inH A D15-Dec-2021117 43

PKG-INFOH A D15-Dec-20218.6 KiB244167

README.mdH A D15-Dec-20217.6 KiB215141

setup.cfgH A D15-Dec-2021177 149

setup.pyH A D15-Dec-20211.5 KiB4736

README.md

1# twilio-python
2
3[![Tests](https://github.com/twilio/twilio-python/actions/workflows/test-and-deploy.yml/badge.svg)](https://github.com/twilio/twilio-python/actions/workflows/test-and-deploy.yml)
4[![PyPI](https://img.shields.io/pypi/v/twilio.svg)](https://pypi.python.org/pypi/twilio)
5[![PyPI](https://img.shields.io/pypi/pyversions/twilio.svg)](https://pypi.python.org/pypi/twilio)
6[![Learn OSS Contribution in TwilioQuest](https://img.shields.io/static/v1?label=TwilioQuest&message=Learn%20to%20contribute%21&color=F22F46&labelColor=1f243c&style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAASFBMVEUAAAAZGRkcHBwjIyMoKCgAAABgYGBoaGiAgICMjIyzs7PJycnMzMzNzc3UoBfd3d3m5ubqrhfrMEDu7u739/f4vSb/3AD///9tbdyEAAAABXRSTlMAAAAAAMJrBrEAAAKoSURBVHgB7ZrRcuI6EESdyxXGYoNFvMD//+l2bSszRgyUYpFAsXOeiJGmj4NkuWx1Qeh+Ekl9DgEXOBwOx+Px5xyQhDykfgq4wG63MxxaR4ddIkg6Ul3g84vCIcjPBA5gmUMeXESrlukuoK33+33uID8TWeLAdOWsKpJYzwVMB7bOzYSGOciyUlXSn0/ABXTosJ1M1SbypZ4O4MbZuIDMU02PMbauhhHMHXbmebmALIiEbbbbbUrpF1gwE9kFfRNAJaP+FQEXCCTGyJ4ngDrjOFo3jEL5JdqjF/pueR4cCeCGgAtwmuRS6gDwaRiGvu+DMFwSBLTE3+jF8JyuV1okPZ+AC4hDFhCHyHQjdjPHUKFDlHSJkHQXMB3KpSwXNGJPcwwTdZiXlRN0gSp0zpWxNtM0beYE0nRH6QIbO7rawwXaBYz0j78gxjokDuv12gVeUuBD0MDi0OQCLvDaAho4juP1Q/jkAncXqIcCfd+7gAu4QLMACCLxpRsSuQh0igu0C9Svhi7weAGZg50L3IE3cai4IfkNZAC8dfdhsUD3CgKBVC9JE5ABAFzg4QL/taYPAAWrHdYcgfLaIgAXWJ7OV38n1LEF8tt2TH29E+QAoDoO5Ve/LtCQDmKM9kPbvCEBApK+IXzbcSJ0cIGF6e8gpcRhUDogWZ8JnaWjPXc/fNnBBUKRngiHgTUSivSzDRDgHZQOLvBQgf8rRt+VdBUUhwkU6VpJ+xcOwQUqZr+mR0kvBUgv6cB4+37hQAkXqE8PwGisGhJtN4xAHMzrsgvI7rccXqSvKh6jltGlrOHA3Xk1At3LC4QiPdX9/0ndHpGVvTjR4bZA1ypAKgVcwE5vx74ulwIugDt8e/X7JgfkucBMIAr26ndnB4UCLnDOqvteQsHlgX9N4A+c4cW3DXSPbwAAAABJRU5ErkJggg==)](https://twil.io/learn-open-source)
7
8* **The default branch name for this repository has been changed to `main` as of 07/27/2020.**
9
10## Documentation
11
12The documentation for the Twilio API can be found [here][apidocs].
13
14The Python library documentation can be found [here][libdocs].
15
16## Versions
17
18`twilio-python` uses a modified version of [Semantic Versioning](https://semver.org) for all changes. [See this document](VERSIONS.md) for details.
19
20### Migrating from 5.x
21
22Please consult the [official migration guide](https://www.twilio.com/docs/libraries/python/migration-guide) for information on upgrading your application using twilio-python 5.x to 6.x
23
24### Supported Python Versions
25
26This library supports the following Python implementations:
27
28* Python 3.6
29* Python 3.7
30* Python 3.8
31* Python 3.9
32
33## Installation
34
35Install from PyPi using [pip](https://pip.pypa.io/en/latest/), a
36package manager for Python.
37
38    pip install twilio
39
40If pip install fails on Windows, check the path length of the directory. If it is greater 260 characters then enable [Long Paths](https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation) or choose other shorter location.
41
42Don't have pip installed? Try installing it, by running this from the command
43line:
44
45    $ curl https://bootstrap.pypa.io/get-pip.py | python
46
47Or, you can [download the source code
48(ZIP)](https://github.com/twilio/twilio-python/zipball/main "twilio-python
49source code") for `twilio-python`, and then run:
50
51    python setup.py install
52
53You may need to run the above commands with `sudo`.
54
55## Getting Started
56
57Getting started with the Twilio API couldn't be easier. Create a
58`Client` and you're ready to go.
59
60### API Credentials
61
62The `Twilio` needs your Twilio credentials. You can either pass these
63directly to the constructor (see the code below) or via environment variables.
64
65```python
66from twilio.rest import Client
67
68account = "ACXXXXXXXXXXXXXXXXX"
69token = "YYYYYYYYYYYYYYYYYY"
70client = Client(account, token)
71```
72
73Alternatively, a `Client` constructor without these parameters will
74look for `TWILIO_ACCOUNT_SID` and `TWILIO_AUTH_TOKEN` variables inside the
75current environment.
76
77We suggest storing your credentials as environment variables. Why? You'll never
78have to worry about committing your credentials and accidentally posting them
79somewhere public.
80
81
82```python
83from twilio.rest import Client
84client = Client()
85```
86
87### Specify Region and/or Edge
88
89To take advantage of Twilio's [Global Infrastructure](https://www.twilio.com/docs/global-infrastructure), specify the target Region and/or Edge for the client:
90
91```python
92from twilio.rest import Client
93
94client = Client(region='au1', edge='sydney')
95```
96A `Client` constructor  without these parameters will also look for `TWILIO_REGION` and `TWILIO_EDGE` variables inside the current environment.
97
98Alternatively, you may specify the edge and/or region after constructing the Twilio client:
99
100```python
101from twilio.rest import Client
102
103client = Client()
104client.region = 'au1'
105client.edge = 'sydney'
106```
107
108This will result in the `hostname` transforming from `api.twilio.com` to `api.sydney.au1.twilio.com`.
109
110### Make a Call
111
112```python
113from twilio.rest import Client
114
115account = "ACXXXXXXXXXXXXXXXXX"
116token = "YYYYYYYYYYYYYYYYYY"
117client = Client(account, token)
118
119call = client.calls.create(to="9991231234",
120                           from_="9991231234",
121                           url="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
122print(call.sid)
123```
124
125### Send an SMS
126
127```python
128from twilio.rest import Client
129
130account = "ACXXXXXXXXXXXXXXXXX"
131token = "YYYYYYYYYYYYYYYYYY"
132client = Client(account, token)
133
134message = client.messages.create(to="+12316851234", from_="+15555555555",
135                                 body="Hello there!")
136```
137
138### Enable Debug Logging
139
140Log the API request and response data to the console:
141
142```python
143import logging
144
145client = Client(account, token)
146logging.basicConfig()
147client.http_client.logger.setLevel(logging.INFO)
148```
149
150Log the API request and response data to a file:
151
152```python
153import logging
154
155client = Client(account, token)
156logging.basicConfig(filename='./log.txt')
157client.http_client.logger.setLevel(logging.INFO)
158```
159
160### Handling Exceptions
161
162```python
163from twilio.rest import Client
164from twilio.base.exceptions import TwilioRestException
165
166account = "ACXXXXXXXXXXXXXXXXX"
167token = "YYYYYYYYYYYYYYYYYY"
168client = Client(account, token)
169
170try:
171  message = client.messages.create(to="+12316851234", from_="+15555555555",
172                                   body="Hello there!")
173except TwilioRestException as e:
174  print(e)
175```
176
177For more descriptive exception types, please see the [Twilio documentation](https://www.twilio.com/docs/libraries/python/usage-guide#exceptions).
178
179### Generating TwiML
180
181To control phone calls, your application needs to output [TwiML][twiml].
182
183Use `twilio.twiml.Response` to easily create such responses.
184
185```python
186from twilio.twiml.voice_response import VoiceResponse
187
188r = VoiceResponse()
189r.say("Welcome to twilio!")
190print(str(r))
191```
192
193```xml
194<?xml version="1.0" encoding="utf-8"?>
195<Response><Say>Welcome to twilio!</Say></Response>
196```
197
198### Using a Custom HTTP Client
199
200To use a custom HTTP client with this helper library, please see the [Twilio documentation](https://www.twilio.com/docs/libraries/python/custom-http-clients-python).
201
202### Docker Image
203
204The `Dockerfile` present in this repository and its respective `twilio/twilio-python` Docker image are currently used by Twilio for testing purposes only.
205
206### Getting help
207
208If you need help installing or using the library, please check the [Twilio Support Help Center](https://support.twilio.com) first, and [file a support ticket](https://twilio.com/help/contact) if you don't find an answer to your question.
209
210If 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!
211
212[apidocs]: https://www.twilio.com/docs/api
213[twiml]: https://www.twilio.com/docs/api/twiml
214[libdocs]: https://twilio.github.io/twilio-python
215