Vonage Numbers

1.0.5 · active · verified Thu Apr 16

The `vonage-numbers` library provides a dedicated Python client for interacting with the Vonage Numbers API. It allows developers to programmatically manage their Vonage phone numbers, including searching, buying, updating, and canceling them. It is built on top of the `vonage-python` SDK and is currently at version 1.0.5, with updates tied to the underlying Vonage API and SDK changes.

Common errors

Warnings

Install

Imports

Quickstart

Initialize the core `vonage.Client` with API credentials, then use it to instantiate the `vonage_numbers.Numbers` client to perform operations like fetching all owned numbers. Ensure `VONAGE_API_KEY` and `VONAGE_API_SECRET` environment variables are set.

import vonage
from vonage_numbers import Numbers
import os

VONAGE_API_KEY = os.environ.get("VONAGE_API_KEY", "YOUR_API_KEY")
VONAGE_API_SECRET = os.environ.get("VONAGE_API_SECRET", "YOUR_API_SECRET")

if VONAGE_API_KEY == "YOUR_API_KEY" or VONAGE_API_SECRET == "YOUR_API_SECRET":
    print("Please set VONAGE_API_KEY and VONAGE_API_SECRET environment variables or replace placeholders.")
else:
    try:
        # Initialize Vonage client
        client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)

        # Initialize Numbers client
        numbers_client = Numbers(client)

        # Example: get all numbers
        print("Fetching all Vonage numbers...")
        all_numbers = numbers_client.get_all_numbers()
        if all_numbers and all_numbers.get('numbers'):
            print(f"Successfully retrieved {len(all_numbers['numbers'])} numbers.")
            for number_data in all_numbers['numbers'][:2]: # Print first 2 for brevity
                print(f"- Number: {number_data.get('msisdn')}, Country: {number_data.get('country')}")
        else:
            print("No numbers found or response was empty.")

    except vonage.exceptions.VonageClientException as e:
        print(f"Vonage API Error: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →