Source code for aas_client3_2.submodel_repository

# SPDX-FileCopyrightText: 2026 aas-client3.2-python AUTHORS
#
# SPDX-License-Identifier: MIT

"""
Implement the operations of the Submodel Repository API.

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.
"""

import datetime
from typing import IO, ContextManager, List, Optional, Union

import aas_core3_2.jsonization as aas_jsonization
import aas_core3_2.types as aas_types

from aas_client3_2 import _files
from aas_client3_2 import _invocation
from aas_client3_2 import _json
from aas_client3_2 import _metadata
from aas_client3_2 import _query
from aas_client3_2 import _query_language
from aas_client3_2 import _signed
from aas_client3_2 import _submodel_operations
from aas_client3_2 import errors
from aas_client3_2 import http
from aas_client3_2 import query_results


def _submodel_path(submodel_identifier: str) -> str:
    """Build the path of the submodel with the given identifier."""
    return "/submodels/" + http.encode_base64url(submodel_identifier)


def _query_of_submodels(
    semantic_id: Optional[aas_types.Reference],
    id_short: Optional[str],
    created_from: Optional[datetime.datetime],
    updated_from: Optional[datetime.datetime],
    limit: Optional[int],
    cursor: Optional[str],
) -> _query.Query:
    """Build the query to filter and page the submodels."""
    query: _query.Query = []

    # NOTE (mristin):
    # The specification serializes the semantic ID to JSON and encodes it in
    # base64url. Its operation table and its OpenAPI speak, in contrast, of
    # "the value of the semantic ID". We follow the prose, as BaSyx Go does.
    if semantic_id is not None:
        query.append(("semanticId", _query.encode_instance(semantic_id)))

    if id_short is not None:
        query.append(("idShort", id_short))

    query.extend(_query.time_range(created_from, updated_from))
    query.extend(_query.page(limit, cursor))

    return query


def _build_get_all_submodels(
    base_url: str,
    *,
    semantic_id: Optional[aas_types.Reference] = None,
    id_short: Optional[str] = None,
    created_from: Optional[datetime.datetime] = None,
    updated_from: Optional[datetime.datetime] = None,
    limit: Optional[int] = None,
    cursor: Optional[str] = None,
    level: Optional[aas_types.Level] = None,
    extent: Optional[aas_types.Extent] = None,
) -> http.Request:
    """Build the request of ``GetAllSubmodels``."""
    return _json.build_request(
        "GET",
        http.build_url(
            base_url,
            "/submodels",
            _query_of_submodels(
                semantic_id, id_short, created_from, updated_from, limit, cursor
            )
            + _query.modifiers(level, extent),
        ),
    )


def _parse_get_all_submodels(response: http.Response) -> aas_types.GetSubmodelsResult:
    """Parse the response of ``GetAllSubmodels``."""
    errors.raise_for_unexpected_status(response, {200})
    return _json.parse(response, aas_jsonization.get_submodels_result_from_jsonable)


