Azure IoT Central Management

9.0.0 · active · verified Thu Apr 09

The `azure-mgmt-iotcentral` library is the Microsoft Azure IoT Central Management Client Library for Python, enabling programmatic control and management of IoT Central applications. It is part of the Azure SDK for Python (Track 2 design) and currently at version 9.0.0. Azure SDK libraries follow a consistent release cadence, with updates often coinciding with new Azure service features or bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with `DefaultAzureCredential`, create an `IotCentralManagementClient`, and then list all IoT Central applications within your Azure subscription. It also includes an example of retrieving a specific application by name and resource group.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.iotcentral import IotCentralManagementClient

# Retrieve your subscription ID from an environment variable or replace with your actual ID
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "")
if not subscription_id:
    raise ValueError("AZURE_SUBSCRIPTION_ID environment variable not set.")

# Authenticate using DefaultAzureCredential.
# This credential will attempt to authenticate in several ways, including
# environment variables, managed identity, Azure CLI, and Visual Studio Code.
credential = DefaultAzureCredential()

# Create an IoT Central Management client
client = IotCentralManagementClient(credential, subscription_id)

# List all IoT Central applications in the subscription
print("Listing all IoT Central applications in the subscription:")
for app in client.apps.list_by_subscription():
    print(f"- App Name: {app.display_name or app.name}, Location: {app.location}, SKU: {app.sku.name}")

# Example: Get an existing IoT Central application by name within a resource group
# Replace with an actual app name and resource group you have, or set via environment variables
resource_group_name = os.environ.get("AZURE_RESOURCE_GROUP", "my-resource-group")
iot_central_app_name = os.environ.get("AZURE_IOTCENTRAL_APP_NAME", "my-iotc-app")

if resource_group_name and iot_central_app_name:
    try:
        print(f"\nAttempting to get app '{iot_central_app_name}' in resource group '{resource_group_name}':")
        app_details = client.apps.get(resource_group_name, iot_central_app_name)
        print(f"Found app: {app_details.display_name or app_details.name}, SKU: {app_details.sku.name}, ID: {app_details.id}")
    except Exception as e:
        print(f"Could not retrieve app {iot_central_app_name} (might not exist, permission issue, or incorrect RG/name): {e}")
else:
    print("\nSkipping 'Get app' example: AZURE_RESOURCE_GROUP or AZURE_IOTCENTRAL_APP_NAME not set.")

view raw JSON →