azure.digitaltwins.core package

class azure.digitaltwins.core.DigitalTwinsClient(endpoint: str, credential: TokenCredential, **kwargs: Any)[source]

Creates an instance of the Digital Twins client.

Parameters
  • endpoint (str) – The URL endpoint of an Azure search service

  • credential (TokenCredential) – A credential to authenticate requests to the service

create_models(dtdl_models: List[Dict[str, object]], **kwargs: Any)List[DigitalTwinsModelData][source]

Create one or more models. When any error occurs, no models are uploaded.

Parameters

model_list (List[Dict[str,object]]) – The set of models to create. Each dict corresponds to exactly one model.

Returns

The list of created models.

Return type

List[DigitalTwinsModelData]

Raises
decommission_model(model_id: str, **kwargs: Any)None[source]

Decommissions a model.

Parameters

model_id (str) – The ID for the model. The ID is globally unique and case sensitive.

Returns

None

Return type

None

Raises
delete_digital_twin(digital_twin_id: str, **kwargs: Any)None[source]

Delete a digital twin.

Parameters

digital_twin_id (str) – The ID of the digital twin.

Keyword Arguments
  • match_condition (MatchConditions) – The condition under which to perform the operation.

  • etag (str) – Only perform the operation if the entity’s etag matches the value provided according to the match_condition.

Returns

None

Return type

None

Raises
delete_event_route(event_route_id: str, **kwargs: Any)None[source]

Delete an event route.

Parameters

event_route_id (str) – The ID of the event route to delete.

Returns

None

Return type

None

Raises
delete_model(model_id: str, **kwargs: Any)None[source]

Delete a model.

Parameters

model_id (str) – The ID of the model to delete.

Returns

None

Return type

None

Raises
delete_relationship(digital_twin_id: str, relationship_id: str, **kwargs: Any)None[source]

Delete a relationship on a digital twin.

Parameters
  • digital_twin_id (str) – The ID of the digital twin.

  • relationship_id (str) – The ID of the relationship to delete.

Keyword Arguments
  • match_condition (MatchConditions) – The condition under which to perform the operation.

  • etag (str) – Only perform the operation if the entity’s etag matches the value provided according to the match_condition.

Returns

None

Return type

None

Raises
get_component(digital_twin_id: str, component_name: str, **kwargs: Any)Dict[str, object][source]

Get a component on a digital twin.

Parameters
  • digital_twin_id (str) – The ID of the digital twin.

  • component_name (str) – The component being retrieved.

Returns

Dictionary containing the component.

Return type

Dict[str, object]

Raises
get_digital_twin(digital_twin_id: str, **kwargs: Any)Dict[str, object][source]

Get a digital twin.

Parameters

digital_twin_id (str) – The ID of the digital twin.

Returns

Dictionary containing the twin.

Return type

Dict[str, object]

Raises
get_event_route(event_route_id: str, **kwargs: Any)DigitalTwinsEventRoute[source]

Get an event route.

Parameters

event_route_id (str) – The ID of the event route.

Returns

The event route object.

Return type

DigitalTwinsEventRoute

Raises
get_model(model_id: str, **kwargs: Any)DigitalTwinsModelData[source]

Get a model, including the model metadata and the model definition.

Parameters

model_id (str) – The ID of the model.

Keyword Arguments

include_model_definition (bool) – Include the model definition as part of the result. The default value is False.

Returns

The model data.

Return type

DigitalTwinsModelData

Raises
get_relationship(digital_twin_id: str, relationship_id: str, **kwargs: Any)Dict[str, object][source]

Get a relationship on a digital twin.

Parameters
  • digital_twin_id (str) – The ID of the digital twin.

  • relationship_id (str) – The ID of the relationship to retrieve.

Returns

Dictionary containing the relationship.

Return type

Dict[str, object]

Raises
list_event_routes(**kwargs: Any)ItemPaged[DigitalTwinsEventRoute][source]

Retrieves all event routes.

Keyword Arguments

results_per_page (int) – The maximum number of items to retrieve per request. The server may choose to return less than the requested max.

Returns

An iterator instance of event routes.

Return type

ItemPaged[DigitalTwinsEventRoute]

Raises

HttpResponseError

list_incoming_relationships(digital_twin_id: str, **kwargs: Any)~ azure.core.paging.ItemPaged[IncomingRelationship][source]

