Bandwidth SDK

raw JSON →
23.1.0 verified Fri May 01 auth: no python

Official Python SDK for Bandwidth's Communication Platform APIs (Voice, Messaging, Multi-Factor Auth). Version 23.1.0 supports Python >=3.7. Monthly releases.

pip install bandwidth-sdk
error ModuleNotFoundError: No module named 'bandwidth_sdk'
cause Attempting to import the package by its PyPI name.
fix
Use 'from bandwidth import Client'.
error TypeError: __init__() missing 1 required positional argument: 'account_id'
cause Missing account_id argument when creating Client.
fix
Include account_id: Client(username='...', password='...', account_id='...')
error bandwidth.api.exceptions.ApiException: (403) Forbidden
cause Invalid credentials or insufficient permissions.
fix
Check BW_USERNAME, BW_PASSWORD, and BW_ACCOUNT_ID environment variables.
breaking The SDK uses 'bandwidth' as the import package, not 'bandwidth_sdk'. Using 'bandwidth_sdk' will cause ModuleNotFoundError.
fix Use 'from bandwidth import Client' instead of 'import bandwidth_sdk'.
gotcha Account ID is required in the client constructor; omitting it will raise a TypeError.
fix Provide account_id as the third argument to Client.
deprecated The method 'Client.create_message' is deprecated; use 'Client.send_message' instead.
fix Replace client.create_message(...) with client.send_message(...).

Initialize client with environment variables and fetch account info.

from bandwidth import Client

client = Client(
    username=os.environ.get('BW_USERNAME', ''),
    password=os.environ.get('BW_PASSWORD', ''),
    account_id=os.environ.get('BW_ACCOUNT_ID', '')
)
try:
    info = client.get_account()
    print(info)
except Exception as e:
    print(f'Error: {e}')