← Back to Blog

How to Make Automated Phone Calls with Python

Step-by-step guide to making automated outbound calls with Python using the Wirexa API. Includes code examples for TTS, IVR menus, call recording and webhooks.

Automating phone calls with Python is easier than ever with a voice API. Whether you need to send appointment reminders, run surveys, or build an IVR system, this guide walks you through everything from setup to a working call.

Prerequisites

  • Python 3.8+
  • A Wirexa API account (request access)
  • A phone number assigned to your project

1. Install the SDK

pip install wirexaapi

2. Initialize the client

from wirexaapi import Client

client = Client(
    "your_project_id",
    "your_api_token",
    signalwire_space_url="wirexaapi.com"
)

3. Make your first call

To originate a call you need a webhook URL — your backend endpoint that returns LAML/XML to control the call flow.

call = client.calls.create(
    to="+15551234567",
    from_="+15559876543",
    url="https://your-backend.com/voice",
)
print(call.sid, call.status)  # CAxxxxx  queued

4. Control the call with LAML/XML

When the call connects, Wirexa API makes a POST request to your url. You respond with XML:

from flask import Flask, Response, request

app = Flask(__name__)

@app.route('/voice', methods=['POST'])
def voice():
    xml = '''<Response>
  <Say language="en-US" voice="polly.Joanna">
    Hello! This is an automated reminder.
    Press 1 to confirm, press 2 to cancel.
  </Say>
  <Gather numDigits="1" timeout="7" action="/gather"></Gather>
  <Hangup/>
</Response>'''
    return Response(xml, mimetype='text/xml')

@app.route('/gather', methods=['POST'])
def gather():
    digits = request.form.get('Digits')
    if digits == '1':
        msg = 'Great, your appointment is confirmed!'
    elif digits == '2':
        msg = 'Your appointment has been cancelled.'
    else:
        msg = 'We did not receive a valid option. Goodbye.'
    xml = f'<Response><Say>{msg}</Say><Hangup/></Response>'
    return Response(xml, mimetype='text/xml')

5. Record the call

Add record=True to capture the full conversation:

call = client.calls.create(
    to="+15551234567",
    from_="+15559876543",
    url="https://your-backend.com/voice",
    record=True,
    recording_status_callback="https://your-backend.com/recording",
)

When the recording is ready, your recording_status_callback receives a POST with RecordingUrl — accessible as .wav or .mp3.

6. Receive call status updates

call = client.calls.create(
    to="+15551234567",
    from_="+15559876543",
    url="https://your-backend.com/voice",
    status_callback="https://your-backend.com/status",
    status_callback_event=["answered", "completed"],
)

Summary

With Wirexa API and Python you can build production-grade automated call systems in minutes. The API is fully compatible with SignalWire and Twilio SDKs — no vendor lock-in.

Ready to get started? Request access or explore the full API reference.

Ready to build with Wirexa API?

Get your API credentials and make your first call in minutes.

Request access →