Azure IoT Hub Provisioning Services Management

1.1.0 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and list all IoT Hub Provisioning Services within a specified resource group. Ensure you have `AZURE_SUBSCRIPTION_ID` and `AZURE_RESOURCE_GROUP_NAME` set as environment variables. `DefaultAzureCredential` will automatically try to pick up credentials from your environment (e.g., Azure CLI, environment variables, Managed Identity).

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.")

view raw JSON →