Azure Management Data Factory Client
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
- breaking Major breaking changes occurred between versions 8.x and 9.x. The client constructor signatures changed, authentication now primarily uses `azure.identity` credentials, and `msrestazure` specific patterns are largely replaced. Migration to `azure.identity.DefaultAzureCredential` is mandatory.
- breaking Version 9.0.0 and above of `azure-mgmt-datafactory` require Python 3.9 or higher. Installations on older Python versions will fail due to `Requires-Python` metadata.
- gotcha Authentication issues are common. `DefaultAzureCredential` attempts various authentication methods (environment variables, managed identity, Azure CLI, etc.). Incorrect setup will lead to `CredentialUnavailableError` or permission errors.
- gotcha Many management operations require the Azure Resource Group name and other resource-specific names (e.g., factory name, pipeline name) as direct parameters. Forgetting or mistyping these can lead to `ResourceNotFound` or `404` errors, even with correct authentication.
Install
-
pip install azure-mgmt-datafactory azure-identity
Imports
- DataFactoryManagementClient
from azure.mgmt.datafactory import DataFactoryManagementClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
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.")