DigitalTwinClient Class

A class to provide convenience APIs for DigitalTwin operations, based on top of the auto generated IotHub REST APIs

Initializer for a DigitalTwinClient.

After a successful creation the class has been authenticated with IoTHub and it is ready to call the member APIs to communicate with IoTHub.

Inheritance
builtins.object
DigitalTwinClient

Constructor

DigitalTwinClient(connection_string=None, host=None, auth=None)

Parameters

Name Description
connection_string
str

The IoTHub connection string used to authenticate connection with IoTHub if we are using connection_str authentication. Default value: None

Default value: None
host
str

The Azure service url if we are using token credential authentication. Default value: None

Default value: None
auth
str

The Azure authentication object if we are using token credential authentication. Default value: None

Default value: None

Methods

from_connection_string

Classmethod initializer for a DigitalTwinClient Service client. Creates DigitalTwinClient class from connection string.

After a successful creation the class has been authenticated with IoTHub and it is ready to call the member APIs to communicate with IoTHub.

from_token_credential

Classmethod initializer for a DigitalTwinClient Service client. Creates DigitalTwinClient class from host name url and Azure token credential.

After a successful creation the class has been authenticated with IoTHub and it is ready to call the member APIs to communicate with IoTHub.

get_digital_twin

Retrieve the Digital Twin of a given device. :param str digital_twin__id: The digital twin Id of the given device.

invoke_command

Invoke a command on a particular device and get the result of it. :param str digital_twin__id: The digital twin Id of the given device. :param str command_name: The command's name. :param str payload: The argument of a command. :param int connect_timeout_in_seconds: Maximum interval of time, in seconds, that the digital twin command will wait for the answer. :param int response_timeout_in_seconds: Maximum interval of time, in seconds, that the digital twin command will wait for the response. The value must be within 5-300.

invoke_component_command

Invoke a command on an component of a particular device and get the result of it. :param str digital_twin__id: The digital twin Id of the given device. :param str component_path: The component's name. :param str command_name: The command's name. :param str payload: The argument of a command. :param int connect_timeout_in_seconds: Maximum interval of time, in seconds, that the digital twin command will wait for the answer. :param int response_timeout_in_seconds: Maximum interval of time, in seconds, that the digital twin command will wait for the response. The value must be within 5-300. :type response_timeout_in_seconds: int

update_digital_twin

Update the Digital Twin Component of a given device using a patch object. :param str digital_twin__id: The digital twin Id of the given device. :param list[object]: The json-patch object to update the Digital Twin. :param str etag: The etag (if_match) value to use for the update operation.

from_connection_string

Classmethod initializer for a DigitalTwinClient Service client. Creates DigitalTwinClient class from connection string.

After a successful creation the class has been authenticated with IoTHub and it is ready to call the member APIs to communicate with IoTHub.

from_connection_string(connection_string)

Parameters

Name Description
connection_string
Required
str

The IoTHub connection string used to authenticate connection with IoTHub.

Returns

Type Description

from_token_credential

Classmethod initializer for a DigitalTwinClient Service client. Creates DigitalTwinClient class from host name url and Azure token credential.

After a successful creation the class has been authenticated with IoTHub and it is ready to call the member APIs to communicate with IoTHub.

from_token_credential(url, token_credential)

Parameters

Name Description
url
Required
str

The Azure service url (host name).

token_credential
Required
<xref:azure.core.TokenCredential>

The Azure token credential object

Returns

Type Description

get_digital_twin

Retrieve the Digital Twin of a given device. :param str digital_twin__id: The digital twin Id of the given device.

get_digital_twin(digital_twin_id)

Parameters

Name Description
digital_twin_id
Required

Returns

Type Description

The return object containing the Digital Twin.

Exceptions

Type Description
<xref:if the HTTP response status is not in >[<xref:200>]<xref:.>

invoke_command

Invoke a command on a particular device and get the result of it. :param str digital_twin__id: The digital twin Id of the given device. :param str command_name: The command's name. :param str payload: The argument of a command. :param int connect_timeout_in_seconds: Maximum interval of time, in seconds, that the digital twin command will wait for the answer. :param int response_timeout_in_seconds: Maximum interval of time, in seconds, that the digital twin command will wait for the response. The value must be within 5-300.

invoke_command(digital_twin_id, command_name, payload, connect_timeout_in_seconds=None, response_timeout_in_seconds=None)

Parameters

Name Description
digital_twin_id
Required
command_name
Required
payload
Required
connect_timeout_in_seconds
Default value: None
response_timeout_in_seconds
Default value: None

Returns

Type Description

The result of the invoked command.

Exceptions

Type Description
<xref:if the HTTP response status is not in >[<xref:200>]<xref:.>

invoke_component_command

Invoke a command on an component of a particular device and get the result of it. :param str digital_twin__id: The digital twin Id of the given device. :param str component_path: The component's name. :param str command_name: The command's name. :param str payload: The argument of a command. :param int connect_timeout_in_seconds: Maximum interval of time, in seconds, that the digital twin command will wait for the answer. :param int response_timeout_in_seconds: Maximum interval of time, in seconds, that the digital twin command will wait for the response. The value must be within 5-300. :type response_timeout_in_seconds: int

invoke_component_command(digital_twin_id, component_path, command_name, payload, connect_timeout_in_seconds=None, response_timeout_in_seconds=None)

Parameters

Name Description
digital_twin_id
Required
component_path
Required
command_name
Required
payload
Required
connect_timeout_in_seconds
Default value: None
response_timeout_in_seconds
Default value: None

Returns

Type Description

The result of the invoked command.

Exceptions

Type Description
<xref:if the HTTP response status is not in >[<xref:200>]<xref:.>

update_digital_twin

Update the Digital Twin Component of a given device using a patch object. :param str digital_twin__id: The digital twin Id of the given device. :param list[object]: The json-patch object to update the Digital Twin. :param str etag: The etag (if_match) value to use for the update operation.

update_digital_twin(digital_twin_id, digital_twin_patch, etag=None)

Parameters

Name Description
digital_twin_id
Required
digital_twin_patch
Required
etag
Default value: None

Returns

Type Description

The return object containing the updated Digital Twin.

Exceptions

Type Description
<xref:if the HTTP response status is not in >[<xref:200>]<xref:.>