Retrieve all incoming relationships for a digital twin.

Parameters

digital_twin_id (str) – The ID of the digital twin.

Returns

An iterator like instance of either Relationship.

Return type

ItemPaged[IncomingRelationship]

Raises
list_models(dependencies_for: Optional[List[str]] = None, **kwargs: Any)ItemPaged[DigitalTwinsModelData][source]

Get the list of models.

Parameters

dependencies_for (List[str]) – The model IDs to have dependencies retrieved. If omitted, all models are retrieved.

Keyword Arguments
  • include_model_definition (bool) – Include the model definition as part of the results. The default value is False.

  • results_per_page (int) – The maximum number of items to retrieve per request. The server may choose to return less than the requested max.

Returns

An iterator instance of list of model data.

Return type

ItemPaged[DigitalTwinsModelData]

Raises

HttpResponseError

list_relationships(digital_twin_id: str, relationship_id: Optional[str] = None, **kwargs: Any)~ azure.core.paging.ItemPaged[Dict[str, object]][source]

Retrieve relationships for a digital twin.

Parameters
  • digital_twin_id (str) – The ID of the digital twin.

  • relationship_id (str) – The ID of the relationship to get (if None all the relationship will be retrieved).

Returns

An iterator instance of list of relationships

Return type

ItemPaged[Dict[str,object]]

Raises
publish_component_telemetry(digital_twin_id: str, component_name: str, telemetry: object, **kwargs: Any)None[source]

Publish telemetry from a digital twin’s component, which is then consumed by one or many destination endpoints (subscribers) defined under.

Parameters
  • digital_twin_id (str) – The ID of the digital twin.

  • component_name (str) – The name of the DTDL component.

  • telemetry (object) – The telemetry data to be sent.

Keyword Arguments

message_id (str) – The message ID. If not specified, a UUID will be generated.

Returns

None

Return type

None

Raises
publish_telemetry(digital_twin_id: str, telemetry: object, **kwargs: Any)None[source]

Publish telemetry from a digital twin, which is then consumed by one or many destination endpoints (subscribers) defined under.

Parameters
  • digital_twin_id (str) – The ID of the digital twin

  • telemetry (object) – The telemetry data to be sent

Keyword Arguments

message_id (str) – The message ID. If not specified, a UUID will be generated.

Returns

None

Return type

None

Raises
query_twins(query_expression: str, **kwargs: Any)azure.core.paging.ItemPaged[Dict[str, object]][source]

Query for digital twins.

Note: that there may be a delay between before changes in your instance are reflected in queries. For more details on query limitations, see https://docs.microsoft.com/azure/digital-twins/how-to-query-graph#query-limitations

Parameters

query_expression (str) – The query expression to execute.

Returns

An iterable of query results.

Return type

ItemPaged[Dict[str, object]]

Raises

HttpResponseError

update_component(digital_twin_id: str, component_name: str, json_patch: List[Dict[str, object]], **kwargs: Any)None[source]

Update properties of a component on a digital twin using a JSON patch.

Parameters
  • digital_twin_id (str) – The ID of the digital twin.

  • component_name (str) – The component being updated.

  • json_patch (List[Dict[str,object]]) – An update specification described by JSON Patch.

Keyword Arguments
  • match_condition (MatchConditions) – The condition under which to perform the operation.

  • etag (str) – Only perform the operation if the entity’s etag matches the value provided according to the match_condition.

Returns

None

Return type

None

Raises
update_digital_twin(digital_twin_id: str, json_patch: List[Dict[str, object]], **kwargs: Any)None[source]

Update a digital twin using a JSON patch.

Parameters
  • digital_twin_id (str) – The ID of the digital twin.

  • json_patch (List[Dict[str,object]]) – An update specification described by JSON Patch. Updates to property values and $model elements may happen in the same request. Operations are limited to add, replace and remove.

Keyword Arguments
  • match_condition (MatchConditions) – The condition under which to perform the operation.

  • etag (str) – Only perform the operation if the entity’s etag matches the value provided according to the match_condition.

Returns

None

Return type

None

Raises
update_relationship(digital_twin_id: str, relationship_id: str, json_patch: List[Dict[str, object]], **kwargs: Any)None[source]

Updates the properties of a relationship on a digital twin using a JSON patch.

