Azure IoT Hub Provisioning Services Management
The Microsoft Azure IoT Hub Provisioning Services Client Library for Python (`azure-mgmt-iothubprovisioningservices`) provides management capabilities for IoT Hub Device Provisioning Service (DPS) resources within Azure. It allows developers to programmatically create, configure, and manage DPS instances, enrollments, and linked IoT hubs. The current stable version is 1.1.0, and it is part of the actively maintained Azure SDK for Python, which follows a regular release cadence with updates and bug fixes.
Warnings
- breaking The credential system was completely revamped in beta versions leading up to 1.0.0. `azure.common.credentials` or `msrestazure.azure_active_directory` instances are no longer supported. The `credentials` parameter was renamed to `credential`.
- breaking The `config` attribute no longer exists directly on the client object for passing configuration. Client configuration should now be passed as keyword arguments during client instantiation.
- breaking Long-running operations (LROs) that previously returned `msrest.polling.LROPoller` now return `azure.core.polling.LROPoller` and are prefixed with `begin_`.
- gotcha Incorrect or missing environment variables are a common cause of authentication failures when using `DefaultAzureCredential`. This credential type relies on specific environment variables (e.g., `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_SUBSCRIPTION_ID`) to locate credentials.
- deprecated Python 2.7 support for Azure SDK Python packages ended on January 1, 2022. While older versions might have been compatible, newer versions are designed for Python 3.6+.
Install
-
pip install azure-mgmt-iothubprovisioningservices azure-identity
Imports
- IotDpsClient
from azure.mgmt.iothubprovisioningservices import IotDpsClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.iothubprovisioningservices import IotDpsClient
# Set your Azure Subscription ID and Resource Group name as environment variables
# export AZURE_SUBSCRIPTION_ID="<your-subscription-id>"
# export AZURE_RESOURCE_GROUP_NAME="<your-resource-group-name>"
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "").strip()
resource_group_name = os.environ.get("AZURE_RESOURCE_GROUP_NAME", "").strip()
if not subscription_id or not resource_group_name:
raise ValueError("Please set AZURE_SUBSCRIPTION_ID and AZURE_RESOURCE_GROUP_NAME environment variables.")
# Authenticate with Azure. DefaultAzureCredential attempts several credential types.
credential = DefaultAzureCredential()
# Create an IoT Hub Provisioning Services client
client = IotDpsClient(credential, subscription_id)
print(f"Listing all IoT Hub Provisioning Services in resource group '{resource_group_name}'...")
# List provisioning services in a specific resource group
for dps in client.iot_dps_resource.list_by_resource_group(resource_group_name):
print(f" - {dps.name} (Location: {dps.location}, Sku: {dps.sku.name})")
print("Done.")