Azure Notification Hubs Management
Microsoft Azure Notification Hubs Management Client Library for Python, currently at version 8.0.0. This package provides programmatic access to manage Azure Notification Hubs resources, enabling operations like creating and configuring namespaces and notification hubs. It is part of the Azure SDK for Python, which typically follows a monthly or bi-monthly release cadence for updates and bug fixes, with major versions introducing breaking changes.
Warnings
- breaking Major breaking changes occurred in version 8.0.0, primarily affecting client instantiation and authentication. Old credential systems (`azure.common.credentials`, `msrestazure.azure_active_directory`) are no longer supported. The `credentials` parameter was renamed to `credential`, and client configuration is now passed as keyword arguments instead of through a `config` attribute.
- breaking The return type of `list_keys` in `NamespacesOperations` changed from `SharedAccessAuthorizationRuleListResult` to `ResourceListKeys` in version 8.0.0.
- deprecated Support for Python 2.7 for Azure SDK Python packages ended on January 1, 2022.
- gotcha All Azure management clients, including `NotificationHubsManagementClient`, require an authenticated credential. The recommended approach is to use `azure-identity` to obtain credentials, such as `DefaultAzureCredential`, which simplifies authentication across various Azure environments.
Install
-
pip install azure-mgmt-notificationhubs azure-identity
Imports
- NotificationHubsManagementClient
from azure.mgmt.notificationhubs import NotificationHubsManagementClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.notificationhubs import NotificationHubsManagementClient
# Set environment variables for authentication and subscription ID
# AZURE_SUBSCRIPTION_ID
# AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID (for Service Principal)
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "<your-subscription-id>")
credential = DefaultAzureCredential()
client = NotificationHubsManagementClient(credential, subscription_id)
print("Listing Notification Hub namespaces...")
for namespace in client.namespaces.list_all():
print(f"- Namespace: {namespace.name} (Location: {namespace.location})")
print("Quickstart complete.")