Make a call with Python SDK

You can quickly see how the Voice API works by calling yourself using the Python SDK for Voice API.

In this guide you will learn:

  1. How to set up your Python application.
  2. How to call your phone number.
Note:

Before you can get started, you need the following already set up:

Set up your Python application

Create a new project folder.

The easiest way to install the SDK is using pip:

  1. Open a command prompt or terminal to the local repository folder.
  2. Execute the following command:
    Copy
    Copied
    pip install sinch

Modify your application

In your project folder, create a new filed named "app.py" and paste the provided "app.py" code into the file.

The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values.

Initialize the client

To start using the SDK, you need to initialize the main client class with your credentials from your Sinch dashboard and additionally add your Voice app credentials.

Copy
Copied
from sinch import SinchClient

sinch_client = SinchClient(
    application_key="YOUR_application_key",
    application_secret="YOUR_application_secret"
)
Note:

For testing purposes on your local environment it's fine to use hardcoded values, but before deploying to production we strongly recommend using environment variables to store the credentials, as in the following example:

Copy
Copied
import os
from sinch import SinchClient

sinch_client = SinchClient(
    application_key=os.getenv("APPLICATION_KEY"),
    application_secret=os.getenv("APPLICATION_SECRET")
)

Destination

In this example you want to call a phone number. Change the value of the endpoint parameter to the phone number you verified in your dashboard in E.164 format.
Note:

When your account is in trial mode, you can only call your verified numbers. If you want to call any number, you need to upgrade your account!

Save the file.

Make your first call

Now you can execute the code and make your text-to-speech call. Run the following command:

Copy
Copied
python app.py

You should receive a phone call to the number you called with the message "Hello, this is a call from Sinch. Congratulations! You made your first call."

Next steps

Now that you know how to make a call, learn how to handle an incoming call.

Additional resources

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.