Parameters
  • digital_twin_id (str) – The ID of the digital twin.

  • relationship_id (str) – The ID of the relationship to retrieve.

  • json_patch (List[Dict[str,object]]) – JSON Patch description of the update to the relationship properties.

Keyword Arguments
  • match_condition (MatchConditions) – The condition under which to perform the operation.

  • etag (str) – Only perform the operation if the entity’s etag matches the value provided according to the match_condition.

Returns

None

Return type

None

Raises
upsert_digital_twin(digital_twin_id: str, digital_twin: Dict[str, object], **kwargs: Any)Dict[str, object][source]

Create or update a digital twin.

Parameters
  • digital_twin_id (str) – The ID of the digital twin.

  • digital_twin (Dict[str,object]) – Dictionary containing the twin to create or update.

Keyword Arguments
  • match_condition (MatchConditions) – The condition under which to perform the operation.

  • etag (str) – Only perform the operation if the entity’s etag matches the value provided according to the match_condition.

Returns

Dictionary containing the created or updated twin.

Return type

Dict[str, object]

Raises
upsert_event_route(event_route_id: str, event_route: DigitalTwinsEventRoute, **kwargs: Any)None[source]

Create or update an event route.

Parameters
  • event_route_id (str) – The ID of the event route to create or update.

  • event_route (DigitalTwinsEventRoute) – The event route data.

Returns

None

Return type

None

Raises

HttpResponseError

upsert_relationship(digital_twin_id: str, relationship_id: str, relationship: Dict[str, object], **kwargs: Any)Dict[str, object][source]

Create or update a relationship on a digital twin.

Parameters
  • digital_twin_id (str) – The ID of the digital twin.

  • relationship_id (str) – The ID of the relationship to retrieve.

  • relationship (Dict[str,object]) – Dictionary containing the relationship.

Keyword Arguments
  • match_condition (MatchConditions) – The condition under which to perform the operation.

  • etag (str) – Only perform the operation if the entity’s etag matches the value provided according to the match_condition.

Returns

The created or updated relationship.

Return type

Dict[str, object]

Raises
class azure.digitaltwins.core.DigitalTwinsEventRoute(*, endpoint_name: str, filter: str, **kwargs)[source]

A route which directs notification and telemetry events to an endpoint. Endpoints are a destination outside of Azure Digital Twins such as an EventHub.

Variables are only populated by the server, and will be ignored when sending a request.

All required parameters must be populated in order to send to Azure.

Variables
  • id (str) – The id of the event route.

  • endpoint_name (str) – Required. The name of the endpoint this event route is bound to.

  • filter (str) – Required. An expression which describes the events which are routed to the endpoint.

Keyword Arguments
  • endpoint_name (str) – Required. The name of the endpoint this event route is bound to.

  • filter (str) – Required. An expression which describes the events which are routed to the endpoint.

as_dict(keep_readonly=True, key_transformer=<function attribute_transformer>, **kwargs)

Return a dict that can be JSONify using json.dump.

Advanced usage might optionaly use a callback as parameter:

Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.

The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.

See the three examples in this file:

  • attribute_transformer

  • full_restapi_key_transformer

  • last_restapi_key_transformer

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

key_transformer (function) – A key transformer function.

Returns

A dict JSON compatible object

Return type

dict

classmethod deserialize(data, content_type=None)

Parse a str using the RestAPI syntax and return a model.

Parameters
  • data (str) – A str using RestAPI structure. JSON by default.

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod enable_additional_properties_sending()
classmethod from_dict(data, key_extractors=None, content_type=None)

Parse a dict using given key extractor return a model.

By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)

Parameters
  • data (dict) – A dict using RestAPI structure

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod is_xml_model()
serialize(keep_readonly=False, **kwargs)

Return the JSON that would be sent to azure from this model.

This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

keep_readonly (bool) – If you want to serialize the readonly attributes

Returns

A dict JSON compatible object

Return type

dict

validate()

Validate this model recursively and return a list of ValidationError.

Returns

A list of validation error

Return type

list

class azure.digitaltwins.core.DigitalTwinsModelData(*, id: str, display_name: Optional[Dict[str, str]] = None, description: Optional[Dict[str, str]] = None, upload_time: Optional[datetime.datetime] = None, decommissioned: Optional[bool] = False, model: Optional[Any] = None, **kwargs)[source]

A model definition and metadata for that model.

