Rent and configure a virtual number using Python
After searching for a number, rent and configure that number for SMS, Voice or both.
Note:
Before you can get started, you need the following already set up:
- All Numbers API prerequisite steps.
- Python and a familiarity with how to create a new file.
- A virtual number you have confirmed to be available.
Installing the SDK
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
Set up your Python application
Now you can start setting up your application.
Create your file
Create a new file namedrent-config-number.py
and paste the provided code found on this page into the file.This code initalizes the Sinch Client and then purchases and configures the number you specify.
Modify your application
The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values.
Initialize the client
Before initializing a client using this SDK, you'll need three pieces of information:
- Your Project ID
- An access key ID
- An access key Secret
Note:
Fill in remaining parameters
- Assign your values to the following parameters:
Parameter | Your value |
---|---|
YOUR_servicePlanId | Your SMS service plan IDThis is only required for SMS configuration. |
YOUR_10DLC_campaignId | Your 10DLC campaign ID for this campaign. Found on the TCR platform. Remove this parameter entirely for non-10DLC numbers. |
YOUR_appId | The Voice app ID or voice API key . Found in the Customer Dashboard. |
YOUR_phone_number | The virtual phone number that you previously searched for and would like to rent. |
- Save the file.
Execute the code
- Execute the code to rent and simultaneously configure your virtual number. Open a command prompt or terminal to the location where your Python file is saved and run the following command:
python rent-config-number.py
Response
You should get a response similar to this one:
ActivateNumberResponse(
phone_number='+12067034732',
region_code='US', type='LOCAL',
capability=['SMS', 'VOICE']
)
Next steps
Send a message to yourself using the SMS API or the Voice API (after setting each up accordingly) to verify that the configuration was successful.
Additional resources
- Explore the API specification to test more endpoints.
- Follow the number rental process in the Customer Dashboard UI rather than through this API.