Azure Management Data Factory Client

9.3.0 · active · verified Thu Apr 09

The azure-mgmt-datafactory library is the official Microsoft Azure Data Factory management client for Python, providing programmatic access to create, configure, and manage Data Factory resources. It is part of the larger Azure SDK for Python ecosystem and is currently at version 9.3.0, with regular updates following the Azure SDK release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate using `DefaultAzureCredential` and initialize the `DataFactoryManagementClient`. It then performs a basic operation to list Data Factories within a specified resource group. Ensure `AZURE_SUBSCRIPTION_ID` and `AZURE_RESOURCE_GROUP` are set in your environment variables for successful execution.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.datafactory import DataFactoryManagementClient

# --- Authentication --- 
# Set environment variables for authentication:
# AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID (for Service Principal)
# or log in via Azure CLI: az login
# or use managed identity, etc.

# Retrieve subscription ID from environment variable
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "")
if not subscription_id:
    print("Please set the AZURE_SUBSCRIPTION_ID environment variable.")
    exit(1)

# Create a credential object using DefaultAzureCredential
# This attempts to authenticate via various methods (environment variables, managed identity, Azure CLI, etc.)
credential = DefaultAzureCredential()

# Create a DataFactoryManagementClient
data_factory_client = DataFactoryManagementClient(credential, subscription_id)

# --- Example Operation: List Data Factories in a Resource Group ---

resource_group_name = os.environ.get("AZURE_RESOURCE_GROUP", "") # Replace with your resource group or set env var

if not resource_group_name:
    print("Please set the AZURE_RESOURCE_GROUP environment variable or provide a default.")
    exit(1)

print(f"Listing data factories in resource group '{resource_group_name}':")
try:
    factories = data_factory_client.factories.list_by_resource_group(resource_group_name)
    found_factories = False
    for factory in factories:
        print(f"- Factory Name: {factory.name}, Location: {factory.location}")
        found_factories = True
    if not found_factories:
        print("No data factories found in this resource group.")
except Exception as e:
    print(f"Error listing data factories: {e}")
    print("Make sure the resource group exists and your credential has 'Contributor' or 'Data Factory Contributor' role.")

print("Quickstart complete.")

view raw JSON →