Microsoft Azure Data Migration Client Library for Python

10.1.0 · active · verified Thu Apr 09

The `azure-mgmt-datamigration` library provides client-side functionality for interacting with the Azure Data Migration Service, allowing programmatic management of data migration tasks to Azure data platforms. It is part of the Azure SDK for Python, currently at version 10.1.0, and follows the modern Azure SDK guidelines, with regular updates and releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and list Data Migration Services within a specified resource group. Ensure you have the necessary environment variables (`AZURE_SUBSCRIPTION_ID`, `AZURE_RESOURCE_GROUP`) set for authentication and operation.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.datamigration import DataMigrationManagementClient

# Set your Azure Subscription ID as an environment variable or replace directly
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "<your-subscription-id>")

# Acquire a credential using DefaultAzureCredential. This will try various methods
# like environment variables (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET),
# Azure CLI, Managed Identity, etc.
credential = DefaultAzureCredential()

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

# Example: List all Data Migration Services in a resource group
resource_group_name = os.environ.get("AZURE_RESOURCE_GROUP", "<your-resource-group>")
print(f"Listing Data Migration Services in resource group: {resource_group_name}")

try:
    for service in client.services.list_by_resource_group(resource_group_name):
        print(f"  Service Name: {service.name}, Location: {service.location}")
except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure AZURE_SUBSCRIPTION_ID and AZURE_RESOURCE_GROUP are set,")
    print("and that your principal has 'Reader' permissions on the resource group.")

view raw JSON →