Python 用 Azure Notification Hubs ライブラリ

管理 API

pip install azure-mgmt-notificationhubs

管理クライアントを作成する

管理クライアントのインスタンスは、以下のコードで作成します。

サブスクリプションの一覧から取得できる をsubscription_id指定する必要があります。

Python SDK を使用した Azure Active Directory の認証処理と Credentials インスタンスの作成について詳しくは、「Resource Management Authentication (リソース管理の認証)」を参照してください。

from azure.mgmt.notificationhubs import NotificationHubsManagementClient
from azure.common.credentials import UserPassCredentials

# Replace this with your subscription id
subscription_id = '33333333-3333-3333-3333-333333333333'

# See above for details on creating different types of AAD credentials
credentials = UserPassCredentials(
    'user@domain.com',	# Your user
    'my_password',		# Your password
)

redis_client = NotificationHubsManagementClient(
    credentials,
    subscription_id
)

名前空間を使用できるかどうかの確認

通知ハブの名前空間を使用できるかどうかは、次のコードで確認します。

from azure.mgmt.notificationhubs.models import CheckAvailabilityParameters

account_name = 'mynotificationhub'
output = notificationhubs_client.namespaces.check_availability(
    azure.mgmt.notificationhubs.models.CheckAvailabilityParameters(
        name = account_name
    )
)
# output is a CheckAvailibilityResource instance
print(output.is_availiable) # Yes, it's 'availiable', it's a typo in the REST API