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:
Note:
Before you can get started, you need the following already set up:
- Set all Voice API configuration settings.
- Python and a familiarity with how to create a new file.
- PIP (package installer for Python) and a familiarity with how to install Python modules.
Set up your Python application
Create a new project folder.
The easiest way to install the SDK is using pip
:
- Open a command prompt or terminal to the local repository folder.
- Execute the following command:
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.
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:
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 theendpoint
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:
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.