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:

Installing the SDK

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

Set up your Python application

Now you can start setting up your application.

Create your file

Create a new file named rent-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
These values can be found on the Access Keys page of the Customer Dashboard. You can also create new access key IDs and Secrets, if required.
Note:
If you have trouble accessing the above link, ensure that you have gained access to the Conversation API by accepting the corresponding terms and conditions.

Fill in remaining parameters

  1. Assign your values to the following parameters:
ParameterYour value
YOUR_servicePlanIdYour SMS service plan IDThis is only required for SMS configuration.
YOUR_10DLC_campaignIdYour 10DLC campaign ID for this campaign. Found on the TCR platform. Remove this parameter entirely for non-10DLC numbers.
YOUR_appIdThe Voice app ID or voice API key. Found in the Customer Dashboard.
YOUR_phone_numberThe virtual phone number that you previously searched for and would like to rent.
  1. Save the file.

Execute the code

  1. 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:
Copy
Copied
python rent-config-number.py

Response

You should get a response similar to this one:

Copy
Copied
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

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