[docs] def get_all_submodels( server: http.Server, *, semantic_id: Optional[aas_types.Reference] = None, id_short: Optional[str] = None, created_from: Optional[datetime.datetime] = None, updated_from: Optional[datetime.datetime] = None, limit: Optional[int] = None, cursor: Optional[str] = None, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> aas_types.GetSubmodelsResult: """ List a page of the submodels in the repository. :param server: where to send the request :param semantic_id: if set, only the submodels with this semantic ID or supplemental semantic ID :param id_short: if set, only the submodels with this ID-short :param created_from: if set, only the submodels created at or after this time :param updated_from: if set, only the submodels updated at or after this time :param limit: maximum number of the submodels in the page :param cursor: where to continue the listing from :param level: depth of the returned submodels :param extent: whether to include the values of blobs :returns: a page of the submodels :implements GetAllSubmodels: ``GET /submodels`` """ request = _build_get_all_submodels( server.base_url, semantic_id=semantic_id, id_short=id_short, created_from=created_from, updated_from=updated_from, limit=limit, cursor=cursor, level=level, extent=extent, ) response = http.send(server.transport, request) return _parse_get_all_submodels(response)
def _build_post_submodel(base_url: str, submodel: aas_types.Submodel) -> http.Request: """Build the request of ``PostSubmodel``.""" return _json.build_request("POST", http.build_url(base_url, "/submodels"), submodel) def _parse_post_submodel(response: http.Response) -> aas_types.Submodel: """Parse the response of ``PostSubmodel``.""" errors.raise_for_unexpected_status(response, {201}) return _json.parse(response, aas_jsonization.submodel_from_jsonable)
[docs] def post_submodel( server: http.Server, submodel: aas_types.Submodel ) -> aas_types.Submodel: """ Create a new submodel in the repository. :param server: where to send the request :param submodel: the submodel to be created :returns: the created submodel, as stored by the server :implements PostSubmodel: ``POST /submodels`` """ request = _build_post_submodel(server.base_url, submodel) response = http.send(server.transport, request) return _parse_post_submodel(response)
def _build_get_all_submodels_metadata( base_url: str, *, semantic_id: Optional[aas_types.Reference] = None, id_short: Optional[str] = None, created_from: Optional[datetime.datetime] = None, updated_from: Optional[datetime.datetime] = None, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> http.Request: """Build the request of ``GetAllSubmodels-Metadata``.""" return _json.build_request( "GET", http.build_url( base_url, "/submodels/$metadata", _query_of_submodels( semantic_id, id_short, created_from, updated_from, limit, cursor ), ), ) def _parse_get_all_submodels_metadata( response: http.Response, ) -> aas_types.GetSubmodelsMetadataResult: """Parse the response of ``GetAllSubmodels-Metadata``.""" errors.raise_for_unexpected_status(response, {200}) return _metadata.parse_page( response, aas_jsonization.get_submodels_metadata_result_from_jsonable )
[docs] def get_all_submodels_metadata( server: http.Server, *, semantic_id: Optional[aas_types.Reference] = None, id_short: Optional[str] = None, created_from: Optional[datetime.datetime] = None, updated_from: Optional[datetime.datetime] = None, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> aas_types.GetSubmodelsMetadataResult: """ List a page of the metadata of the submodels in the repository. :param server: where to send the request :param semantic_id: if set, only the submodels with this semantic ID or supplemental semantic ID :param id_short: if set, only the submodels with this ID-short :param created_from: if set, only the submodels created at or after this time :param updated_from: if set, only the submodels updated at or after this time :param limit: maximum number of the submodels in the page :param cursor: where to continue the listing from :returns: a page of the metadata of the submodels :implements GetAllSubmodels-Metadata: ``GET /submodels/$metadata`` """ request = _build_get_all_submodels_metadata( server.base_url, semantic_id=semantic_id, id_short=id_short, created_from=created_from, updated_from=updated_from, limit=limit, cursor=cursor, ) response = http.send(server.transport, request) return _parse_get_all_submodels_metadata(response)
def _build_get_all_submodels_reference( base_url: str, *, semantic_id: Optional[aas_types.Reference] = None, id_short: Optional[str] = None, created_from: Optional[datetime.datetime] = None, updated_from: Optional[datetime.datetime] = None, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> http.Request: """Build the request of ``GetAllSubmodels-Reference``.""" return _json.build_request( "GET", http.build_url( base_url, "/submodels/$reference", _query_of_submodels( semantic_id, id_short, created_from, updated_from, limit, cursor ), ), ) def _parse_get_all_submodels_reference( response: http.Response, ) -> aas_types.GetReferencesResult: """Parse the response of ``GetAllSubmodels-Reference``.""" errors.raise_for_unexpected_status(response, {200}) return _json.parse(response, aas_jsonization.get_references_result_from_jsonable)
[docs] def get_all_submodels_reference( server: http.Server, *, semantic_id: Optional[aas_types.Reference] = None, id_short: Optional[str] = None, created_from: Optional[datetime.datetime] = None, updated_from: Optional[datetime.datetime] = None, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> aas_types.GetReferencesResult: """ List a page of the references to the submodels in the repository. This is not to be confused with :py:func:`aas_client3_2.aas_repository.get_all_submodel_references`, which lists the submodel references of an Asset Administration Shell. The deprecated query parameter ``level`` is omitted, since it allows only the value ``core``. :param server: where to send the request :param semantic_id: if set, only the submodels with this semantic ID or supplemental semantic ID :param id_short: if set, only the submodels with this ID-short :param created_from: if set, only the submodels created at or after this time :param updated_from: if set, only the submodels updated at or after this time :param limit: maximum number of the references in the page :param cursor: where to continue the listing from :returns: a page of the references :implements GetAllSubmodels-Reference: ``GET /submodels/$reference`` """ request = _build_get_all_submodels_reference( server.base_url, semantic_id=semantic_id, id_short=id_short, created_from=created_from, updated_from=updated_from, limit=limit, cursor=cursor, ) response = http.send(server.transport, request) return _parse_get_all_submodels_reference(response)
def _build_get_all_submodels_value_only( base_url: str, *, semantic_id: Optional[aas_types.Reference] = None, id_short: Optional[str] = None, created_from: Optional[datetime.datetime] = None, updated_from: Optional[datetime.datetime] = None, limit: Optional[int] = None, cursor: Optional[str] = None, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> http.Request: """Build the request of ``GetAllSubmodels-ValueOnly``.""" return _json.build_request( "GET", http.build_url( base_url, "/submodels/$value", _query_of_submodels( semantic_id, id_short, created_from, updated_from, limit, cursor ) + _query.modifiers(level, extent), ), ) def _parse_get_all_submodels_value_only( response: http.Response, ) -> aas_types.GetSubmodelsValueResult: """Parse the response of ``GetAllSubmodels-ValueOnly``.""" errors.raise_for_unexpected_status(response, {200}) return _json.parse( response, aas_jsonization.get_submodels_value_result_from_jsonable )
[docs] def get_all_submodels_value_only( server: http.Server, *, semantic_id: Optional[aas_types.Reference] = None, id_short: Optional[str] = None, created_from: Optional[datetime.datetime] = None, updated_from: Optional[datetime.datetime] = None, limit: Optional[int] = None, cursor: Optional[str] = None, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> aas_types.GetSubmodelsValueResult: """ List a page of the values of the submodels in the repository. Each item of the page is the ValueOnly serialization of a submodel, a JSON object keyed by the ID-shorts of its elements. The ValueOnly serialization carries no identifier, so the items can not be told apart by the submodels they belong to. Filter by :paramref:`id_short` or :paramref:`semantic_id` to narrow the page down. :param server: where to send the request :param semantic_id: if set, only the submodels with this semantic ID or supplemental semantic ID :param id_short: if set, only the submodels with this ID-short :param created_from: if set, only the submodels created at or after this time :param updated_from: if set, only the submodels updated at or after this time :param limit: maximum number of the submodels in the page :param cursor: where to continue the listing from :param level: depth of the returned values :param extent: whether to include the values of blobs :returns: a page of the values of the submodels :implements GetAllSubmodels-ValueOnly: ``GET /submodels/$value`` """ request = _build_get_all_submodels_value_only( server.base_url, semantic_id=semantic_id, id_short=id_short, created_from=created_from, updated_from=updated_from, limit=limit, cursor=cursor, level=level, extent=extent, ) response = http.send(server.transport, request) return _parse_get_all_submodels_value_only(response)
def _build_get_all_submodels_path( base_url: str, *, semantic_id: Optional[aas_types.Reference] = None, id_short: Optional[str] = None, created_from: Optional[datetime.datetime] = None, updated_from: Optional[datetime.datetime] = None, limit: Optional[int] = None, cursor: Optional[str] = None, level: Optional[aas_types.Level] = None, ) -> http.Request: """Build the request of ``GetAllSubmodels-Path``.""" return _json.build_request( "GET", http.build_url( base_url, "/submodels/$path", _query_of_submodels( semantic_id, id_short, created_from, updated_from, limit, cursor ) + _query.modifiers(level, None), ), ) def _parse_get_all_submodels_path( response: http.Response, ) -> aas_types.GetPathItemsResult: """Parse the response of ``GetAllSubmodels-Path``.""" errors.raise_for_unexpected_status(response, {200}) return _json.parse(response, aas_jsonization.get_path_items_result_from_jsonable)
[docs] def get_all_submodels_path( server: http.Server, *, semantic_id: Optional[aas_types.Reference] = None, id_short: Optional[str] = None, created_from: Optional[datetime.datetime] = None, updated_from: Optional[datetime.datetime] = None, limit: Optional[int] = None, cursor: Optional[str] = None, level: Optional[aas_types.Level] = None, ) -> aas_types.GetPathItemsResult: """ List a page of the ID-short paths of the elements of the submodels in the repository. Part 2 gives a single flat page of paths for all the matching submodels. The paths are relative to their submodels, and carry no identifier, so the paths of different submodels can not be told apart. Filter by :paramref:`id_short` or :paramref:`semantic_id` to narrow the page down, or use :py:func:`get_submodel_by_id_path` for a single submodel. The limit applies to the paths, not to the submodels. :param server: where to send the request :param semantic_id: if set, only the submodels with this semantic ID or supplemental semantic ID :param id_short: if set, only the submodels with this ID-short :param created_from: if set, only the submodels created at or after this time :param updated_from: if set, only the submodels updated at or after this time :param limit: maximum number of the paths in the page :param cursor: where to continue the listing from :param level: depth of the returned paths :returns: a page of the paths :implements GetAllSubmodels-Path: ``GET /submodels/$path`` """ request = _build_get_all_submodels_path( server.base_url, semantic_id=semantic_id, id_short=id_short, created_from=created_from, updated_from=updated_from, limit=limit, cursor=cursor, level=level, ) response = http.send(server.transport, request) return _parse_get_all_submodels_path(response)
def _build_get_submodel_by_id( base_url: str, submodel_identifier: str, *, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> http.Request: """Build the request of ``GetSubmodelById``.""" return _submodel_operations.build_get_submodel_by_id( base_url, _submodel_path(submodel_identifier), level=level, extent=extent ) def _parse_get_submodel_by_id(response: http.Response) -> aas_types.Submodel: """Parse the response of ``GetSubmodelById``.""" return _submodel_operations.parse_get_submodel_by_id(response)
[docs] def get_submodel_by_id( server: http.Server, submodel_identifier: str, *, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> aas_types.Submodel: """ Get the submodel with the given identifier. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param level: depth of the returned submodel :param extent: whether to include the values of blobs :returns: the submodel :implements GetSubmodelById: ``GET /submodels/{submodelIdentifier}`` """ request = _build_get_submodel_by_id( server.base_url, submodel_identifier, level=level, extent=extent ) response = http.send(server.transport, request) return _parse_get_submodel_by_id(response)
def _build_put_submodel_by_id( base_url: str, submodel_identifier: str, submodel: aas_types.Submodel ) -> http.Request: """Build the request of ``PutSubmodelById``.""" return _submodel_operations.build_put_submodel_by_id( base_url, _submodel_path(submodel_identifier), submodel ) def _parse_put_submodel_by_id(response: http.Response) -> None: """Parse the response of ``PutSubmodelById``. The server responds with 201 and the submodel if it created the submodel, or with 204 if it updated an existing one. We do not parse the submodel, since it is the one which the users sent.""" return _submodel_operations.parse_put_submodel_by_id(response)
[docs] def put_submodel_by_id( server: http.Server, submodel_identifier: str, submodel: aas_types.Submodel ) -> None: """ Create or replace the submodel with the given identifier. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param submodel: the submodel to be stored :implements PutSubmodelById: ``PUT /submodels/{submodelIdentifier}`` """ request = _build_put_submodel_by_id(server.base_url, submodel_identifier, submodel) response = http.send(server.transport, request) _parse_put_submodel_by_id(response)
def _build_patch_submodel_by_id( base_url: str, submodel_identifier: str, submodel: aas_types.Submodel ) -> http.Request: """Build the request of ``PatchSubmodelById``.""" return _submodel_operations.build_patch_submodel_by_id( base_url, _submodel_path(submodel_identifier), submodel ) def _parse_patch_submodel_by_id(response: http.Response) -> None: """Parse the response of ``PatchSubmodelById``.""" return _submodel_operations.parse_patch_submodel_by_id(response)
[docs] def patch_submodel_by_id( server: http.Server, submodel_identifier: str, submodel: aas_types.Submodel ) -> None: """ Update the existing submodel with the given identifier. Part 2 replaces the elements of the stored submodel one by one with the elements of :paramref:`submodel`, which must all exist on the server. The query parameter ``level`` is omitted, since it allows only the value ``core``. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param submodel: the submodel with the updates :implements PatchSubmodelById: ``PATCH /submodels/{submodelIdentifier}`` """ request = _build_patch_submodel_by_id( server.base_url, submodel_identifier, submodel ) response = http.send(server.transport, request) _parse_patch_submodel_by_id(response)
def _build_delete_submodel_by_id( base_url: str, submodel_identifier: str ) -> http.Request: """Build the request of ``DeleteSubmodelById``.""" return _submodel_operations.build_delete_submodel_by_id( base_url, _submodel_path(submodel_identifier) ) def _parse_delete_submodel_by_id(response: http.Response) -> None: """Parse the response of ``DeleteSubmodelById``.""" return _submodel_operations.parse_delete_submodel_by_id(response)
[docs] def delete_submodel_by_id(server: http.Server, submodel_identifier: str) -> None: """ Delete the submodel with the given identifier. :param server: where to send the request :param submodel_identifier: identifier of the submodel :implements DeleteSubmodelById: ``DELETE /submodels/{submodelIdentifier}`` """ request = _build_delete_submodel_by_id(server.base_url, submodel_identifier) response = http.send(server.transport, request) _parse_delete_submodel_by_id(response)
def _build_get_submodel_by_id_metadata( base_url: str, submodel_identifier: str ) -> http.Request: """Build the request of ``GetSubmodelById-Metadata``.""" return _submodel_operations.build_get_submodel_by_id_metadata( base_url, _submodel_path(submodel_identifier) ) def _parse_get_submodel_by_id_metadata( response: http.Response, ) -> aas_types.SubmodelMetadata: """Parse the response of ``GetSubmodelById-Metadata``.""" return _submodel_operations.parse_get_submodel_by_id_metadata(response)
[docs] def get_submodel_by_id_metadata( server: http.Server, submodel_identifier: str ) -> aas_types.SubmodelMetadata: """ Get the metadata of the submodel with the given identifier. :param server: where to send the request :param submodel_identifier: identifier of the submodel :returns: the metadata of the submodel :implements GetSubmodelById-Metadata: ``GET /submodels/{submodelIdentifier}/$metadata`` """ request = _build_get_submodel_by_id_metadata(server.base_url, submodel_identifier) response = http.send(server.transport, request) return _parse_get_submodel_by_id_metadata(response)
def _build_patch_submodel_by_id_metadata( base_url: str, submodel_identifier: str, submodel_metadata: aas_types.SubmodelMetadata, ) -> http.Request: """Build the request of ``PatchSubmodelById-Metadata``.""" return _submodel_operations.build_patch_submodel_by_id_metadata( base_url, _submodel_path(submodel_identifier), submodel_metadata ) def _parse_patch_submodel_by_id_metadata(response: http.Response) -> None: """Parse the response of ``PatchSubmodelById-Metadata``.""" return _submodel_operations.parse_patch_submodel_by_id_metadata(response)
[docs] def patch_submodel_by_id_metadata( server: http.Server, submodel_identifier: str, submodel_metadata: aas_types.SubmodelMetadata, ) -> None: """ Update the metadata of the submodel with the given identifier. The submodel elements remain unchanged. The query parameter ``level`` is omitted, since it allows only the value ``core``. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param submodel_metadata: the new metadata of the submodel :implements PatchSubmodelById-Metadata: ``PATCH /submodels/{submodelIdentifier}/$metadata`` """ request = _build_patch_submodel_by_id_metadata( server.base_url, submodel_identifier, submodel_metadata ) response = http.send(server.transport, request) _parse_patch_submodel_by_id_metadata(response)
def _build_get_submodel_by_id_reference( base_url: str, submodel_identifier: str ) -> http.Request: """Build the request of ``GetSubmodelById-Reference``.""" return _submodel_operations.build_get_submodel_by_id_reference( base_url, _submodel_path(submodel_identifier) ) def _parse_get_submodel_by_id_reference(response: http.Response) -> aas_types.Reference: """Parse the response of ``GetSubmodelById-Reference``.""" return _submodel_operations.parse_get_submodel_by_id_reference(response)
[docs] def get_submodel_by_id_reference( server: http.Server, submodel_identifier: str ) -> aas_types.Reference: """ Get a reference to the submodel with the given identifier. :param server: where to send the request :param submodel_identifier: identifier of the submodel :returns: the reference to the submodel :implements GetSubmodelById-Reference: ``GET /submodels/{submodelIdentifier}/$reference`` """ request = _build_get_submodel_by_id_reference(server.base_url, submodel_identifier) response = http.send(server.transport, request) return _parse_get_submodel_by_id_reference(response)
def _build_get_submodel_by_id_value_only( base_url: str, submodel_identifier: str, *, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> http.Request: """Build the request of ``GetSubmodelById-ValueOnly``.""" return _submodel_operations.build_get_submodel_by_id_value_only( base_url, _submodel_path(submodel_identifier), level=level, extent=extent ) def _parse_get_submodel_by_id_value_only( response: http.Response, ) -> aas_types.JsonObject: """Parse the response of ``GetSubmodelById-ValueOnly``.""" return _submodel_operations.parse_get_submodel_by_id_value_only(response)
[docs] def get_submodel_by_id_value_only( server: http.Server, submodel_identifier: str, *, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> aas_types.JsonObject: """ Get the values of the submodel with the given identifier. 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 :py:func:`get_submodel_by_id_metadata`, since the same JSON can stand for different kinds of elements; for example, a range looks exactly like a collection with the properties ``min`` and ``max``. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param level: depth of the returned values :param extent: whether to include the values of blobs :returns: the values of the submodel :implements GetSubmodelById-ValueOnly: ``GET /submodels/{submodelIdentifier}/$value`` """ request = _build_get_submodel_by_id_value_only( server.base_url, submodel_identifier, level=level, extent=extent ) response = http.send(server.transport, request) return _parse_get_submodel_by_id_value_only(response)
def _build_patch_submodel_by_id_value_only( base_url: str, submodel_identifier: str, submodel: aas_types.Submodel ) -> http.Request: """Build the request of ``PatchSubmodelById-ValueOnly``.""" return _submodel_operations.build_patch_submodel_by_id_value_only( base_url, _submodel_path(submodel_identifier), submodel ) def _parse_patch_submodel_by_id_value_only(response: http.Response) -> None: """Parse the response of ``PatchSubmodelById-ValueOnly``.""" return _submodel_operations.parse_patch_submodel_by_id_value_only(response)
[docs] def patch_submodel_by_id_value_only( server: http.Server, submodel_identifier: str, submodel: aas_types.Submodel ) -> None: """ Update the values of the submodel with the given identifier. The client sends only the values of :paramref:`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 ``level`` is omitted, since it allows only the value ``core``. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param submodel: the submodel with the new values :raises: :py:class:`ValueError` if a value of :paramref:`submodel` can not be serialized, such as a property ``xs:int`` with the value ``"abc"`` :implements PatchSubmodelById-ValueOnly: ``PATCH /submodels/{submodelIdentifier}/$value`` """ request = _build_patch_submodel_by_id_value_only( server.base_url, submodel_identifier, submodel ) response = http.send(server.transport, request) _parse_patch_submodel_by_id_value_only(response)
def _build_get_submodel_by_id_path( base_url: str, submodel_identifier: str, *, level: Optional[aas_types.Level] = None, ) -> http.Request: """Build the request of ``GetSubmodelById-Path``.""" return _submodel_operations.build_get_submodel_by_id_path( base_url, _submodel_path(submodel_identifier), level=level ) def _parse_get_submodel_by_id_path(response: http.Response) -> List[str]: """Parse the response of ``GetSubmodelById-Path``.""" return _submodel_operations.parse_get_submodel_by_id_path(response)
[docs] def get_submodel_by_id_path( server: http.Server, submodel_identifier: str, *, level: Optional[aas_types.Level] = None, ) -> List[str]: """ List the ID-short paths of the elements of the submodel. The paths start at the top-level elements, such as ``Motor`` and ``Motor.Speed``, since the submodel itself has no path. With :paramref:`level` set to core, only the paths of the top-level elements are listed. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param level: depth of the returned paths :returns: the paths :implements GetSubmodelById-Path: ``GET /submodels/{submodelIdentifier}/$path`` """ request = _build_get_submodel_by_id_path( server.base_url, submodel_identifier, level=level ) response = http.send(server.transport, request) return _parse_get_submodel_by_id_path(response)
def _build_get_all_submodel_elements( base_url: str, submodel_identifier: str, *, limit: Optional[int] = None, cursor: Optional[str] = None, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> http.Request: """Build the request of ``GetAllSubmodelElements_SubmodelRepository``.""" return _submodel_operations.build_get_all_submodel_elements( base_url, _submodel_path(submodel_identifier), limit=limit, cursor=cursor, level=level, extent=extent, ) def _parse_get_all_submodel_elements( response: http.Response, ) -> aas_types.GetSubmodelElementsResult: """Parse the response of ``GetAllSubmodelElements_SubmodelRepository``.""" return _submodel_operations.parse_get_all_submodel_elements(response)
[docs] def get_all_submodel_elements( server: http.Server, submodel_identifier: str, *, limit: Optional[int] = None, cursor: Optional[str] = None, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> aas_types.GetSubmodelElementsResult: """ List a page of the top-level submodel elements of the submodel. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param limit: maximum number of the submodel elements in the page :param cursor: where to continue the listing from :param level: depth of the returned submodel elements :param extent: whether to include the values of blobs :returns: a page of the submodel elements :implements GetAllSubmodelElements_SubmodelRepository: ``GET /submodels/{submodelIdentifier}/submodel-elements`` """ request = _build_get_all_submodel_elements( server.base_url, submodel_identifier, limit=limit, cursor=cursor, level=level, extent=extent, ) response = http.send(server.transport, request) return _parse_get_all_submodel_elements(response)
def _build_post_submodel_element( base_url: str, submodel_identifier: str, submodel_element: aas_types.SubmodelElement, ) -> http.Request: """Build the request of ``PostSubmodelElement_SubmodelRepo``.""" return _submodel_operations.build_post_submodel_element( base_url, _submodel_path(submodel_identifier), submodel_element ) def _parse_post_submodel_element(response: http.Response) -> aas_types.SubmodelElement: """Parse the response of ``PostSubmodelElement_SubmodelRepo``.""" return _submodel_operations.parse_post_submodel_element(response)
[docs] def post_submodel_element( server: http.Server, submodel_identifier: str, submodel_element: aas_types.SubmodelElement, ) -> aas_types.SubmodelElement: """ Add a new top-level submodel element to the submodel. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param submodel_element: the submodel element to be created :returns: the created submodel element, as stored by the server :implements PostSubmodelElement_SubmodelRepo: ``POST /submodels/{submodelIdentifier}/submodel-elements`` """ request = _build_post_submodel_element( server.base_url, submodel_identifier, submodel_element ) response = http.send(server.transport, request) return _parse_post_submodel_element(response)
def _build_get_all_submodel_elements_metadata( base_url: str, submodel_identifier: str, *, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> http.Request: """Build the request of ``GetAllSubmodelElements-Metadata_SubmodelRepo``.""" return _submodel_operations.build_get_all_submodel_elements_metadata( base_url, _submodel_path(submodel_identifier), limit=limit, cursor=cursor ) def _parse_get_all_submodel_elements_metadata( response: http.Response, ) -> aas_types.GetSubmodelElementsMetadataResult: """Parse the response of ``GetAllSubmodelElements-Metadata_SubmodelRepo``.""" return _submodel_operations.parse_get_all_submodel_elements_metadata(response)
[docs] def get_all_submodel_elements_metadata( server: http.Server, submodel_identifier: str, *, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> aas_types.GetSubmodelElementsMetadataResult: """ List a page of the metadata of the top-level submodel elements of the submodel. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param limit: maximum number of the submodel elements in the page :param cursor: where to continue the listing from :returns: a page of the metadata of the submodel elements :implements GetAllSubmodelElements-Metadata_SubmodelRepo: ``GET /submodels/{submodelIdentifier}/submodel-elements/$metadata`` """ request = _build_get_all_submodel_elements_metadata( server.base_url, submodel_identifier, limit=limit, cursor=cursor ) response = http.send(server.transport, request) return _parse_get_all_submodel_elements_metadata(response)
def _build_get_all_submodel_elements_value_only( base_url: str, submodel_identifier: str, *, limit: Optional[int] = None, cursor: Optional[str] = None, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> http.Request: """Build the request of ``GetAllSubmodelElements-ValueOnly_SubmodelRepo``.""" return _submodel_operations.build_get_all_submodel_elements_value_only( base_url, _submodel_path(submodel_identifier), limit=limit, cursor=cursor, level=level, extent=extent, ) def _parse_get_all_submodel_elements_value_only( response: http.Response, ) -> aas_types.GetSubmodelElementsValueResult: """Parse the response of ``GetAllSubmodelElements-ValueOnly_SubmodelRepo``.""" return _submodel_operations.parse_get_all_submodel_elements_value_only(response)
[docs] def get_all_submodel_elements_value_only( server: http.Server, submodel_identifier: str, *, limit: Optional[int] = None, cursor: Optional[str] = None, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> aas_types.GetSubmodelElementsValueResult: """ 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. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param limit: maximum number of the submodel elements in the page :param cursor: where to continue the listing from :param level: depth of the returned values :param extent: whether to include the values of blobs :returns: a page of the values of the submodel elements :implements GetAllSubmodelElements-ValueOnly_SubmodelRepo: ``GET /submodels/{submodelIdentifier}/submodel-elements/$value`` """ request = _build_get_all_submodel_elements_value_only( server.base_url, submodel_identifier, limit=limit, cursor=cursor, level=level, extent=extent, ) response = http.send(server.transport, request) return _parse_get_all_submodel_elements_value_only(response)
def _build_get_all_submodel_elements_reference( base_url: str, submodel_identifier: str, *, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> http.Request: """Build the request of ``GetAllSubmodelElements-Reference_SubmodelRepo``.""" return _submodel_operations.build_get_all_submodel_elements_reference( base_url, _submodel_path(submodel_identifier), limit=limit, cursor=cursor ) def _parse_get_all_submodel_elements_reference( response: http.Response, ) -> aas_types.GetReferencesResult: """Parse the response of ``GetAllSubmodelElements-Reference_SubmodelRepo``.""" return _submodel_operations.parse_get_all_submodel_elements_reference(response)
[docs] def get_all_submodel_elements_reference( server: http.Server, submodel_identifier: str, *, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> aas_types.GetReferencesResult: """ List a page of the references to the top-level submodel elements of the submodel. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param limit: maximum number of the references in the page :param cursor: where to continue the listing from :returns: a page of the references :implements GetAllSubmodelElements-Reference_SubmodelRepo: ``GET /submodels/{submodelIdentifier}/submodel-elements/$reference`` """ request = _build_get_all_submodel_elements_reference( server.base_url, submodel_identifier, limit=limit, cursor=cursor ) response = http.send(server.transport, request) return _parse_get_all_submodel_elements_reference(response)
def _build_get_all_submodel_elements_path( base_url: str, submodel_identifier: str, *, limit: Optional[int] = None, cursor: Optional[str] = None, level: Optional[aas_types.Level] = None, ) -> http.Request: """Build the request of ``GetAllSubmodelElements-Path_SubmodelRepo``.""" return _submodel_operations.build_get_all_submodel_elements_path( base_url, _submodel_path(submodel_identifier), limit=limit, cursor=cursor, level=level, ) def _parse_get_all_submodel_elements_path( response: http.Response, ) -> aas_types.GetPathItemsResult: """Parse the response of ``GetAllSubmodelElements-Path_SubmodelRepo``.""" return _submodel_operations.parse_get_all_submodel_elements_path(response)
[docs] def get_all_submodel_elements_path( server: http.Server, submodel_identifier: str, *, limit: Optional[int] = None, cursor: Optional[str] = None, level: Optional[aas_types.Level] = None, ) -> aas_types.GetPathItemsResult: """ 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. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param limit: maximum number of the paths in the page :param cursor: where to continue the listing from :param level: depth of the returned paths :returns: a page of the paths :implements GetAllSubmodelElements-Path_SubmodelRepo: ``GET /submodels/{submodelIdentifier}/submodel-elements/$path`` """ request = _build_get_all_submodel_elements_path( server.base_url, submodel_identifier, limit=limit, cursor=cursor, level=level ) response = http.send(server.transport, request) return _parse_get_all_submodel_elements_path(response)
def _build_get_submodel_element_by_path( base_url: str, submodel_identifier: str, id_short_path: str, *, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> http.Request: """Build the request of ``GetSubmodelElementByPath_SubmodelRepo``.""" return _submodel_operations.build_get_submodel_element_by_path( base_url, _submodel_path(submodel_identifier), id_short_path, level=level, extent=extent, ) def _parse_get_submodel_element_by_path( response: http.Response, ) -> aas_types.SubmodelElement: """Parse the response of ``GetSubmodelElementByPath_SubmodelRepo``.""" return _submodel_operations.parse_get_submodel_element_by_path(response)
[docs] def get_submodel_element_by_path( server: http.Server, submodel_identifier: str, id_short_path: str, *, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> aas_types.SubmodelElement: """ Get the submodel element at the given ID-short path. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the element, such as ``Motor.Speed`` :param level: depth of the returned element :param extent: whether to include the values of blobs :returns: the submodel element :implements GetSubmodelElementByPath_SubmodelRepo: ``GET /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}`` """ request = _build_get_submodel_element_by_path( server.base_url, submodel_identifier, id_short_path, level=level, extent=extent ) response = http.send(server.transport, request) return _parse_get_submodel_element_by_path(response)
def _build_post_submodel_element_by_path( base_url: str, submodel_identifier: str, id_short_path: str, submodel_element: aas_types.SubmodelElement, ) -> http.Request: """Build the request of ``PostSubmodelElementByPath_SubmodelRepo``.""" return _submodel_operations.build_post_submodel_element_by_path( base_url, _submodel_path(submodel_identifier), id_short_path, submodel_element ) def _parse_post_submodel_element_by_path( response: http.Response, ) -> aas_types.SubmodelElement: """Parse the response of ``PostSubmodelElementByPath_SubmodelRepo``.""" return _submodel_operations.parse_post_submodel_element_by_path(response)
[docs] def post_submodel_element_by_path( server: http.Server, submodel_identifier: str, id_short_path: str, submodel_element: aas_types.SubmodelElement, ) -> aas_types.SubmodelElement: """ Add a new submodel element as a child of the element at the given ID-short path. The element at :paramref:`id_short_path` must be able to hold children, such as a submodel element collection, a submodel element list or an entity. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the parent element :param submodel_element: the submodel element to be created :returns: the created submodel element, as stored by the server :implements PostSubmodelElementByPath_SubmodelRepo: ``POST /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}`` """ request = _build_post_submodel_element_by_path( server.base_url, submodel_identifier, id_short_path, submodel_element ) response = http.send(server.transport, request) return _parse_post_submodel_element_by_path(response)
def _build_put_submodel_element_by_path( base_url: str, submodel_identifier: str, id_short_path: str, submodel_element: aas_types.SubmodelElement, ) -> http.Request: """Build the request of ``PutSubmodelElementByPath_SubmodelRepo``.""" return _submodel_operations.build_put_submodel_element_by_path( base_url, _submodel_path(submodel_identifier), id_short_path, submodel_element ) def _parse_put_submodel_element_by_path(response: http.Response) -> None: """Parse the response of ``PutSubmodelElementByPath_SubmodelRepo``. The server responds with 201 and the element if it created the element, or with 204 if it updated an existing one. We do not parse the element, since it is the one which the users sent.""" return _submodel_operations.parse_put_submodel_element_by_path(response)
[docs] def put_submodel_element_by_path( server: http.Server, submodel_identifier: str, id_short_path: str, submodel_element: aas_types.SubmodelElement, ) -> None: """ Create or replace the submodel element at the given ID-short path. The query parameter ``level`` is omitted, since it allows only the value ``deep``. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the element :param submodel_element: the submodel element to be stored :implements PutSubmodelElementByPath_SubmodelRepo: ``PUT /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}`` """ request = _build_put_submodel_element_by_path( server.base_url, submodel_identifier, id_short_path, submodel_element ) response = http.send(server.transport, request) _parse_put_submodel_element_by_path(response)
def _build_patch_submodel_element_by_path( base_url: str, submodel_identifier: str, id_short_path: str, submodel_element: aas_types.SubmodelElement, ) -> http.Request: """Build the request of ``PatchSubmodelElementByPath_SubmodelRepo``.""" return _submodel_operations.build_patch_submodel_element_by_path( base_url, _submodel_path(submodel_identifier), id_short_path, submodel_element ) def _parse_patch_submodel_element_by_path(response: http.Response) -> None: """Parse the response of ``PatchSubmodelElementByPath_SubmodelRepo``.""" return _submodel_operations.parse_patch_submodel_element_by_path(response)
[docs] def patch_submodel_element_by_path( server: http.Server, submodel_identifier: str, id_short_path: str, submodel_element: aas_types.SubmodelElement, ) -> None: """ Update the existing submodel element at the given ID-short path. Part 2 replaces the stored element and its children one by one with :paramref:`submodel_element` and its children, which must all exist on the server. The query parameter ``level`` is omitted, since it allows only the value ``core``. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the element :param submodel_element: the submodel element with the updates :implements PatchSubmodelElementByPath_SubmodelRepo: ``PATCH /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}`` """ request = _build_patch_submodel_element_by_path( server.base_url, submodel_identifier, id_short_path, submodel_element ) response = http.send(server.transport, request) _parse_patch_submodel_element_by_path(response)
def _build_delete_submodel_element_by_path( base_url: str, submodel_identifier: str, id_short_path: str ) -> http.Request: """Build the request of ``DeleteSubmodelElementByPath_SubmodelRepo``.""" return _submodel_operations.build_delete_submodel_element_by_path( base_url, _submodel_path(submodel_identifier), id_short_path ) def _parse_delete_submodel_element_by_path(response: http.Response) -> None: """Parse the response of ``DeleteSubmodelElementByPath_SubmodelRepo``.""" return _submodel_operations.parse_delete_submodel_element_by_path(response)
[docs] def delete_submodel_element_by_path( server: http.Server, submodel_identifier: str, id_short_path: str ) -> None: """ Delete the submodel element at the given ID-short path. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the element :implements DeleteSubmodelElementByPath_SubmodelRepo: ``DELETE /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}`` """ request = _build_delete_submodel_element_by_path( server.base_url, submodel_identifier, id_short_path ) response = http.send(server.transport, request) _parse_delete_submodel_element_by_path(response)
def _build_get_submodel_element_by_path_metadata( base_url: str, submodel_identifier: str, id_short_path: str ) -> http.Request: """Build the request of ``GetSubmodelElementByPath-Metadata_SubmodelRepo``.""" return _submodel_operations.build_get_submodel_element_by_path_metadata( base_url, _submodel_path(submodel_identifier), id_short_path ) def _parse_get_submodel_element_by_path_metadata( response: http.Response, ) -> aas_types.SubmodelElementMetadata: """Parse the response of ``GetSubmodelElementByPath-Metadata_SubmodelRepo``.""" return _submodel_operations.parse_get_submodel_element_by_path_metadata(response)
[docs] def get_submodel_element_by_path_metadata( server: http.Server, submodel_identifier: str, id_short_path: str ) -> aas_types.SubmodelElementMetadata: """ Get the metadata of the submodel element at the given ID-short path. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the element, such as ``Motor.Speed`` :returns: the metadata of the submodel element :implements GetSubmodelElementByPath-Metadata_SubmodelRepo: ``GET /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/$metadata`` """ request = _build_get_submodel_element_by_path_metadata( server.base_url, submodel_identifier, id_short_path ) response = http.send(server.transport, request) return _parse_get_submodel_element_by_path_metadata(response)
def _build_patch_submodel_element_by_path_metadata( base_url: str, submodel_identifier: str, id_short_path: str, submodel_element_metadata: aas_types.SubmodelElementMetadata, ) -> http.Request: """Build the request of ``PatchSubmodelElementByPath-Metadata_SubmodelRepo``.""" return _submodel_operations.build_patch_submodel_element_by_path_metadata( base_url, _submodel_path(submodel_identifier), id_short_path, submodel_element_metadata, ) def _parse_patch_submodel_element_by_path_metadata(response: http.Response) -> None: """Parse the response of ``PatchSubmodelElementByPath-Metadata_SubmodelRepo``.""" return _submodel_operations.parse_patch_submodel_element_by_path_metadata(response)
[docs] def patch_submodel_element_by_path_metadata( server: http.Server, submodel_identifier: str, id_short_path: str, submodel_element_metadata: aas_types.SubmodelElementMetadata, ) -> None: """ Update the metadata of the submodel element at the given ID-short path. The value of the element remains unchanged. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the element :param submodel_element_metadata: the new metadata of the submodel element :implements PatchSubmodelElementByPath-Metadata_SubmodelRepo: ``PATCH /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/$metadata`` """ request = _build_patch_submodel_element_by_path_metadata( server.base_url, submodel_identifier, id_short_path, submodel_element_metadata ) response = http.send(server.transport, request) _parse_patch_submodel_element_by_path_metadata(response)
def _build_get_submodel_element_by_path_value_only( base_url: str, submodel_identifier: str, id_short_path: str, *, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> http.Request: """Build the request of ``GetSubmodelElementByPath-ValueOnly_SubmodelRepo``.""" return _submodel_operations.build_get_submodel_element_by_path_value_only( base_url, _submodel_path(submodel_identifier), id_short_path, level=level, extent=extent, ) def _parse_get_submodel_element_by_path_value_only( response: http.Response, ) -> aas_types.JsonValue: """Parse the response of ``GetSubmodelElementByPath-ValueOnly_SubmodelRepo``.""" return _submodel_operations.parse_get_submodel_element_by_path_value_only(response)
[docs] def get_submodel_element_by_path_value_only( server: http.Server, submodel_identifier: str, id_short_path: str, *, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> aas_types.JsonValue: """ 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, ``5`` for a property ``xs: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 properties ``min`` and ``max``. If you know the kind, you can parse some kinds with aas-core3.2, for example, a range with :py:func:`aas_core3_2.jsonization.range_value_from_jsonable`. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the element, such as ``Motor.Speed`` :param level: depth of the returned value :param extent: whether to include the values of blobs :returns: the value of the submodel element :implements GetSubmodelElementByPath-ValueOnly_SubmodelRepo: ``GET /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/$value`` """ request = _build_get_submodel_element_by_path_value_only( server.base_url, submodel_identifier, id_short_path, level=level, extent=extent ) response = http.send(server.transport, request) return _parse_get_submodel_element_by_path_value_only(response)
def _build_patch_submodel_element_by_path_value_only( base_url: str, submodel_identifier: str, id_short_path: str, submodel_element: aas_types.SubmodelElement, ) -> http.Request: """Build the request of ``PatchSubmodelElementByPath-ValueOnly_SubmodelRepo``.""" return _submodel_operations.build_patch_submodel_element_by_path_value_only( base_url, _submodel_path(submodel_identifier), id_short_path, submodel_element ) def _parse_patch_submodel_element_by_path_value_only(response: http.Response) -> None: """Parse the response of ``PatchSubmodelElementByPath-ValueOnly_SubmodelRepo``.""" return _submodel_operations.parse_patch_submodel_element_by_path_value_only( response )
[docs] def patch_submodel_element_by_path_value_only( server: http.Server, submodel_identifier: str, id_short_path: str, submodel_element: aas_types.SubmodelElement, ) -> None: """ Update the value of the submodel element at the given ID-short path. The client sends only the value of :paramref:`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 ``level`` is omitted, since it allows only the value ``core``. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the element :param submodel_element: the submodel element with the new value :raises: :py:class:`ValueError` if :paramref:`submodel_element` is an operation or a capability, which have no value, or if its value can not be serialized, such as a property ``xs:int`` with the value ``"abc"`` :implements PatchSubmodelElementByPath-ValueOnly_SubmodelRepo: ``PATCH /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/$value`` """ request = _build_patch_submodel_element_by_path_value_only( server.base_url, submodel_identifier, id_short_path, submodel_element ) response = http.send(server.transport, request) _parse_patch_submodel_element_by_path_value_only(response)
def _build_get_submodel_element_by_path_reference( base_url: str, submodel_identifier: str, id_short_path: str ) -> http.Request: """Build the request of ``GetSubmodelElementByPath-Reference_SubmodelRepo``.""" return _submodel_operations.build_get_submodel_element_by_path_reference( base_url, _submodel_path(submodel_identifier), id_short_path ) def _parse_get_submodel_element_by_path_reference( response: http.Response, ) -> aas_types.Reference: """Parse the response of ``GetSubmodelElementByPath-Reference_SubmodelRepo``.""" return _submodel_operations.parse_get_submodel_element_by_path_reference(response)
[docs] def get_submodel_element_by_path_reference( server: http.Server, submodel_identifier: str, id_short_path: str ) -> aas_types.Reference: """ 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``. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the element, such as ``Motor.Speed`` :returns: the reference to the submodel element :implements GetSubmodelElementByPath-Reference_SubmodelRepo: ``GET /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/$reference`` """ request = _build_get_submodel_element_by_path_reference( server.base_url, submodel_identifier, id_short_path ) response = http.send(server.transport, request) return _parse_get_submodel_element_by_path_reference(response)
def _build_get_submodel_element_by_path_path( base_url: str, submodel_identifier: str, id_short_path: str, *, level: Optional[aas_types.Level] = None, ) -> http.Request: """Build the request of ``GetSubmodelElementByPath-Path_SubmodelRepo``.""" return _submodel_operations.build_get_submodel_element_by_path_path( base_url, _submodel_path(submodel_identifier), id_short_path, level=level ) def _parse_get_submodel_element_by_path_path(response: http.Response) -> List[str]: """Parse the response of ``GetSubmodelElementByPath-Path_SubmodelRepo``.""" return _submodel_operations.parse_get_submodel_element_by_path_path(response)
[docs] def get_submodel_element_by_path_path( server: http.Server, submodel_identifier: str, id_short_path: str, *, level: Optional[aas_types.Level] = None, ) -> List[str]: """ List the ID-short paths of the submodel element and of its descendants. The paths include the path of the element itself. With :paramref:`level` set to core, only the paths of the element and of its direct children are listed. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the element, such as ``Motor.Speed`` :param level: depth of the returned paths :returns: the paths :implements GetSubmodelElementByPath-Path_SubmodelRepo: ``GET /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/$path`` """ request = _build_get_submodel_element_by_path_path( server.base_url, submodel_identifier, id_short_path, level=level ) response = http.send(server.transport, request) return _parse_get_submodel_element_by_path_path(response)
def _build_get_file_by_path( base_url: str, submodel_identifier: str, id_short_path: str ) -> http.Request: """Build the request of ``GetFileByPath_SubmodelRepo``.""" return _submodel_operations.build_get_file_by_path( base_url, _submodel_path(submodel_identifier), id_short_path )
[docs] def get_file_by_path( server: http.Server, submodel_identifier: str, id_short_path: str ) -> ContextManager[http.Download]: """ 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: .. code-block:: python with submodel_repository.get_file_by_path( server, "urn:example:submodel:1", "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. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the file element, such as ``Manual`` :returns: a context manager which gives the download :raises: :py:class:`~aas_client3_2.errors.MethodNotAllowed` if the element is not a file element :implements GetFileByPath_SubmodelRepo: ``GET /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/attachment`` """ request = _build_get_file_by_path( server.base_url, submodel_identifier, id_short_path ) return _files.download(server, request, {200})
def _build_put_file_by_path( base_url: str, submodel_identifier: str, id_short_path: str, content: Union[bytes, IO[bytes]], *, file_name: Optional[str] = None, content_type: Optional[str] = None, ) -> http.Request: """Build the request of ``PutFileByPath_SubmodelRepo``.""" return _submodel_operations.build_put_file_by_path( base_url, _submodel_path(submodel_identifier), id_short_path, content, file_name=file_name, content_type=content_type, ) def _parse_put_file_by_path(response: http.Response) -> None: """Parse the response of ``PutFileByPath_SubmodelRepo``.""" return _submodel_operations.parse_put_file_by_path(response)
[docs] def put_file_by_path( server: http.Server, submodel_identifier: str, id_short_path: str, content: Union[bytes, IO[bytes]], *, file_name: Optional[str] = None, content_type: Optional[str] = None, ) -> None: """ 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. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the file element, such as ``Manual`` :param content: content of the file :param file_name: if set, the name of the file :param content_type: if set, the content type of the file, such as ``application/pdf``, otherwise ``application/octet-stream``. The servers may take it as the new content type of the file element. :raises: :py:class:`TypeError` before sending anything if the content is neither bytes nor a binary file object; :py:class:`ValueError` before 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; :py:class:`~aas_client3_2.errors.MethodNotAllowed` if the element is not a file element :implements PutFileByPath_SubmodelRepo: ``PUT /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/attachment`` """ request = _build_put_file_by_path( server.base_url, submodel_identifier, id_short_path, content, file_name=file_name, content_type=content_type, ) response = http.send(server.transport, request) _parse_put_file_by_path(response)
def _build_delete_file_by_path( base_url: str, submodel_identifier: str, id_short_path: str ) -> http.Request: """Build the request of ``DeleteFileByPath_SubmodelRepo``.""" return _submodel_operations.build_delete_file_by_path( base_url, _submodel_path(submodel_identifier), id_short_path ) def _parse_delete_file_by_path(response: http.Response) -> None: """Parse the response of ``DeleteFileByPath_SubmodelRepo``.""" return _submodel_operations.parse_delete_file_by_path(response)
[docs] def delete_file_by_path( server: http.Server, submodel_identifier: str, id_short_path: str ) -> None: """ Delete the content of the file element at the given ID-short path. The file element itself stays. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the file element, such as ``Manual`` :implements DeleteFileByPath_SubmodelRepo: ``DELETE /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/attachment`` """ request = _build_delete_file_by_path( server.base_url, submodel_identifier, id_short_path ) response = http.send(server.transport, request) _parse_delete_file_by_path(response)
def _build_invoke_operation( base_url: str, submodel_identifier: str, id_short_path: str, operation_request: aas_types.OperationRequest, ) -> http.Request: """Build the request of ``InvokeOperation_SubmodelRepo``.""" return _submodel_operations.build_invoke_operation( base_url, _submodel_path(submodel_identifier), id_short_path, operation_request ) def _parse_invoke_operation(response: http.Response) -> aas_types.OperationResult: """Parse the response of ``InvokeOperation_SubmodelRepo``.""" return _submodel_operations.parse_invoke_operation(response)
[docs] def invoke_operation( server: http.Server, submodel_identifier: str, id_short_path: str, operation_request: aas_types.OperationRequest, ) -> aas_types.OperationResult: """ 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_duration`` of :paramref:`operation_request`, such as ``PT30S``, to tell the server how long the client waits; the timeout of the transport should be longer. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the operation, such as ``Control.Start`` :param operation_request: the input and in-output arguments :returns: the result of the operation; check its ``execution_state`` and ``success``, since a failed operation still gives a result :raises: :py:class:`~aas_client3_2.errors.MethodNotAllowed` if the element is not an operation :implements InvokeOperation_SubmodelRepo: ``POST /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/invoke`` """ request = _build_invoke_operation( server.base_url, submodel_identifier, id_short_path, operation_request ) response = http.send(server.transport, request) return _parse_invoke_operation(response)
def _build_invoke_operation_value_only( base_url: str, submodel_identifier: str, id_short_path: str, operation_request: aas_types.OperationRequestValueOnly, ) -> http.Request: """Build the request of ``InvokeOperation-ValueOnly_SubmodelRepository``.""" return _submodel_operations.build_invoke_operation_value_only( base_url, _submodel_path(submodel_identifier), id_short_path, operation_request ) def _parse_invoke_operation_value_only( response: http.Response, ) -> aas_types.OperationResultValueOnly: """Parse the response of ``InvokeOperation-ValueOnly_SubmodelRepository``.""" return _submodel_operations.parse_invoke_operation_value_only(response)
[docs] def invoke_operation_value_only( server: http.Server, submodel_identifier: str, id_short_path: str, operation_request: aas_types.OperationRequestValueOnly, ) -> aas_types.OperationResultValueOnly: """ 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. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the operation, such as ``Control.Start`` :param operation_request: the input and in-output arguments :returns: the result of the operation :raises: :py:class:`~aas_client3_2.errors.MethodNotAllowed` if the element is not an operation :implements InvokeOperation-ValueOnly_SubmodelRepository: ``POST /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/invoke/$value`` """ request = _build_invoke_operation_value_only( server.base_url, submodel_identifier, id_short_path, operation_request ) response = http.send(server.transport, request) return _parse_invoke_operation_value_only(response)
def _build_invoke_operation_async( base_url: str, submodel_identifier: str, id_short_path: str, operation_request: aas_types.OperationRequestAsync, ) -> http.Request: """Build the request of ``InvokeOperationAsync_SubmodelRepository``.""" return _submodel_operations.build_invoke_operation_async( base_url, _submodel_path(submodel_identifier), id_short_path, operation_request ) def _parse_invoke_operation_async(response: http.Response) -> aas_types.OperationHandle: """Parse the response of ``InvokeOperationAsync_SubmodelRepository``.""" return _submodel_operations.parse_invoke_operation_async(response)
[docs] def invoke_operation_async( server: http.Server, submodel_identifier: str, id_short_path: str, operation_request: aas_types.OperationRequestAsync, ) -> aas_types.OperationHandle: """ Start the operation at the given ID-short path on the server, and return at once. Poll :py:func:`get_operation_async_status` with the handle until the operation is finished, and then fetch :py:func:`get_operation_async_result`: .. code-block:: python handle = submodel_repository.invoke_operation_async( server, "urn:example:submodel:1", "Control.Start", aas_types.OperationRequestAsync(client_timeout_duration="PT60S"), ) while True: status = submodel_repository.get_operation_async_status( server, "urn:example:submodel:1", "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_repository.get_operation_async_result( server, "urn:example:submodel:1", "Control.Start", handle.handle_id ) Note that the server may accept an invocation which fails later. The failure then shows in the result. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the operation, such as ``Control.Start`` :param operation_request: the arguments, and how long the client waits at most :returns: the handle of the invocation, as given in the header ``Location`` :raises: :py:class:`~aas_client3_2.errors.MethodNotAllowed` if the element is not an operation :implements InvokeOperationAsync_SubmodelRepository: ``POST /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/invoke-async`` """ request = _build_invoke_operation_async( server.base_url, submodel_identifier, id_short_path, operation_request ) response = http.send(server.transport, request) return _parse_invoke_operation_async(response)
def _build_invoke_operation_async_value_only( base_url: str, submodel_identifier: str, id_short_path: str, operation_request: aas_types.OperationRequestAsyncValueOnly, ) -> http.Request: """Build the request of ``InvokeOperationAsync-ValueOnly_SubmodelRepository``.""" return _submodel_operations.build_invoke_operation_async_value_only( base_url, _submodel_path(submodel_identifier), id_short_path, operation_request ) def _parse_invoke_operation_async_value_only( response: http.Response, ) -> aas_types.OperationHandle: """Parse the response of ``InvokeOperationAsync-ValueOnly_SubmodelRepository``.""" return _submodel_operations.parse_invoke_operation_async_value_only(response)
[docs] def invoke_operation_async_value_only( server: http.Server, submodel_identifier: str, id_short_path: str, operation_request: aas_types.OperationRequestAsyncValueOnly, ) -> aas_types.OperationHandle: """ Start the operation with the arguments in Value-Only, and return at once. See :py:func:`invoke_operation_async` for how to poll the status; fetch the result with :py:func:`get_operation_async_result_value_only`. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the operation, such as ``Control.Start`` :param operation_request: the arguments, and how long the client waits at most :returns: the handle of the invocation, as given in the header ``Location`` :implements InvokeOperationAsync-ValueOnly_SubmodelRepository: ``POST /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/invoke-async/$value`` """ request = _build_invoke_operation_async_value_only( server.base_url, submodel_identifier, id_short_path, operation_request ) response = http.send(server.transport, request) return _parse_invoke_operation_async_value_only(response)
def _build_get_operation_async_status( base_url: str, submodel_identifier: str, id_short_path: str, handle_id: str ) -> http.Request: """Build the request of ``GetOperationAsyncStatus_SubmodelRepository``.""" return _submodel_operations.build_get_operation_async_status( base_url, _submodel_path(submodel_identifier), id_short_path, handle_id ) def _parse_get_operation_async_status( response: http.Response, ) -> Union[aas_types.BaseOperationResult, str]: """Parse the response of ``GetOperationAsyncStatus_SubmodelRepository``. :returns: the status, or the location of the result if the transport did not follow the redirect to it""" return _submodel_operations.parse_get_operation_async_status(response)
[docs] def get_operation_async_status( server: http.Server, submodel_identifier: str, id_short_path: str, handle_id: str ) -> aas_types.BaseOperationResult: """ 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_state`` tells whether the operation completed, failed or timed out. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the operation, such as ``Control.Start`` :param handle_id: handle as given by :py:func:`invoke_operation_async` :returns: the status of the invocation :raises: :py:class:`~aas_client3_2.errors.NotFound` if there is no such invocation; :py:class:`~aas_client3_2.errors.UnexpectedResponse` if the server redirects to another origin :implements GetOperationAsyncStatus_SubmodelRepository: ``GET /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/operation-status/{handleId}`` """ request = _build_get_operation_async_status( server.base_url, submodel_identifier, id_short_path, handle_id ) response = http.send(server.transport, request) status = _parse_get_operation_async_status(response) if not isinstance(status, str): return status try: url = _invocation.resolve_result_url(server.base_url, request.url, status) except ValueError as exception: raise errors.UnexpectedResponse(response, exception) from exception followed = http.send(server.transport, _invocation.build_follow_request(url)) return _invocation.parse_followed(followed)
def _build_get_operation_async_result( base_url: str, submodel_identifier: str, id_short_path: str, handle_id: str ) -> http.Request: """Build the request of ``GetOperationAsyncResult_SubmodelRepository``.""" return _submodel_operations.build_get_operation_async_result( base_url, _submodel_path(submodel_identifier), id_short_path, handle_id ) def _parse_get_operation_async_result( response: http.Response, ) -> aas_types.OperationResult: """Parse the response of ``GetOperationAsyncResult_SubmodelRepository``.""" return _submodel_operations.parse_get_operation_async_result(response)
[docs] def get_operation_async_result( server: http.Server, submodel_identifier: str, id_short_path: str, handle_id: str ) -> aas_types.OperationResult: """ Get the result of the finished asynchronous invocation with the given handle. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the operation, such as ``Control.Start`` :param handle_id: handle as given by :py:func:`invoke_operation_async` :returns: the result of the operation; a failed operation still gives a result, with ``execution_state`` set to ``Failed`` :raises: :py:class:`~aas_client3_2.errors.NotFound` if there is no such invocation :implements GetOperationAsyncResult_SubmodelRepository: ``GET /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/operation-results/{handleId}`` """ request = _build_get_operation_async_result( server.base_url, submodel_identifier, id_short_path, handle_id ) response = http.send(server.transport, request) return _parse_get_operation_async_result(response)
def _build_get_operation_async_result_value_only( base_url: str, submodel_identifier: str, id_short_path: str, handle_id: str ) -> http.Request: """Build the request of ``GetOperationAsyncResult-ValueOnly_SubmodelRepository``.""" return _submodel_operations.build_get_operation_async_result_value_only( base_url, _submodel_path(submodel_identifier), id_short_path, handle_id ) def _parse_get_operation_async_result_value_only( response: http.Response, ) -> aas_types.OperationResultValueOnly: """ Parse the response of ``GetOperationAsyncResult-ValueOnly_SubmodelRepository``. """ return _submodel_operations.parse_get_operation_async_result_value_only(response)
[docs] def get_operation_async_result_value_only( server: http.Server, submodel_identifier: str, id_short_path: str, handle_id: str ) -> aas_types.OperationResultValueOnly: """ Get the result of the finished asynchronous invocation in Value-Only. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param id_short_path: ID-short path of the operation, such as ``Control.Start`` :param handle_id: handle as given by :py:func:`invoke_operation_async` or :py:func:`invoke_operation_async_value_only` :returns: the result of the operation :raises: :py:class:`~aas_client3_2.errors.NotFound` if there is no such invocation :implements GetOperationAsyncResult-ValueOnly_SubmodelRepository: ``GET /submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/operation-results/{handleId}/$value`` """ request = _build_get_operation_async_result_value_only( server.base_url, submodel_identifier, id_short_path, handle_id ) response = http.send(server.transport, request) return _parse_get_operation_async_result_value_only(response)
def _build_get_submodel_version_by_id_and_date( base_url: str, submodel_identifier: str, *, date: Optional[datetime.datetime] = None, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> http.Request: """Build the request of ``GetSubmodelVersionByIdAndDate``.""" return _json.build_request( "GET", http.build_url( base_url, _submodel_path(submodel_identifier) + "/$history", _query.modifiers(level, extent) + _query.date(date), ), ) def _parse_get_submodel_version_by_id_and_date( response: http.Response, ) -> aas_types.Submodel: """Parse the response of ``GetSubmodelVersionByIdAndDate``.""" errors.raise_for_unexpected_status(response, {200}) return _json.parse(response, aas_jsonization.submodel_from_jsonable)
[docs] def get_submodel_version_by_id_and_date( server: http.Server, submodel_identifier: str, *, date: Optional[datetime.datetime] = None, level: Optional[aas_types.Level] = None, extent: Optional[aas_types.Extent] = None, ) -> aas_types.Submodel: """ Get the version of the submodel which was valid at the given point in time. The version is not the attribute ``version`` of the administrative information, but the state of the submodel as stored by the server; which changes make a new version is up to the server. :param server: where to send the request :param submodel_identifier: identifier of the submodel :param date: point in time with a time zone; if not set, the server gives the latest version :param level: depth of the returned submodel :param extent: whether to include the values of blobs :returns: the version of the submodel :raises: :py:class:`ValueError` before sending anything if :paramref:`date` has no time zone; :py:class:`~aas_client3_2.errors.NotFound` if there was no such submodel at that point in time :implements GetSubmodelVersionByIdAndDate: ``GET /submodels/{submodelIdentifier}/$history`` """ request = _build_get_submodel_version_by_id_and_date( server.base_url, submodel_identifier, date=date, level=level, extent=extent ) response = http.send(server.transport, request) return _parse_get_submodel_version_by_id_and_date(response)
def _build_get_submodel_by_id_signed( base_url: str, submodel_identifier: str ) -> http.Request: """Build the request of ``GetSubmodelByIdSigned``.""" return _signed.build_request( http.build_url(base_url, _submodel_path(submodel_identifier) + "/$signed") ) def _parse_get_submodel_by_id_signed(response: http.Response) -> str: """Parse the response of ``GetSubmodelByIdSigned``.""" return _signed.parse(response)
[docs] def get_submodel_by_id_signed(server: http.Server, submodel_identifier: str) -> str: """ Get the submodel with the given identifier, signed by the server. The submodel is the payload of a JSON Web Signature (JWS, RFC 7515), signed with RS256, with the certificate chain of the signing key in the header ``x5c``. The client does not verify the signature, since only the users know which certificates they trust. Verify it with a JWS library, and parse the verified payload with :py:func:`aas_core3_2.jsonization.submodel_from_jsonable`. :param server: where to send the request :param submodel_identifier: identifier of the submodel :returns: the JWS in the compact serialization :implements GetSubmodelByIdSigned: ``GET /submodels/{submodelIdentifier}/$signed`` """ request = _build_get_submodel_by_id_signed(server.base_url, submodel_identifier) response = http.send(server.transport, request) return _parse_get_submodel_by_id_signed(response)
def _build_get_all_submodels_recent_changes( base_url: str, *, semantic_id: Optional[aas_types.Reference] = None, id_short: Optional[str] = None, created_from: Optional[datetime.datetime] = None, updated_from: Optional[datetime.datetime] = None, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> http.Request: """Build the request of ``GetAllSubmodelsRecentChanges``.""" return _json.build_request( "GET", http.build_url( base_url, "/submodels/$recent-changes", _query_of_submodels( semantic_id, id_short, created_from, updated_from, limit, cursor ), ), ) def _parse_get_all_submodels_recent_changes( response: http.Response, ) -> aas_types.GetAllSubmodelsRecentChangesResult: """Parse the response of ``GetAllSubmodelsRecentChanges``.""" errors.raise_for_unexpected_status(response, {200}) return _json.parse( response, aas_jsonization.get_all_submodels_recent_changes_result_from_jsonable )
[docs] def get_all_submodels_recent_changes( server: http.Server, *, semantic_id: Optional[aas_types.Reference] = None, id_short: Optional[str] = None, created_from: Optional[datetime.datetime] = None, updated_from: Optional[datetime.datetime] = None, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> aas_types.GetAllSubmodelsRecentChangesResult: """ List a page of the changes of the submodels in the repository. A change gives only the identifier of a submodel, its semantic IDs, and when the submodel was created and last updated, so that also a large number of changes can be listed; get the submodels themselves with :py:func:`get_submodel_by_id`. The filters are combined with "and", except :paramref:`created_from` and :paramref:`updated_from`, which are combined with "or": a submodel is listed if it was created at or after :paramref:`created_from`, *or* updated at or after :paramref:`updated_from`. The operation is experimental in Part 2 V3.2. The times are ``createdAt`` and ``updatedAt`` of the administrative information as the users wrote them. The server does not set them (see https://github.com/eclipse-basyx/basyx-go-components/issues/821), so a submodel without them is not listed. :param server: where to send the request :param semantic_id: if set, only the submodels with this semantic ID or supplemental semantic ID :param id_short: if set, only the submodels with this ID-short :param created_from: if set, the submodels created at or after this time :param updated_from: if set, the submodels updated at or after this time :param limit: maximum number of the changes in the page :param cursor: where to continue the listing from :returns: a page of the changes :raises: :py:class:`ValueError` before sending anything if a time has no time zone :implements GetAllSubmodelsRecentChanges: ``GET /submodels/$recent-changes`` """ request = _build_get_all_submodels_recent_changes( server.base_url, semantic_id=semantic_id, id_short=id_short, created_from=created_from, updated_from=updated_from, limit=limit, cursor=cursor, ) response = http.send(server.transport, request) return _parse_get_all_submodels_recent_changes(response)
def _build_query_submodels( base_url: str, query: aas_types.Query, *, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> http.Request: """Build the request of ``QuerySubmodels`` for the full submodels.""" _query_language.check_selects_objects(query, "query_submodel_ids") return _query_language.build_request( base_url, "/query/submodels", query, limit, cursor ) def _parse_query_submodels(response: http.Response) -> aas_types.GetSubmodelsResult: """Parse the response of ``QuerySubmodels`` with the full submodels.""" errors.raise_for_unexpected_status(response, {200}) return _json.parse( response, aas_jsonization.get_submodels_result_from_jsonable, _query_language.make_page_adapter("Submodel", paging_metadata_required=True), )
[docs] def query_submodels( server: http.Server, query: aas_types.Query, *, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> aas_types.GetSubmodelsResult: """ List a page of the submodels in the repository which match :paramref:`query`. The :paramref:`query` must not select the identifiers (``"$select": "id"``); use :py:func:`query_submodel_ids` for that. Both functions implement the same operation, but give different results. The filters of the :paramref:`query` (``$filters``) may remove parts of the submodels, so the submodels in the page are not necessarily complete. :param server: where to send the request :param query: query in the AAS Query Language :param limit: maximum number of the submodels in the page :param cursor: where to continue the listing from :returns: a page of the matching submodels :raises: :py:class:`ValueError` before sending anything if :paramref:`query` selects the identifiers, or can not be serialized to JSON (*e.g.*, a number literal is not finite) :implements QuerySubmodels: ``POST /query/submodels`` """ request = _build_query_submodels(server.base_url, query, limit=limit, cursor=cursor) response = http.send(server.transport, request) return _parse_query_submodels(response)
def _build_query_submodel_ids( base_url: str, query: aas_types.Query, *, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> http.Request: """Build the request of ``QuerySubmodels`` for the identifiers.""" _query_language.check_selects_ids(query, "query_submodels") return _query_language.build_request( base_url, "/query/submodels", query, limit, cursor ) def _parse_query_submodel_ids(response: http.Response) -> query_results.IdsResult: """Parse the response of ``QuerySubmodels`` with the identifiers.""" errors.raise_for_unexpected_status(response, {200}) return _json.parse( response, _json.ids_result_from_jsonable, _query_language.make_page_adapter( _query_language.IDS_RESULT_TYPE, paging_metadata_required=True ), )
[docs] def query_submodel_ids( server: http.Server, query: aas_types.Query, *, limit: Optional[int] = None, cursor: Optional[str] = None, ) -> query_results.IdsResult: """ List a page of the identifiers of the submodels which match :paramref:`query`. The :paramref:`query` must select the identifiers (``"$select": "id"``); use :py:func:`query_submodels` for the full submodels. Both functions implement the same operation, but give different results. :param server: where to send the request :param query: query in the AAS Query Language :param limit: maximum number of the identifiers in the page :param cursor: where to continue the listing from :returns: a page of the identifiers of the matching submodels :raises: :py:class:`ValueError` before sending anything if :paramref:`query` does not select the identifiers, or can not be serialized to JSON (*e.g.*, a number literal is not finite) :implements QuerySubmodels: ``POST /query/submodels`` """ request = _build_query_submodel_ids( server.base_url, query, limit=limit, cursor=cursor ) response = http.send(server.transport, request) return _parse_query_submodel_ids(response)