Microsoft Azure Traffic Manager Management Client Library for Python
npx @tessl/cli install tessl/pypi-azure-mgmt-trafficmanager@1.1.0A comprehensive Python client library for managing Azure Traffic Manager services through the Azure Resource Manager API. This library enables developers to programmatically create, configure, and manage Traffic Manager profiles, endpoints, and geographic hierarchies for load balancing and traffic routing across Azure regions.
pip install azure-mgmt-trafficmanagerfrom azure.mgmt.trafficmanager import TrafficManagerManagementClient
from azure.identity import DefaultAzureCredential
from azure.core.credentials import TokenCredentialFor async operations:
from azure.mgmt.trafficmanager.aio import TrafficManagerManagementClient
from azure.identity.aio import DefaultAzureCredentialFor models and enums:
from azure.mgmt.trafficmanager.models import (
Profile, Endpoint, DnsConfig, MonitorConfig,
TrafficRoutingMethod, EndpointType, ProfileStatus
)from azure.mgmt.trafficmanager import TrafficManagerManagementClient
from azure.identity import DefaultAzureCredential
# Initialize client
credential = DefaultAzureCredential()
subscription_id = "your-subscription-id"
client = TrafficManagerManagementClient(credential, subscription_id)
# Create a basic Traffic Manager profile
profile = client.profiles.create_or_update(
resource_group_name="my-rg",
profile_name="my-profile",
parameters={
"location": "global",
"tags": {"environment": "production"},
"profile_status": "Enabled",
"traffic_routing_method": "Performance",
"dns_config": {
"relative_name": "my-app-tm",
"ttl": 60
},
"monitor_config": {
"protocol": "HTTPS",
"port": 443,
"path": "/health",
"interval_in_seconds": 30,
"timeout_in_seconds": 10,
"tolerated_number_of_failures": 3
}
}
)
# Add an Azure endpoint
endpoint = client.endpoints.create_or_update(
resource_group_name="my-rg",
profile_name="my-profile",
endpoint_type="AzureEndpoints",
endpoint_name="my-endpoint",
parameters={
"target_resource_id": "/subscriptions/.../resourceGroups/.../providers/Microsoft.Web/sites/my-app",
"endpoint_status": "Enabled",
"weight": 100,
"priority": 1
}
)
print(f"Profile FQDN: {profile.dns_config.fqdn}")The Azure Traffic Manager Management Client follows Azure SDK patterns and provides:
profiles: Traffic Manager profile managementendpoints: Traffic Manager endpoint managementgeographic_hierarchies: Geographic routing configurationheat_map: Performance analytics and heat mapstraffic_manager_user_metrics_keys: Real user metrics configurationPrimary client class for managing all Traffic Manager resources with Azure authentication and subscription-based operations.
class TrafficManagerManagementClient:
def __init__(
self,
credential: TokenCredential,
subscription_id: str,
base_url: str = "https://management.azure.com",
**kwargs
): ...
def close(self) -> None: ...
def __enter__(self) -> "TrafficManagerManagementClient": ...
def __exit__(self, *exc_details) -> None: ...Complete lifecycle management of Traffic Manager profiles including creation, configuration, updating, deletion, and listing operations.
def create_or_update(
resource_group_name: str,
profile_name: str,
parameters: Profile
) -> Profile: ...
def get(resource_group_name: str, profile_name: str) -> Profile: ...
def update(resource_group_name: str, profile_name: str, parameters: Profile) -> Profile: ...
def delete(resource_group_name: str, profile_name: str) -> Optional[DeleteOperationResult]: ...
def list_by_resource_group(resource_group_name: str) -> Iterable[Profile]: ...
def list_by_subscription() -> Iterable[Profile]: ...Management of Traffic Manager endpoints including Azure endpoints, external endpoints, and nested endpoints with full CRUD operations.
def create_or_update(
resource_group_name: str,
profile_name: str,
endpoint_type: Union[str, EndpointType],
endpoint_name: str,
parameters: Endpoint
) -> Endpoint: ...
def get(
resource_group_name: str,
profile_name: str,
endpoint_type: Union[str, EndpointType],
endpoint_name: str
) -> Endpoint: ...Traffic analytics through heat maps, health monitoring configuration, and real user metrics for performance optimization.
def get(
resource_group_name: str,
profile_name: str,
top_left: Optional[List[float]] = None,
bot_right: Optional[List[float]] = None
) -> HeatMapModel: ...
def create_or_update() -> UserMetricsModel: ...
def get() -> UserMetricsModel: ...
def delete() -> DeleteOperationResult: ...Geographic hierarchy management for geographic-based traffic routing including region codes and hierarchical geographic mappings.
def get_default_geographic_hierarchy() -> TrafficManagerGeographicHierarchy: ...class Profile:
"""Traffic Manager profile configuration."""
profile_status: ProfileStatus
traffic_routing_method: TrafficRoutingMethod
dns_config: DnsConfig
monitor_config: MonitorConfig
endpoints: List[Endpoint]
traffic_view_enrollment_status: TrafficViewEnrollmentStatus
allowed_endpoint_record_types: List[AllowedEndpointRecordType]
max_return: int
class Endpoint:
"""Traffic Manager endpoint configuration."""
target_resource_id: str
target: str
endpoint_status: EndpointStatus
weight: int
priority: int
endpoint_location: str
endpoint_monitor_status: EndpointMonitorStatus
min_child_endpoints: int
geo_mapping: List[str]
subnets: List[EndpointPropertiesSubnetsItem]
custom_headers: List[EndpointPropertiesCustomHeadersItem]
class DnsConfig:
"""DNS configuration for Traffic Manager profiles."""
relative_name: str
fqdn: str # read-only
ttl: int
class MonitorConfig:
"""Health monitoring configuration."""
profile_monitor_status: ProfileMonitorStatus
protocol: MonitorProtocol
port: int
path: str
interval_in_seconds: int
timeout_in_seconds: int
tolerated_number_of_failures: int
custom_headers: List[MonitorConfigCustomHeadersItem]
expected_status_code_ranges: List[MonitorConfigExpectedStatusCodeRangesItem]class TrafficRoutingMethod(str, Enum):
PERFORMANCE = "Performance"
PRIORITY = "Priority"
WEIGHTED = "Weighted"
GEOGRAPHIC = "Geographic"
MULTI_VALUE = "MultiValue"
SUBNET = "Subnet"
class EndpointType(str, Enum):
AZURE_ENDPOINTS = "AzureEndpoints"
EXTERNAL_ENDPOINTS = "ExternalEndpoints"
NESTED_ENDPOINTS = "NestedEndpoints"
class ProfileStatus(str, Enum):
ENABLED = "Enabled"
DISABLED = "Disabled"
class EndpointStatus(str, Enum):
ENABLED = "Enabled"
DISABLED = "Disabled"
class MonitorProtocol(str, Enum):
HTTP = "HTTP"
HTTPS = "HTTPS"
TCP = "TCP"
class AlwaysServe(str, Enum):
ENABLED = "Enabled"
DISABLED = "Disabled"