All required parameters must be populated in order to send to Azure.

Variables
  • display_name (dict[str, str]) – A language map that contains the localized display names as specified in the model definition.

  • description (dict[str, str]) – A language map that contains the localized descriptions as specified in the model definition.

  • id (str) – Required. The id of the model as specified in the model definition.

  • upload_time (datetime) – The time the model was uploaded to the service.

  • decommissioned (bool) – Indicates if the model is decommissioned. Decommissioned models cannot be referenced by newly created digital twins.

  • model (any) – The model definition.

Keyword Arguments
  • display_name (dict[str, str]) – A language map that contains the localized display names as specified in the model definition.

  • description (dict[str, str]) – A language map that contains the localized descriptions as specified in the model definition.

  • id (str) – Required. The id of the model as specified in the model definition.

  • upload_time (datetime) – The time the model was uploaded to the service.

  • decommissioned (bool) – Indicates if the model is decommissioned. Decommissioned models cannot be referenced by newly created digital twins.

  • model (any) – The model definition.

as_dict(keep_readonly=True, key_transformer=<function attribute_transformer>, **kwargs)

Return a dict that can be JSONify using json.dump.

Advanced usage might optionaly use a callback as parameter:

Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.

The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.

See the three examples in this file:

  • attribute_transformer

  • full_restapi_key_transformer

  • last_restapi_key_transformer

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

key_transformer (function) – A key transformer function.

Returns

A dict JSON compatible object

Return type

dict

classmethod deserialize(data, content_type=None)

Parse a str using the RestAPI syntax and return a model.

Parameters
  • data (str) – A str using RestAPI structure. JSON by default.

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod enable_additional_properties_sending()
classmethod from_dict(data, key_extractors=None, content_type=None)

Parse a dict using given key extractor return a model.

By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)

Parameters
  • data (dict) – A dict using RestAPI structure

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod is_xml_model()
serialize(keep_readonly=False, **kwargs)

Return the JSON that would be sent to azure from this model.

This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

keep_readonly (bool) – If you want to serialize the readonly attributes

Returns

A dict JSON compatible object

Return type

dict

validate()

Validate this model recursively and return a list of ValidationError.

Returns

A list of validation error

Return type

list

class azure.digitaltwins.core.IncomingRelationship(*, relationship_id: Optional[str] = None, source_id: Optional[str] = None, relationship_name: Optional[str] = None, relationship_link: Optional[str] = None, **kwargs)[source]

An incoming relationship.

Variables
  • relationship_id (str) – A user-provided string representing the id of this relationship, unique in the context of the source digital twin, i.e. sourceId + relationshipId is unique in the context of the service.

  • source_id (str) – The id of the source digital twin.

  • relationship_name (str) – The name of the relationship.

  • relationship_link (str) – Link to the relationship, to be used for deletion.

Keyword Arguments
  • relationship_id (str) – A user-provided string representing the id of this relationship, unique in the context of the source digital twin, i.e. sourceId + relationshipId is unique in the context of the service.

  • source_id (str) – The id of the source digital twin.

  • relationship_name (str) – The name of the relationship.

  • relationship_link (str) – Link to the relationship, to be used for deletion.

as_dict(keep_readonly=True, key_transformer=<function attribute_transformer>, **kwargs)

Return a dict that can be JSONify using json.dump.

Advanced usage might optionaly use a callback as parameter:

Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.

The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.

See the three examples in this file:

  • attribute_transformer

  • full_restapi_key_transformer

  • last_restapi_key_transformer

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

key_transformer (function) – A key transformer function.

Returns

A dict JSON compatible object

Return type

dict

classmethod deserialize(data, content_type=None)

Parse a str using the RestAPI syntax and return a model.

Parameters
  • data (str) – A str using RestAPI structure. JSON by default.

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod enable_additional_properties_sending()
classmethod from_dict(data, key_extractors=None, content_type=None)

Parse a dict using given key extractor return a model.

By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)

Parameters
  • data (dict) – A dict using RestAPI structure

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod is_xml_model()
serialize(keep_readonly=False, **kwargs)

Return the JSON that would be sent to azure from this model.

This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

keep_readonly (bool) – If you want to serialize the readonly attributes

Returns

A dict JSON compatible object

Return type

dict

validate()

Validate this model recursively and return a list of ValidationError.

Returns

A list of validation error

Return type

list