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
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file azure_iot_hub-2.0.0rc1-py2.py3-none-any.whl
.
File metadata
- Download URL: azure_iot_hub-2.0.0rc1-py2.py3-none-any.whl
- Upload date:
- Size: 71.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdc2f4c80b66b1536213f201d186966a24be0a2ba78819c4f738eb5a0472beab |
|
MD5 | 3c4dc6adc027966aaf88bffc6c6e3506 |
|
BLAKE2b-256 | 0a2fb627224985dfe3dddf00201f8ea2ed391f156a2665fa6763f177d35d61e2 |