Azure Management Relay Client Library
The `azure-mgmt-relay` library is the Microsoft Azure Relay Client Library for Python. It enables programmatic management of Azure Relay resources, such as namespaces, hybrid connections, and WCF relays, through Azure Resource Manager (ARM). The library is currently at stable version 1.1.0, released in September 2021. A 2.0.0b1 beta version was released in November 2022, but no stable release has followed since 1.1.0.
Warnings
- breaking The credential system underwent a complete revamp in `azure-mgmt-relay` 1.0.0b1. Old `azure.common.credentials` or `msrestazure.azure_active_directory` instances are no longer supported. The `credentials` parameter was also renamed to `credential`.
- breaking The `config` attribute on client objects has been removed starting from `azure-mgmt-relay` 1.0.0b1. All configuration options should now be passed as keyword arguments during client instantiation.
- breaking For long-running operations (LROs), methods that previously returned `msrest.polling.LROPoller` now return `azure.core.polling.LROPoller` and are prefixed with `begin_` (e.g., `create` became `begin_create`).
- breaking Model signatures now exclusively use keyword-argument syntax. Any positional arguments previously used for model creation or method calls must be rewritten as keyword arguments.
- gotcha A `ModuleNotFoundError: No module named 'azure.mgmt.relay'` can occur if the package is not correctly installed, if the Python environment is not activated, or if there are conflicts with other Azure CLI or SDK installations.
Install
-
pip install azure-mgmt-relay -
pip install --pre azure-mgmt-relay
Imports
- RelayManagementClient
from azure.mgmt.relay import RelayManagementClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
- ServicePrincipalCredentials (deprecated)
from azure.identity import ClientSecretCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.relay import RelayManagementClient
# Retrieve subscription ID from environment variable
# Ensure AZURE_SUBSCRIPTION_ID is set in your environment
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "")
if not subscription_id:
raise ValueError("AZURE_SUBSCRIPTION_ID environment variable not set.")
# Authenticate using DefaultAzureCredential
# This credential will attempt to authenticate in various environments:
# environment variables, managed identity, VS Code, Azure CLI, etc.
credential = DefaultAzureCredential()
# Create a RelayManagementClient
client = RelayManagementClient(credential, subscription_id)
print("Listing all Relay namespaces in the subscription...")
try:
for namespace in client.namespaces.list():
print(f"- {namespace.name}")
print("\nSuccessfully listed Relay namespaces.")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure your Azure credentials and subscription ID are correctly configured and you have the necessary permissions.")