aas_client3_2.submodel
Implement the operations of the Submodel API.
The Submodel API is the interface of a single submodel. Its paths are relative to
the endpoint of the submodel, as a registry lists it in protocolInformation.href
of a descriptor with the interface SUBMODEL-3.2. Hence the base URL of
the Server is the endpoint itself, such as
https://example.com/submodels/dXJuOmV4YW1wbGU6c206MQ, and the paths are appended
without the prefix /submodel of the OpenAPI. Part 2 has the clients use
the endpoint from the registry as it is, so that a submodel server and a submodel
repository can not be told apart.
Every public function implements exactly one operation of the specification. The
private functions _build_* and _parse_* build the request and parse
the response of the operation. They do no I/O, and constitute a semi-public
interface for the testing client, which is released in lockstep with this client.
- aas_client3_2.submodel.get_submodel(server: Server, *, level: Level | None = None, extent: Extent | None = None) Submodel[source]
Get the submodel.
- aas_client3_2.submodel.put_submodel(server: Server, submodel: Submodel) None[source]
Replace the submodel.
- aas_client3_2.submodel.patch_submodel(server: Server, submodel: Submodel) None[source]
Update the existing submodel with the given identifier.
Part 2 replaces the elements of the stored submodel one by one with the elements of
submodel, which must all exist on the server.The query parameter
levelis omitted, since it allows only the valuecore.
- aas_client3_2.submodel.get_submodel_metadata(server: Server) SubmodelMetadata[source]
Get the metadata of the submodel.
- Parameters:
server¶ – where to send the request
- Returns:
the metadata of the submodel
- Implements:
GetSubmodel-Metadata –
GET /submodel/$metadata
- aas_client3_2.submodel.patch_submodel_metadata(server: Server, submodel_metadata: SubmodelMetadata) None[source]
Update the metadata of the submodel.
The submodel elements remain unchanged.
The query parameter
levelis omitted, since it allows only the valuecore.
- aas_client3_2.submodel.get_submodel_reference(server: Server) Reference[source]
Get a reference to the submodel.
- Parameters:
server¶ – where to send the request
- Returns:
the reference to the submodel
- Implements:
GetSubmodel-Reference –
GET /submodel/$reference
- aas_client3_2.submodel.get_submodel_value_only(server: Server, *, level: Level | None = None, extent: Extent | None = None) Mapping[str, Any][source]
Get the values of the submodel.
The values are in the ValueOnly serialization, a JSON object keyed by the ID-shorts of the submodel elements. They can not be parsed further without knowing the structure of the submodel, for example, from
get_submodel_metadata(), since the same JSON can stand for different kinds of elements; for example, a range looks exactly like a collection with the propertiesminandmax.
- aas_client3_2.submodel.patch_submodel_value_only(server: Server, submodel: Submodel) None[source]
Update the values of the submodel.
The client sends only the values of
submodel, in the ValueOnly serialization. Part 2 replaces the values of the stored elements one by one, and the elements must all exist on the server. Everything else, such as the semantic IDs, remains unchanged.The query parameter
levelis omitted, since it allows only the valuecore.
- aas_client3_2.submodel.get_submodel_path(server: Server, *, level: Level | None = None) List[str][source]
List the ID-short paths of the elements of the submodel.
The paths start at the top-level elements, such as
MotorandMotor.Speed, since the submodel itself has no path. Withlevelset to core, only the paths of the top-level elements are listed.
- aas_client3_2.submodel.get_all_submodel_elements(server: Server, *, limit: int | None = None, cursor: str | None = None, level: Level | None = None, extent: Extent | None = None) GetSubmodelElementsResult[source]
List a page of the top-level submodel elements of the submodel.
- Parameters:
- Returns:
a page of the submodel elements
- Implements:
GetAllSubmodelElements –
GET /submodel/submodel-elements
- aas_client3_2.submodel.post_submodel_element(server: Server, submodel_element: SubmodelElement) SubmodelElement[source]
Add a new top-level submodel element to the submodel.
- aas_client3_2.submodel.get_all_submodel_elements_metadata(server: Server, *, limit: int | None = None, cursor: str | None = None) GetSubmodelElementsMetadataResult[source]
List a page of the metadata of the top-level submodel elements of the submodel.
- aas_client3_2.submodel.get_all_submodel_elements_value_only(server: Server, *, limit: int | None = None, cursor: str | None = None, level: Level | None = None, extent: Extent | None = None) GetSubmodelElementsValueResult[source]
List a page of the values of the top-level submodel elements of the submodel.
Each item of the page is a JSON object with a single key, the ID-short of the element, whose value is the ValueOnly serialization of the element. Unlike the OpenAPI, which types the page as a single JSON object, aas-core3.2 follows Eclipse BaSyx Go components and the prose of Part 2 here.
- Parameters:
- Returns:
a page of the values of the submodel elements
- Implements:
GetAllSubmodelElements-ValueOnly –
GET /submodel/submodel-elements/$value
- aas_client3_2.submodel.get_all_submodel_elements_reference(server: Server, *, limit: int | None = None, cursor: str | None = None) GetReferencesResult[source]
List a page of the references to the top-level submodel elements of the submodel.
- aas_client3_2.submodel.get_all_submodel_elements_path(server: Server, *, limit: int | None = None, cursor: str | None = None, level: Level | None = None) GetPathItemsResult[source]
List a page of the ID-short paths of the elements of the submodel.
The limit applies to the paths, not to the top-level elements.
- aas_client3_2.submodel.get_submodel_element_by_path(server: Server, id_short_path: str, *, level: Level | None = None, extent: Extent | None = None) SubmodelElement[source]
Get the submodel element at the given ID-short path.
- Parameters:
- Returns:
the submodel element
- Implements:
GetSubmodelElementByPath –
GET /submodel/submodel-elements/{idShortPath}
- aas_client3_2.submodel.post_submodel_element_by_path(server: Server, id_short_path: str, submodel_element: SubmodelElement) SubmodelElement[source]
Add a new submodel element as a child of the element at the given ID-short path.
The element at
id_short_pathmust be able to hold children, such as a submodel element collection, a submodel element list or an entity.- Parameters:
- Returns:
the created submodel element, as stored by the server
- Implements:
PostSubmodelElementByPath –
POST /submodel/submodel-elements/{idShortPath}
- aas_client3_2.submodel.put_submodel_element_by_path(server: Server, id_short_path: str, submodel_element: SubmodelElement) None[source]
Create or replace the submodel element at the given ID-short path.
The query parameter
levelis omitted, since it allows only the valuedeep.
- aas_client3_2.submodel.patch_submodel_element_by_path(server: Server, id_short_path: str, submodel_element: SubmodelElement) None[source]
Update the existing submodel element at the given ID-short path.
Part 2 replaces the stored element and its children one by one with
submodel_elementand its children, which must all exist on the server.The query parameter
levelis omitted, since it allows only the valuecore.
- aas_client3_2.submodel.delete_submodel_element_by_path(server: Server, id_short_path: str) None[source]
Delete the submodel element at the given ID-short path.
- aas_client3_2.submodel.get_submodel_element_by_path_metadata(server: Server, id_short_path: str) SubmodelElementMetadata[source]
Get the metadata of the submodel element at the given ID-short path.
- aas_client3_2.submodel.patch_submodel_element_by_path_metadata(server: Server, id_short_path: str, submodel_element_metadata: SubmodelElementMetadata) None[source]
Update the metadata of the submodel element at the given ID-short path.
The value of the element remains unchanged.
- aas_client3_2.submodel.get_submodel_element_by_path_value_only(server: Server, id_short_path: str, *, level: Level | None = None, extent: Extent | None = None) None | bool | int | float | str | Sequence[Any] | Mapping[str, Any][source]
Get the value of the submodel element at the given ID-short path.
The value is in the ValueOnly serialization, without the ID-short of the element; for example,
5for a propertyxs:int, or{"min": 1, "max": 5}for a range. The value can not be parsed further without knowing the kind of the element, since the ValueOnly serialization drops the model types; for example, the range above looks exactly like a collection with the propertiesminandmax. If you know the kind, you can parse some kinds with aas-core3.2, for example, a range withaas_core3_2.jsonization.range_value_from_jsonable().- Parameters:
- Returns:
the value of the submodel element
- Implements:
GetSubmodelElementByPath-ValueOnly –
GET /submodel/submodel-elements/{idShortPath}/$value
- aas_client3_2.submodel.patch_submodel_element_by_path_value_only(server: Server, id_short_path: str, submodel_element: SubmodelElement) None[source]
Update the value of the submodel element at the given ID-short path.
The client sends only the value of
submodel_element, in the ValueOnly serialization. Part 2 replaces the value of the stored element, and of its children one by one, which must all exist on the server. Everything else, such as the semantic ID, remains unchanged.The query parameter
levelis omitted, since it allows only the valuecore.- Parameters:
- Raises:
ValueErrorifsubmodel_elementis an operation or a capability, which have no value, or if its value can not be serialized, such as a propertyxs:intwith the value"abc"- Implements:
PatchSubmodelElementByPath-ValueOnly –
PATCH /submodel/submodel-elements/{idShortPath}/$value
- aas_client3_2.submodel.get_submodel_element_by_path_reference(server: Server, id_short_path: str) Reference[source]
Get a reference to the submodel element at the given ID-short path.
The reference is a model reference with a key for the submodel, followed by a key for each element along the path. The key of an element in a list holds its index, such as
0.
- aas_client3_2.submodel.get_submodel_element_by_path_path(server: Server, id_short_path: str, *, level: Level | None = None) List[str][source]
List the ID-short paths of the submodel element and of its descendants.
The paths include the path of the element itself. With
levelset to core, only the paths of the element and of its direct children are listed.
- aas_client3_2.submodel.get_file_by_path(server: Server, id_short_path: str) ContextManager[Download][source]
Download the content of the file element at the given ID-short path.
The content is streamed, so use the result as a context manager:
with submodel.get_file_by_path(server, "Documentation.Manual") as download: with open("manual.pdf", "wb") as fid: download.write_to(fid)
The connection is released when the context is exited. If the file element refers to an external resource, the server may redirect to it; whether the redirect is followed is up to the transport.
- Parameters:
- Returns:
a context manager which gives the download
- Raises:
MethodNotAllowedif the element is not a file element- Implements:
GetFileByPath –
GET /submodel/submodel-elements/{idShortPath}/attachment
- aas_client3_2.submodel.put_file_by_path(server: Server, id_short_path: str, content: bytes | IO[bytes], *, file_name: str | None = None, content_type: str | None = None) None[source]
Upload the content of the file element at the given ID-short path.
The content is either
bytes, or a binary file object which is readable and seekable; it is read from its current position to its end, in chunks, so that a large file is never held in memory. The file object must not be modified during the upload.- Parameters:
server¶ – where to send the request
id_short_path¶ – ID-short path of the file element, such as
Manualcontent¶ – content of the file
file_name¶ – if set, the name of the file
content_type¶ – if set, the content type of the file, such as
application/pdf, otherwiseapplication/octet-stream. The servers may take it as the new content type of the file element.
- Raises:
TypeErrorbefore sending anything if the content is neither bytes nor a binary file object;ValueErrorbefore sending anything if the content can not be read again, or if the file name or the content type contain double quotes, backslashes or control characters;MethodNotAllowedif the element is not a file element- Implements:
PutFileByPath –
PUT /submodel/submodel-elements/{idShortPath}/attachment
- aas_client3_2.submodel.delete_file_by_path(server: Server, id_short_path: str) None[source]
Delete the content of the file element at the given ID-short path.
The file element itself stays.
- aas_client3_2.submodel.invoke_operation(server: Server, id_short_path: str, operation_request: OperationRequest) OperationResult[source]
Invoke the operation at the given ID-short path, and wait for its result.
The connection stays open until the server has the result. Set
client_timeout_durationofoperation_request, such asPT30S, to tell the server how long the client waits; the timeout of the transport should be longer.- Parameters:
- Returns:
the result of the operation; check its
execution_stateandsuccess, since a failed operation still gives a result- Raises:
MethodNotAllowedif the element is not an operation- Implements:
InvokeOperation –
POST /submodel/submodel-elements/{idShortPath}/invoke
- aas_client3_2.submodel.invoke_operation_sync_value_only(server: Server, id_short_path: str, operation_request: OperationRequestValueOnly) OperationResultValueOnly[source]
Invoke the operation with the arguments in Value-Only, and wait for its result.
The arguments map the ID-shorts of the variables to their values, such as
{"speed": 5}; the numbers in the result are floats, as everywhere in Value-Only, since JSON knows a single numeric type. The value types of the variables tell which of the numbers are integers.- Parameters:
- Returns:
the result of the operation
- Raises:
MethodNotAllowedif the element is not an operation- Implements:
InvokeOperationSync-ValueOnly –
POST /submodel/submodel-elements/{idShortPath}/invoke/$value
- aas_client3_2.submodel.invoke_operation_async(server: Server, id_short_path: str, operation_request: OperationRequestAsync) OperationHandle[source]
Start the operation at the given ID-short path on the server, and return at once.
Poll
get_operation_async_status()with the handle until the operation is finished, and then fetchget_operation_async_result():handle = submodel.invoke_operation_async( server, "Control.Start", aas_types.OperationRequestAsync(client_timeout_duration="PT60S"), ) while True: status = submodel.get_operation_async_status( server, "Control.Start", handle.handle_id ) if status.execution_state not in ( aas_types.ExecutionState.INITIATED, aas_types.ExecutionState.RUNNING, ): break time.sleep(1) result = submodel.get_operation_async_result( server, "Control.Start", handle.handle_id )
Note that the server may accept an invocation which fails later. The failure then shows in the result.
- Parameters:
- Returns:
the handle of the invocation, as given in the header
Location- Raises:
MethodNotAllowedif the element is not an operation- Implements:
InvokeOperationAsync –
POST /submodel/submodel-elements/{idShortPath}/invoke-async
- aas_client3_2.submodel.invoke_operation_async_value_only(server: Server, id_short_path: str, operation_request: OperationRequestAsyncValueOnly) OperationHandle[source]
Start the operation with the arguments in Value-Only, and return at once.
See
invoke_operation_async()for how to poll the status; fetch the result withget_operation_async_result_value_only().- Parameters:
- Returns:
the handle of the invocation, as given in the header
Location- Implements:
InvokeOperationAsync-ValueOnly –
POST /submodel/submodel-elements/{idShortPath}/invoke-async/$value
- aas_client3_2.submodel.get_operation_async_status(server: Server, id_short_path: str, handle_id: str) BaseOperationResult[source]
Get the status of the asynchronous invocation with the given handle.
While the operation runs, the server gives the status. Once it is finished, the server redirects to the result. The transport usually follows the redirect (the one based on requests does); if not, the client follows it, but only to the origin of the server. Either way, the status is taken from the result, so its
execution_statetells whether the operation completed, failed or timed out.- Parameters:
server¶ – where to send the request
id_short_path¶ – ID-short path of the operation, such as
Control.Starthandle_id¶ – handle as given by
invoke_operation_async()
- Returns:
the status of the invocation
- Raises:
NotFoundif there is no such invocation;UnexpectedResponseif the server redirects to another origin- Implements:
GetOperationAsyncStatus –
GET /submodel/submodel-elements/{idShortPath}/operation-status/{handleId}
- aas_client3_2.submodel.get_operation_async_result(server: Server, id_short_path: str, handle_id: str) OperationResult[source]
Get the result of the finished asynchronous invocation with the given handle.
- Parameters:
server¶ – where to send the request
id_short_path¶ – ID-short path of the operation, such as
Control.Starthandle_id¶ – handle as given by
invoke_operation_async()
- Returns:
the result of the operation; a failed operation still gives a result, with
execution_stateset toFailed- Raises:
NotFoundif there is no such invocation- Implements:
GetOperationAsyncResult –
GET /submodel/submodel-elements/{idShortPath}/operation-results/{handleId}
- aas_client3_2.submodel.get_operation_async_result_value_only(server: Server, id_short_path: str, handle_id: str) OperationResultValueOnly[source]
Get the result of the finished asynchronous invocation in Value-Only.
- Parameters:
server¶ – where to send the request
id_short_path¶ – ID-short path of the operation, such as
Control.Starthandle_id¶ – handle as given by
invoke_operation_async()orinvoke_operation_async_value_only()
- Returns:
the result of the operation
- Raises:
NotFoundif there is no such invocation- Implements:
GetOperationAsyncResult-ValueOnly –
GET /submodel/submodel-elements/{idShortPath}/operation-results/{handleId}/$value