Azure SignalR Management Client Library for Python
The `azure-mgmt-signalr` library is the Microsoft Azure SignalR Client Library for Python, enabling programmatic management of Azure SignalR Service resources. It supports operations like creating, updating, deleting, and listing SignalR instances. The current stable version is 1.2.0, released in March 2023. This library is part of the broader Azure SDK for Python, which generally follows a consistent release cadence with frequent updates across its various service-specific packages.
Warnings
- breaking The credential system was completely revamped starting from version 1.0.0b1. Older `azure.common.credentials` or `msrestazure.azure_active_directory` instances are no longer supported for authentication. The `credentials` parameter on client constructors was renamed to `credential`.
- breaking Between earlier preview versions and 1.2.0, a new code generator might have introduced breaking changes related to module visibility and import paths. Specifically, `SignalRClient` was renamed to `SignalRManagementClient` and its direct import from `azure.mgmt.signalr.signalr_client` is incorrect; it should now be imported from `azure.mgmt.signalr`. Similarly, direct imports of models from `azure.mgmt.signalr.models.my_class` are no longer supported; instead, import from the `azure.mgmt.signalr.models` module.
- gotcha This package, like other modern Azure SDK for Python libraries, officially supports Python 3.7 and later. Support for Python 2.7 ended on January 1, 2022. Using it with unsupported Python versions may lead to unexpected behavior or installation issues.
- gotcha Authentication using `DefaultAzureCredential` relies on specific environment variables for service principal or client secret authentication. Without these configured, the credential chain might fail. Required variables include `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`, and `AZURE_SUBSCRIPTION_ID`.
Install
-
pip install azure-mgmt-signalr azure-identity
Imports
- SignalRManagementClient
from azure.mgmt.signalr import SignalRManagementClient
- models
from azure.mgmt.signalr import models
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.signalr import SignalRManagementClient
# Set environment variables for authentication and subscription ID
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
# AZURE_SUBSCRIPTION_ID
subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'your_subscription_id')
if subscription_id == 'your_subscription_id':
print("Please set the AZURE_SUBSCRIPTION_ID environment variable.")
exit(1)
try:
# Authenticate using DefaultAzureCredential
# This credential will attempt to authenticate via environment variables, managed identity, or Azure CLI.
credential = DefaultAzureCredential()
# Create a SignalRManagementClient
signalr_client = SignalRManagementClient(credential, subscription_id)
print(f"Listing SignalR resources in subscription: {subscription_id}")
# List all SignalR services in the subscription
for resource in signalr_client.signal_r.list_by_subscription():
print(f" - SignalR Resource: {resource.name}, Location: {resource.location}")
except Exception as e:
print(f"An error occurred: {e}")