Registry /
azure / azure-mgmt-trafficmanager
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.578s · 43.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.8s · import 0.526s · 44MB
43MB installed
● package 43MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
TrafficManagerManagementClient
✓ from azure.mgmt.trafficmanager import TrafficManagerManagementClient
DefaultAzureCredential
✓ from azure.identity import DefaultAzureCredential
✗ from msrestazure.azure_active_directory import AADTokenCredentials
The `msrestazure` based credentials are for older SDK versions (Track 1). Modern Azure SDKs (Track 2) use `azure-identity`.
This quickstart demonstrates how to authenticate with `DefaultAzureCredential`, create a `TrafficManagerManagementClient`, list existing Traffic Manager profiles, and create a new basic profile. Ensure your environment variables for Azure authentication are set, or replace placeholders with actual values.
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.trafficmanager import TrafficManagerManagementClient
# --- Environment Variables (for local development) ---
# AZURE_SUBSCRIPTION_ID: Your Azure Subscription ID
# AZURE_CLIENT_ID: Your Azure AD Application (client) ID
# AZURE_CLIENT_SECRET: Your Azure AD Application client secret
# AZURE_TENANT_ID: Your Azure AD Tenant ID
subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')
resource_group_name = "my-traffic-manager-rg"
profile_name = "myuniquetmprofile123" # Must be globally unique
# Authenticate using DefaultAzureCredential
# This credential type tries various auth methods suitable for local dev and production
credential = DefaultAzureCredential()
# Create a TrafficManagerManagementClient
traffic_manager_client = TrafficManagerManagementClient(credential, subscription_id)
print(f"Listing Traffic Manager profiles in subscription {subscription_id}:")
for profile in traffic_manager_client.profiles.list_by_subscription():
print(f"- {profile.name} (Status: {profile.profile_status})")
# Example: Create a simple Traffic Manager profile
# Note: This is a basic example, a real profile would need endpoints
location = "global" # Traffic Manager is a global service
profile_parameters = {
"location": location,
"profile_status": "Enabled",
"traffic_routing_method": "Performance",
"dns_config": {
"relative_name": profile_name, # This forms the globally unique FQDN: <relative_name>.trafficmanager.net
"ttl": 300
},
"monitor_config": {
"protocol": "HTTP",
"port": 80,
"path": "/"
}
}
print(f"\nAttempting to create/update Traffic Manager profile '{profile_name}'...")
poller = traffic_manager_client.profiles.begin_create_or_update(
resource_group_name,
profile_name,
profile_parameters
)
profile_result = poller.result()
print(f"Profile '{profile_result.name}' created/updated successfully.")
print(f"FQDN: {profile_result.dns_config.fqdn}")
Debug
Known issues
breakingOlder Azure Management SDKs (often referred to as Track 1) used `msrestazure.azure_active_directory.AADTokenCredentials` for authentication. Modern Azure SDKs (Track 2, including this library) exclusively use `azure-identity` library for authentication, such as `DefaultAzureCredential`.fixMigrate your authentication code to use classes from `azure.identity`, like `DefaultAzureCredential`. See Azure Identity documentation for more details.
affects: <1.0.0 (Track 1 libraries) vs. >=1.0.0 (Track 2 libraries)
gotchaTraffic Manager profile names (`dns_config.relative_name`) must be globally unique across all of Azure, not just within your subscription or resource group. If the name is already taken, creation will fail.fixChoose a highly unique name for your Traffic Manager profile, often by incorporating a random string or GUID, to ensure global uniqueness.
affects: All versions
gotchaWhen creating or updating a Traffic Manager profile, the `location` property must always be set to 'global'. Traffic Manager is a global service and does not reside in a specific Azure region.fixEnsure `profile_parameters['location'] = 'global'` when defining your profile configuration.
affects: All versions
deprecatedOlder methods for working with management clients might be replaced by new patterns (e.g., direct property access vs. `get_` methods). Always refer to the latest SDK documentation and samples for the current idiomatic usage.fixConsult the official Azure SDK for Python documentation and samples on GitHub to ensure you are using the most up-to-date and recommended patterns for client interaction and resource management.
affects: Prior major versions
breakingThe `DefaultAzureCredential` failed to acquire a token because no valid credentials (e.g., environment variables, Azure CLI login, Managed Identity) were found or configured in the execution environment. This is a common issue when running applications that depend on `azure-identity`.fixEnsure your environment is correctly configured for `DefaultAzureCredential`. This typically involves setting `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET` (for service principals), or running `az login` (for developer workstations), or ensuring Managed Identity is enabled and assigned correctly in Azure environments. Refer to the Azure Identity documentation for detailed troubleshooting: https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.
affects: All versions using `azure-identity` (Track 2 SDKs)
breakingDefaultAzureCredential failed to authenticate because none of its underlying credential types (e.g., EnvironmentCredential, AzureCliCredential, ManagedIdentityCredential) could successfully retrieve a token. This often indicates missing environment variables, an unauthenticated Azure CLI, or an unavailable managed identity.fixEnsure your environment is correctly configured for one of the `DefaultAzureCredential`'s underlying credentials. This might involve setting `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET` environment variables, logging in via Azure CLI (`az login`), or running the application in an environment with an assigned managed identity. Consult the `azure-identity` documentation for detailed troubleshooting.
affects: All versions using `azure-identity`
Upgrade
Version history
1.1.0latest on PyPI · released Jun 21, 2023
Audit
Dependencies
azure-identityrequiredRequired for authentication with Azure services.
azure-mgmt-corerequiredCore functionalities for Azure management plane clients.