Skip to main content

Azure iot hub api with azure cli backend

Project description

azure-iot-hub-api

Azure IoT hub api interface using azure cli

This package is alternative to azure-iot-hub which hasn't had any updates in several years and relays on the deprecated azure-uamqp-python.

This package can be used as a stopgap until the azure-iot-hub been updated to no longer depend on deprecated packages.

Currently these very basic functionalities of the IoTHubRegistryManager are supported:

  • create_device_with_sas
  • get_twin
  • get_twins
  • update_twin
  • get_device
  • get_devices
  • delete_device

The package are designed, so that, if it is used as alternative to existing azure-iot-hub in the project, it need to make only little changes to the codebase.

Usage

Simply import and create IoTHubRegistryManager using connection string, then you can call api functions.

Sample code

from azure_iot_hub_api import IoTHubRegistryManager

AZURE_IOT_CONNECTION_STRING = "HostName=MyAzureIotHub.azure-devices.net;SharedAccessKeyName=xxx;SharedAccessKey=xxxxxxxxxxxxxx"
registry_manager = IoTHubRegistryManager(AZURE_IOT_CONNECTION_STRING)
my_device_id = 'E-11'
primary_key = 'primary-base64-key'
secondary_key = 'secondary-base64-key'

# Create a device
registry_manager.create_device_with_sas(
        device_id=my_device_id,
        primary_key=primary_key,
        secondary_key=secondary_key,
        status='enabled',
    )

# Get device twin
my_device_twin = registry_manager.get_twin(device_id=my_device_id)
my_device_twin.properties.desired['speed'] = 70

# Update device twin (It updates only desired object)
registry_manager.update_twin(device_id=my_device_id, twin=my_device_twin)

Project details


Download files

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

Source Distribution

azure_iot_hub_api-0.2.0.tar.gz (9.1 kB view hashes)

Uploaded Source

Built Distribution

azure_iot_hub_api-0.2.0-py3-none-any.whl (9.8 kB view hashes)

Uploaded 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