Azure Search Management Client Library

9.2.0 · active · verified Thu Apr 09

The `azure-mgmt-search` library provides a client for managing Azure AI Search (formerly Azure Cognitive Search) resources, including search services, private endpoint connections, and shared private link resources. It is part of the Azure SDK for Python, currently at version 9.2.0, and follows the Azure SDK's regular release cadence with updates typically released monthly or bi-monthly.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and list Azure AI Search services within your subscription and a specific resource group using `SearchManagementClient`. It assumes you have the necessary environment variables set for authentication or are logged in via Azure CLI/VS Code.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.search import SearchManagementClient

# Ensure these environment variables are set for DefaultAzureCredential
# AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID for service principal
# Or AZURE_SUBSCRIPTION_ID and logged in via Azure CLI/VS Code

subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "<your-subscription-id>")
resource_group_name = os.environ.get("AZURE_RESOURCE_GROUP_NAME", "<your-resource-group-name>")
search_service_name = os.environ.get("AZURE_SEARCH_SERVICE_NAME", "<your-search-service-name>")

if subscription_id == "<your-subscription-id>":
    print("Please set the AZURE_SUBSCRIPTION_ID environment variable.")
    exit(1)

# Authenticate using DefaultAzureCredential
credential = DefaultAzureCredential()

# Create a SearchManagementClient
client = SearchManagementClient(credential, subscription_id)

try:
    # Example 1: List all search services in the subscription
    print("\nListing all search services in subscription:")
    for service in client.services.list_by_subscription():
        print(f"  - {service.name} (Location: {service.location}, SKU: {service.sku.name})")

    # Example 2: List search services in a specific resource group
    if resource_group_name != "<your-resource-group-name>":
        print(f"\nListing search services in resource group '{resource_group_name}':")
        for service in client.services.list_by_resource_group(resource_group_name):
            print(f"  - {service.name} (Location: {service.location}, SKU: {service.sku.name})")
    else:
        print("\nTo list services by resource group, set AZURE_RESOURCE_GROUP_NAME.")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →