Microsoft Azure Bot Service Client Library for Python
The azure-mgmt-botservice library provides the Python SDK for programmatically managing Azure Bot Service resources. It enables the creation, update, retrieval, and deletion of bots, channels, connections, SKUs, and properties. It utilizes the modern Azure SDK guidelines, including `azure-identity` for authentication. The current stable version is 2.0.0, and it follows the typical Azure SDK release cadence.
Warnings
- breaking The credential system has been completely revamped. Older authentication methods like `azure.common.credentials` or `msrestazure.azure_active_directory` are no longer supported. The `credentials` parameter on client constructors has been renamed to `credential`.
- breaking As part of the unified Azure SDK guidelines, operations that previously returned `msrest.polling.LROPoller` now return `azure.core.polling.LROPoller` and are typically prefixed with `begin_` (e.g., `create_bot` might become `begin_create_bot`).
- breaking The exception hierarchy has been simplified. Most exceptions now inherit from `azure.core.exceptions.HttpResponseError`. The older `CloudError` has been removed.
- deprecated Multi-tenant bot creation will be deprecated after July 31, 2025. This impacts how new bots configured for multi-tenancy can be registered or created using the Azure Bot Service.
- gotcha Python 2.7 support for Azure SDK Python packages ended on January 1, 2022. This library requires Python 3.7 or newer.
Install
-
pip install azure-mgmt-botservice azure-identity
Imports
- AzureBotService
from azure.mgmt.botservice import AzureBotService
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.botservice import AzureBotService
# Set environment variables or replace with your actual values
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET, AZURE_SUBSCRIPTION_ID
subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')
resource_group_name = os.environ.get('AZURE_RESOURCE_GROUP', 'YOUR_RESOURCE_GROUP_NAME')
bot_name = os.environ.get('AZURE_BOT_NAME', 'YOUR_BOT_NAME')
if subscription_id == 'YOUR_SUBSCRIPTION_ID' or resource_group_name == 'YOUR_RESOURCE_GROUP_NAME' or bot_name == 'YOUR_BOT_NAME':
raise ValueError("Please set AZURE_SUBSCRIPTION_ID, AZURE_RESOURCE_GROUP, and AZURE_BOT_NAME environment variables or replace placeholders.")
# Authenticate using DefaultAzureCredential
credential = DefaultAzureCredential()
# Create a Bot Service management client
client = AzureBotService(credential=credential, subscription_id=subscription_id)
# Example: List bots in a resource group
try:
print(f"Listing bots in resource group '{resource_group_name}':")
bots = client.bots.list_by_resource_group(resource_group_name)
for bot in bots:
print(f" Bot Name: {bot.name}, Location: {bot.location}")
except Exception as e:
print(f"Error listing bots: {e}")