Git Product home page Git Product logo

sdk-python's Introduction

Apidaze Python SDK

The Apidaze Python SDK contains the Python client of Apidaze REST API as well as an XML script builder. The SDK allows you to leverage all Apidaze platform features such as making calls, sending text messages, serving IVR systems and many others in your Python based application. The SDK also includes sample applications that demonstrate how to use the SDK interfaces. See Apidaze REST API specification which includes XML Scripting Reference as well.

Requirements

  • Python 3.4+
  • requests
  • lxml

Installation

To install the SDK just type

make

After that activate the virtual environment by typing

source venv/bin/activate

Now you're ready to install all python dependencies

pip install -r requirements.txt

You're now ready to use the SDK

Quickstart

SDK client

Initiate the SDK Client

from apidaze import Client

apidaze = Client(api_key=API_KEY, api_secret=API_SECRET)

Where API_KEY and API_SECRET should be replaced with the real key and secret from your Apidaze application.

Make a call

apidaze.calls.place(
        caller_id='9876543',
        origin='123456',
        destination='123456',
        CallType.number)

Where caller_id is the phone number to be presented as caller id, origin the phone number or SIP account to ring first, and destination is passed as a parameter to your External Script URL.

Send a text message

apidaze.messages.send(
   origin='14125423968',
   destination='14125423968',
   body='Hello World from Python SDK'
)

Where origin is the number to send the text from. Must be an active number on your account. destination is the number you want to send the text to. body is the message to send.

Download recordings

response = apidaze.recordings.get(filename='my_recording.wav')
data = response['body']
file = open(filename, 'wb')
file.write(data)
file.close()

In this example, we will download the recording named my_recording.wav.

Script builder

The script builder is used to build XML instructions described in XML Scripting Reference. To build an instruction which echo back received audio to the caller with some delay use the following code.

from apidaze.script import Builder, Answer, Echo, Speak

xmlbuilder = Builder()
answer = Answer()
speak = Speak(text='Thank you for trying our demo. Have an wonderful day!')
echo = Echo(500)

xmlbuilder.add(answer).add(speak).add(echo)
xmlbuilder.printXML()

The code above will produce the following XML

<?xml version='1.0' encoding='utf8'?>
<document>
  <work>
    <answer/>
    <speak lang="en-US">Thank you for trying our demo. Have an wonderful day!</speak>
    <echo>500</echo>
  </work>
</document>

More examples

For more examples please see our example repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.