Skip to main content

Microsoft Azure IoTHub Service Library

Project description

Azure IoTHub Service SDK

The Azure IoTHub Service SDK for Python provides functionality for communicating with the Azure IoT Hub.

Note that this SDK is currently in preview, and is subject to change.

Features

The SDK provides the following clients:

  • IoT Hub Registry Manager

    • Provides CRUD operations for device on IoTHub
    • Get statistics about the IoTHub service and devices
  • Digital Twin Service Client

    • Read and update Digital Twin
    • Read Digital Twin Interface Instances
    • Read Model

These clients are available with an asynchronous API, as well as a blocking synchronous API for compatibility scenarios. We recommend you use Python 3.7+ and the asynchronous API.

Python Version Synchronous API
Python 3.5.3+ YES
Python 3.4 YES
Python 2.7 YES

Installation

pip install azure-iot-hub

Set up an IoT Hub

  1. Install the Azure CLI (or use the Azure Cloud Shell) and use it to create an Azure IoT Hub.
az iot hub create --resource-group <your resource group> --name <your IoT Hub name>
  • Note that this operation make take a few minutes.

How to use the IoTHub Registry Manager

  • Create an IoTHubRegistryManager

registry_manager = IoTHubRegistryManager(iothub_connection_str)
  • Create a device

new_device = registry_manager.create_device_with_sas(device_id, primary_key, secondary_key, device_state)
  • Read device information

device = registry_manager.get_device(device_id)
  • Update device information

device_updated = registry_manager.update_device_with_sas(
    device_id, etag, primary_key, secondary_key, device_state)
  • Delete device

registry_manager.delete_device(device_id)
  • Get service statistics

registry_statistics = registry_manager.get_service_statistics()
  • Get device registry statistics

registry_statistics = registry_manager.get_device_registry_statistics()

How to use the Digital Twin Service Client

  • Create an DigitalTwinServiceClient

digital_twin_service_client = DigitalTwinServiceClient(iothub_connection_str)
  • Get DigitalTwin of a particular device

digital_twin = digital_twin_service_client.get_digital_twin(device_id)
  • Get a DigitalTwin Interface Instance

digital_twin_interface_instance = digital_twin_service_client.get_digital_twin_interface_instance(
    device_id, interface_instance_name
)
  • Update DigitalTwin with a patch

digital_twin_updated = digital_twin_service_client.update_digital_twin(device_id, patch, etag)
  • Update a DigitalTwin property by name

digital_twin_service_client.update_digital_twin_property(
    device_id, interface_instance_name, property_name, property_value
)
  • Get a Model

digital_twin_model = digital_twin_service_client.get_model(model_id)

IoTHub Samples

Check out the samples repository for more detailed samples

Getting help and finding API docs

Our SDK makes use of docstrings which means you can find API documentation directly through Python with use of the help command:

>>> from azure.iot.hub import IoTHubRegistryManager
>>> help(IoTHubRegistryManager)

>>> from azure.iot.hub import DigitalTwinServiceClient
>>> help(DigitalTwinServiceClient)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

azure_iot_hub-2.0.0rc1-py2.py3-none-any.whl (71.1 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page