Vonage Number Insight
The `vonage-number-insight` package provides Python access to Vonage's Number Insight API, allowing users to retrieve real-time intelligence about phone numbers at basic, standard, and advanced levels. While currently functional, the Vonage Number Insight API is scheduled for sunset on February 4, 2027, with migration encouraged to the Vonage Identity Insights API. The library's current version is 1.0.7 and it's typically updated in conjunction with the main Vonage Python SDK.
Common errors
-
AuthenticationError: 'Signature verification failed' or 'API Key / Secret is invalid'
cause The provided Vonage API Key or API Secret is incorrect, or environment variables are not loaded.fixVerify your `VONAGE_API_KEY` and `VONAGE_API_SECRET` credentials from your Vonage dashboard. Ensure they are correctly set as environment variables or passed directly to the `Vonage` client constructor. -
AttributeError: 'VonageClient' object has no attribute 'number_insight'
cause The `vonage-number-insight` package is not installed, or the `vonage` SDK is an outdated version that doesn't correctly integrate the number insight methods.fixEnsure both `vonage` and `vonage-number-insight` packages are installed and up-to-date (`pip install --upgrade vonage vonage-number-insight`). The Number Insight API methods are accessed via `client.number_insight.<method_name>`. -
requests.exceptions.Timeout: The read operation timed out
cause Attempting a synchronous Advanced Number Insight request, which can exceed typical API timeouts due to extensive data processing.fixSwitch to asynchronous Advanced Number Insight requests by using `AdvancedAsyncInsightRequest` and providing a `callback` URL to receive the results.
Warnings
- breaking The Vonage Number Insight API, which this library integrates with, is being sunset on February 4, 2027. Users are strongly encouraged to migrate to the Vonage Identity Insights API for continued support and enhanced functionality.
- gotcha For Advanced Number Insight requests, Vonage strongly recommends using the asynchronous API via webhooks to avoid potential timeouts due to the comprehensive data retrieval. Synchronous Advanced Insight can be slow.
- gotcha Caller Name (CNAM) lookup is an optional feature for Standard and Advanced Number Insight and incurs an additional charge. It is only available for US numbers, and not all US numbers are supported.
- gotcha Phone numbers for insight requests should be in national or international format. If the number does not include a country code or its country is uncertain, you must provide a two-character ISO 3166-1 alpha-2 country code (e.g., 'GB' or 'US').
Install
-
pip install vonage-number-insight vonage
Imports
- Vonage
from vonage import Vonage
- BasicInsightRequest
from vonage.number_insight import BasicInsightRequest
from vonage_number_insight import BasicInsightRequest
- StandardInsightRequest
from vonage_number_insight import StandardInsightRequest
- AdvancedAsyncInsightRequest
from vonage_number_insight import AdvancedAsyncInsightRequest
Quickstart
import os
from vonage import Vonage
from vonage_number_insight import BasicInsightRequest
# Set environment variables: VONAGE_API_KEY, VONAGE_API_SECRET
API_KEY = os.environ.get('VONAGE_API_KEY', 'YOUR_API_KEY')
API_SECRET = os.environ.get('VONAGE_API_SECRET', 'YOUR_API_SECRET')
PHONE_NUMBER = '12345678900' # Replace with a valid phone number
if not API_KEY or not API_SECRET:
print("Error: VONAGE_API_KEY and VONAGE_API_SECRET environment variables must be set.")
else:
try:
client = Vonage(key=API_KEY, secret=API_SECRET)
# Make a Basic Number Insight Request
request = BasicInsightRequest(number=PHONE_NUMBER)
response = client.number_insight.basic_number_insight(request)
print(f"Basic Number Insight for {PHONE_NUMBER}:")
print(response.model_dump_json(indent=2, exclude_none=True))
except Exception as e:
print(f"An error occurred: {e}")