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.
Common errors
-
ModuleNotFoundError: No module named 'azure.mgmt.signalr'
cause The `azure-mgmt-signalr` package is not installed in the current Python environment.fixRun `pip install azure-mgmt-signalr` to install the necessary library. -
The client 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' with object id 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' does not have authorization to perform action 'Microsoft.SignalRService/signalR/listKeys/action' over scope '/subscriptions/...' or the scope is invalid.
cause The authenticated identity (e.g., Managed Identity, Service Principal, or user) lacks the necessary Azure Role-Based Access Control (RBAC) permissions on the target Azure SignalR Service resource or its parent scope to perform the requested management operation.fixGrant the appropriate Azure RBAC role (e.g., 'SignalR Service Owner' or a custom role with specific permissions like `Microsoft.SignalRService/signalR/listKeys/action`) to the managed identity, service principal, or user on the SignalR resource. Allow some time for role assignments to propagate. -
AttributeError: 'SignalRManagementClient' object has no attribute 'some_deprecated_method' OR ModuleNotFoundError: No module named 'azure.mgmt.signalr.signalr_client'
cause This error often occurs when attempting to use deprecated classes or methods, or incorrect import paths due to API changes in newer versions of the `azure-mgmt-signalr` library. For example, `SignalRClient` can no longer be imported from `azure.mgmt.signalr.signalr_client`.fixEnsure you are using `from azure.mgmt.signalr import SignalRManagementClient` and accessing operations directly from the `SignalRManagementClient` instance (e.g., `client.signal_r.list_keys(...)`). Refer to the latest SDK documentation for current class names and method signatures. -
from azure.communication.identity import CommunicationIdentityClient; client = CommunicationIdentityClient.from_connection_string(conn_str); identity = client.create_user() # This results in a 403 Forbidden or similar error when trying to manage SignalR Service.
cause You are attempting to use the `azure-communication-identity` client, which is for Azure Communication Services, to perform management operations for Azure SignalR Service. These are distinct services with different SDKs.fixUse the `azure-mgmt-signalr` library for SignalR Service management tasks, specifically `SignalRManagementClient`. For example, to retrieve access keys, use `from azure.mgmt.signalr import SignalRManagementClient` and then `client.signal_r.list_keys(...)`.
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.signalr_client import SignalRClient
from azure.mgmt.signalr import SignalRManagementClient
- models
from azure.mgmt.signalr.models.my_model_class import MyModelClass
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}")