banner



How To Install Twilio In Python 2.7

twilio-python

Tests PyPI PyPI Learn OSS Contribution in TwilioQuest

  • The default branch name for this repository has been changed to principal every bit of 07/27/2020.

Documentation

The documentation for the Twilio API tin be found here.

The Python library documentation tin be found here.

Versions

twilio-python uses a modified version of Semantic Versioning for all changes. See this document for details.

Migrating from five.x

Please consult the official migration guide for information on upgrading your awarding using twilio-python 5.x to half-dozen.x

Supported Python Versions

This library supports the following Python implementations:

  • Python 3.six
  • Python 3.7
  • Python 3.8
  • Python 3.9
  • Python 3.10

Installation

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

          pip install twilio                  

If pip install fails on Windows, check the path length of the directory. If it is greater 260 characters and then enable Long Paths or cull other shorter location.

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

          $ curl https://bootstrap.pypa.io/go-pip.py | python                  

Or, y'all can download the source code (Nil) for twilio-python, and then run:

          python setup.py install                  

You may need to run the in a higher place commands with sudo.

Getting Started

Getting started with the Twilio API couldn't exist easier. Create a Customer and you lot're ready to go.

API Credentials

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

          from          twilio.residue          import          Customer          account          =          "ACXXXXXXXXXXXXXXXXX"          token          =          "YYYYYYYYYYYYYYYYYY"          client          =          Client          (          account          ,          token          )        

Alternatively, a Customer constructor without these parameters will wait for TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN variables inside the current surroundings.

We propose storing your credentials as surroundings variables. Why? You'll never take to worry well-nigh committing your credentials and accidentally posting them somewhere public.

          from          twilio.rest          import          Client          client          =          Client          ()        

Specify Region and/or Edge

To take advantage of Twilio'south Global Infrastructure, specify the target Region and/or Edge for the client:

          from          twilio.rest          import          Client          customer          =          Client          (          region          =          'au1'          ,          border          =          'sydney'          )        

A Client constructor without these parameters will also look for TWILIO_REGION and TWILIO_EDGE variables inside the current environment.

Alternatively, you lot may specify the edge and/or region after constructing the Twilio customer:

          from          twilio.rest          import          Client          client          =          Client          ()          client          .          region          =          'au1'          client          .          edge          =          'sydney'        

This will result in the hostname transforming from api.twilio.com to api.sydney.au1.twilio.com.

Make a Phone call

          from          twilio.residue          import          Customer          account          =          "ACXXXXXXXXXXXXXXXXX"          token          =          "YYYYYYYYYYYYYYYYYY"          client          =          Customer          (          account          ,          token          )          call          =          customer          .          calls          .          create          (          to          =          "9991231234"          ,          from_          =          "9991231234"          ,          url          =          "http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient"          )          print          (          call          .          sid          )        

Transport an SMS

          from          twilio.residuum          import          Client          account          =          "ACXXXXXXXXXXXXXXXXX"          token          =          "YYYYYYYYYYYYYYYYYY"          customer          =          Customer          (          business relationship          ,          token          )          bulletin          =          customer          .          messages          .          create          (          to          =          "+12316851234"          ,          from_          =          "+15555555555"          ,          torso          =          "Hello there!"          )        

Enable Debug Logging

Log the API request and response data to the console:

          import          logging          client          =          Client          (          business relationship          ,          token          )          logging          .          basicConfig          ()          client          .          http_client          .          logger          .          setLevel          (          logging          .          INFO          )        

Log the API request and response data to a file:

          import          logging          client          =          Client          (          business relationship          ,          token          )          logging          .          basicConfig          (          filename          =          './log.txt'          )          client          .          http_client          .          logger          .          setLevel          (          logging          .          INFO          )        

Handling Exceptions

          from          twilio.rest          import          Client          from          twilio.base.exceptions          import          TwilioRestException          account          =          "ACXXXXXXXXXXXXXXXXX"          token          =          "YYYYYYYYYYYYYYYYYY"          client          =          Customer          (          account          ,          token          )          try          :          message          =          client          .          messages          .          create          (          to          =          "+12316851234"          ,          from_          =          "+15555555555"          ,          body          =          "Howdy there!"          )          except          TwilioRestException          equally          eastward          :          print          (          e          )        

For more descriptive exception types, delight see the Twilio documentation.

Generating TwiML

To control phone calls, your application needs to output TwiML.

Utilize 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="ane.0" encoding="utf-viii"?>          <Response><Say>Welcome to twilio!</Say></Response>        

Using a Custom HTTP Client

To use a custom HTTP client with this helper library, please come across the Twilio documentation.

Docker Image

The Dockerfile present in this repository and its corresponding twilio/twilio-python Docker prototype are currently used by Twilio for testing purposes but.

Getting help

If y'all need help installing or using the library, delight bank check the Twilio Support Help Center first, and file a back up ticket if you lot don't find an answer to your question.

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

Source: https://pypi.org/project/twilio/

Posted by: groesbeckalmly1938.blogspot.com

0 Response to "How To Install Twilio In Python 2.7"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel