Azure Management Relay Client Library

1.1.0 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and list all Azure Relay namespaces within a specified subscription. Ensure you have the `AZURE_SUBSCRIPTION_ID` environment variable set and appropriate permissions in Azure for `DefaultAzureCredential` to function.

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.")

view raw JSON →