V2 - We are now GA!

This repository contains code for the Azure IoT SDKs for Python. This enables python developers to easily create IoT device solutions that seamlessly connect to the Azure IoT Hub ecosystem.

If you're looking for the v1.x.x client library, it is now preserved in the v1-deprecated branch.

Azure IoT SDK for Python

This repository contains the following libraries:

Azure IoT Device library.

Azure IoT Hub Service library

Coming Soon: Azure IoT Device Provisioning Service Library

Critical Upcoming Change Notice

All Azure IoT SDK users are advised to be aware of upcoming TLS certificate changes for Azure IoT Hub and Device Provisioning Service
that will impact the SDK's ability to connect to these services. In October 2022, both services will migrate from the current
Baltimore CyberTrust CA Root to the
DigiCert Global G2 CA root. There will be a
transition period beforehand where your IoT devices must have both the Baltimore and Digicert public certificates
installed in their certificate store in order to prevent connectivity issues.

Devices with only the Baltimore public certificate installed will lose the ability to connect to Azure IoT hub and Device Provisioning Service in October 2022.

To prepare for this change, make sure your device's certificate store has both of these public certificates installed.

For a more in depth explanation as to why the IoT services are doing this, please see
this article.

Installing the libraries

Pip installs are provided for all of the SDK libraries in this repo:

Device libraries

IoTHub library

Using the libraries

Want to start off on the right foot? Be sure to learn about common pitfalls of using this Python SDK before starting a project.

You can also view samples in each library:

Features

:heavy_check_mark: feature available  :heavy_multiplication_x: feature planned but not yet supported  :heavy_minus_sign: no support planned*

*Features that are not planned may be prioritized in a future release, but are not currently planned

This SDK only supports the MQTT protocol.

Device Client Library (azure-iot-device)

IoTHub Device Client

Features Status Description
Authentication :heavy_check_mark: Connect your device to IoT Hub securely with supported authentication, including symmetric key, X-509 Self Signed, Certificate Authority (CA) Signed, and SASToken
Send device-to-cloud message :heavy_check_mark: Send device-to-cloud messages (max 256KB) to IoT Hub with the option to add custom properties.
Receive cloud-to-device messages :heavy_check_mark: Receive cloud-to-device messages and read associated custom and system properties from IoT Hub, with the option to complete/reject/abandon C2D messages.
Device Twins :heavy_check_mark: IoT Hub persists a device twin for each device that you connect to IoT Hub. The device can perform operations like get twin tags, subscribe to desired properties.
Direct Methods :heavy_check_mark: IoT Hub gives you the ability to invoke direct methods on devices from the cloud. The SDK supports handler for method specific and generic operation.
Connection Status and Error reporting :heavy_multiplication_x: Error reporting for IoT Hub supported error code. *This SDK supports error reporting on authentication and Device Not Found.
Retry policies :heavy_check_mark: Operations which fail with a transient error and dropped connections will be retried with a fixed 10 second interval by default. This functionality can be disabled if desired, and the interval can be configured
Upload file to Blob :heavy_check_mark: A device can initiate a file upload and notifies IoT Hub when the upload is complete.

IoTHub Module Client

Note: IoT Edge for Python is scoped to Linux containers & devices only. Learn more about using Linux containers for IoT edge on Windows devices.

Features Status Description
Authentication :heavy_check_mark: Connect your device to IoT Hub securely with supported authentication, including symmetric key, X-509 Self Signed, and Certificate Authority (CA) Signed. SASToken authentication is not currently supported.
Send device-to-cloud message :heavy_check_mark: Send device-to-cloud messages (max 256KB) to IoT Hub with the option to add custom properties.
Receive cloud-to-device messages :heavy_check_mark: Receive cloud-to-device messages and read associated custom and system properties from IoT Hub, with the option to complete/reject/abandon C2D messages.
Device Twins :heavy_check_mark: IoT Hub persists a device twin for each device that you connect to IoT Hub. The device can perform operations like get twin tags, subscribe to desired properties.
Direct Methods :heavy_check_mark: IoT Hub gives you the ability to invoke direct methods on devices from the cloud. The SDK supports handler for method specific and generic operation.
Connection Status and Error reporting :heavy_multiplication_x: Error reporting for IoT Hub supported error code. *This SDK supports error reporting on authentication and Device Not Found.
Retry policies :heavy_check_mark: Operations which fail with a transient error and dropped connections will be retried with a fixed 10 second interval. TThis functionality can be disabled if desired, and the interval can be configured
Direct Invocation of Method on Modules :heavy_check_mark: Invoke method calls to another module using using the Edge Gateway.

Provisioning Device Client

Features Status Description
TPM Individual Enrollment :heavy_minus_sign: Provisioning via Trusted Platform Module.
X.509 Individual Enrollment :heavy_check_mark: Provisioning via X.509 root certificate. Please review the samples folder and this quickstart on how to create a device client.
X.509 Enrollment Group :heavy_check_mark: Provisioning via X.509 leaf certificate). Please review the samples folder on how to create a device client.
Symmetric Key Enrollment :heavy_check_mark: Provisioning via Symmetric key attestation). Please review the samples folder on how to create a device client.

IoTHub Service Library (azure-iot-hub)

Registry Manager

Features Status Description
Identity registry (CRUD) :heavy_check_mark: Use your backend app to perform CRUD operation for individual device or in bulk.
Cloud-to-device messaging :heavy_check_mark: Use your backend app to send cloud-to-device messages, and set up cloud-to-device message receivers.
Direct Methods operations :heavy_check_mark: Use your backend app to invoke direct method on device.
Device Twins operations :heavy_check_mark: Use your backend app to perform device twin operations. *Twin reported property update callback and replace twin are in progress.
Query :heavy_check_mark: Use your backend app to perform query for information.
Jobs :heavy_multiplication_x: Use your backend app to perform job operation.

IoTHub Provisioning Service Library

Feature is Coming Soon

Features Status Description
CRUD Operation with TPM Individual Enrollment :heavy_multiplication_x: Manage device enrollment using TPM with the service SDK.
Bulk CRUD Operation with TPM Individual Enrollment :heavy_multiplication_x: Bulk manage device enrollment using TPM with the service SDK.
CRUD Operation with X.509 Individual Enrollment :heavy_multiplication_x: Manages device enrollment using X.509 individual enrollment with the service SDK.
CRUD Operation with X.509 Group Enrollment :heavy_multiplication_x: Manages device enrollment using X.509 group enrollment with the service SDK.
Query enrollments :heavy_multiplication_x: Query registration states with the service SDK.
GitHub - Azure/azure-iot-sdk-python: A Python SDK for connecting devices to Microsoft Azure IoT services
A Python SDK for connecting devices to Microsoft Azure IoT services - GitHub - Azure/azure-iot-sdk-python: A Python SDK for connecting devices to Microsoft Azure IoT services