Use this guide to setup your Python application for use with the Numbers API to search for an available Sinch virtual number.
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.
- PIP (package installer for Python) and a familiarity with how to install Python modules.
- Install the Sinch Python SDK.
- Set up your Python application
- Search for an available virtual number for SMS, Voice or both.
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
Create a new file named search-number.py
and paste the provided code found on this page into the file.
from sinch import SinchClient
sinch_client = SinchClient(
key_id="YOUR_key_id",
key_secret="YOUR_key_secret",
project_id="YOUR_project_id"
)
available_numbers_response = sinch_client.numbers.available.list(
region_code="YOUR_region_code",
number_type="YOUR_number_type"
)
print(available_numbers_response)
The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values.
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 <b>Access Keys</b> page of the Sinch Build Dashboard. You can also create new access key IDs and Secrets, if required.
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.
- Assign your values to the following required parameters:
Parameter | Your value |
---|---|
YOUR_region_code | The two letter abbreviation of the country for which you'd like a number. Must be in the ISO 3166-1 alpha-2. format. For example, US . |
YOUR_number_type | The type of number you would like to rent. Available options are: MOBILE , LOCAL , or TOLL_FREE . Note that 10DLC numbers should be set to LOCAL . |
- Save the file.
Execute the code to search for an available number. Open a command prompt or terminal to the location where your Python file is saved and run the following command:
python search-number.py
These steps should return a JSON list of numbers available to rent.
AvailableNumbersResponse(available_numbers=
[SinchNumber(
phone_number='YOUR_response_phone_number',
region_code='US',
type='LOCAL',
capability=['SMS','VOICE'],
setup_price={
'currencyCode': 'USD',
'amount': '2.00'
},
monthly_price={
'currencyCode': 'USD',
'amount': '2.00'
},
payment_interval_months=1,
supporting_documentation_required=True)])
Copy the phoneNumber
you would like to use and rent your virtual number using the Numbers API.
- Explore the API specification to test more endpoints.
- Prefer a UI to search for a number? Follow the entire number searching and renting process in the Sinch Build Dashboard.