# SPDX-FileCopyrightText: 2026 aas-client3.2-python AUTHORS
#
# SPDX-License-Identifier: MIT
"""
Implement the operations of the Asset Administration Shell 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, Sequence, 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 _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 _shell_path(aas_identifier: str) -> str:
"""Build the path of the Asset Administration Shell with the given identifier."""
return "/shells/" + http.encode_base64url(aas_identifier)
def _query_of_shells(
asset_ids: Optional[Sequence[aas_types.SpecificAssetID]],
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 Asset Administration Shells."""
query: _query.Query = []
# NOTE (mristin):
# The specification repeats the parameter for every specific asset ID.
if asset_ids is not None:
query.extend(
("assetIds", _query.encode_instance(asset_id)) for asset_id in asset_ids
)
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_asset_administration_shells(
base_url: str,
*,
asset_ids: Optional[Sequence[aas_types.SpecificAssetID]] = 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 ``GetAllAssetAdministrationShells``."""
return _json.build_request(
"GET",
http.build_url(
base_url,
"/shells",
_query_of_shells(
asset_ids, id_short, created_from, updated_from, limit, cursor
),
),
)
def _parse_get_all_asset_administration_shells(
response: http.Response,
) -> aas_types.GetAssetAdministrationShellsResult:
"""Parse the response of ``GetAllAssetAdministrationShells``."""
errors.raise_for_unexpected_status(response, {200})
return _json.parse(
response, aas_jsonization.get_asset_administration_shells_result_from_jsonable
)
[docs]
def get_all_asset_administration_shells(
server: http.Server,
*,
asset_ids: Optional[Sequence[aas_types.SpecificAssetID]] = 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.GetAssetAdministrationShellsResult:
"""
List a page of the Asset Administration Shells in the repository.
:param server: where to send the request
:param asset_ids: if set, only the shells with all these specific asset IDs
:param id_short: if set, only the shells with this ID-short
:param created_from: if set, only the shells created at or after this time
:param updated_from: if set, only the shells updated at or after this time
:param limit: maximum number of the shells in the page
:param cursor: where to continue the listing from
:returns: a page of the shells
:implements GetAllAssetAdministrationShells: ``GET /shells``
"""
request = _build_get_all_asset_administration_shells(
server.base_url,
asset_ids=asset_ids,
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_asset_administration_shells(response)
def _build_post_asset_administration_shell(
base_url: str, asset_administration_shell: aas_types.AssetAdministrationShell
) -> http.Request:
"""Build the request of ``PostAssetAdministrationShell``."""
return _json.build_request(
"POST", http.build_url(base_url, "/shells"), asset_administration_shell
)
def _parse_post_asset_administration_shell(
response: http.Response,
) -> aas_types.AssetAdministrationShell:
"""Parse the response of ``PostAssetAdministrationShell``."""
errors.raise_for_unexpected_status(response, {201})
return _json.parse(
response, aas_jsonization.asset_administration_shell_from_jsonable
)
[docs]
def post_asset_administration_shell(
server: http.Server, asset_administration_shell: aas_types.AssetAdministrationShell
) -> aas_types.AssetAdministrationShell:
"""
Create a new Asset Administration Shell in the repository.
:param server: where to send the request
:param asset_administration_shell: the shell to be created
:returns: the created shell, as stored by the server
:implements PostAssetAdministrationShell: ``POST /shells``
"""
request = _build_post_asset_administration_shell(
server.base_url, asset_administration_shell
)
response = http.send(server.transport, request)
return _parse_post_asset_administration_shell(response)
def _build_get_all_asset_administration_shells_reference(
base_url: str,
*,
asset_ids: Optional[Sequence[aas_types.SpecificAssetID]] = 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 ``GetAllAssetAdministrationShells-Reference``."""
return _json.build_request(
"GET",
http.build_url(
base_url,
"/shells/$reference",
_query_of_shells(
asset_ids, id_short, created_from, updated_from, limit, cursor
),
),
)
def _parse_get_all_asset_administration_shells_reference(
response: http.Response,
) -> aas_types.GetReferencesResult:
"""Parse the response of ``GetAllAssetAdministrationShells-Reference``."""
errors.raise_for_unexpected_status(response, {200})
return _json.parse(response, aas_jsonization.get_references_result_from_jsonable)
[docs]
def get_all_asset_administration_shells_reference(
server: http.Server,
*,
asset_ids: Optional[Sequence[aas_types.SpecificAssetID]] = 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 Asset Administration Shells.
:param server: where to send the request
:param asset_ids: if set, only the shells with all these specific asset IDs
:param id_short: if set, only the shells with this ID-short
:param created_from: if set, only the shells created at or after this time
:param updated_from: if set, only the shells 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 GetAllAssetAdministrationShells-Reference: ``GET /shells/$reference``
"""
request = _build_get_all_asset_administration_shells_reference(
server.base_url,
asset_ids=asset_ids,
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_asset_administration_shells_reference(response)
def _build_get_asset_administration_shell_by_id(
base_url: str, aas_identifier: str
) -> http.Request:
"""Build the request of ``GetAssetAdministrationShellById``."""
return _json.build_request(
"GET", http.build_url(base_url, _shell_path(aas_identifier))
)
def _parse_get_asset_administration_shell_by_id(
response: http.Response,
) -> aas_types.AssetAdministrationShell:
"""Parse the response of ``GetAssetAdministrationShellById``."""
errors.raise_for_unexpected_status(response, {200})
return _json.parse(
response, aas_jsonization.asset_administration_shell_from_jsonable
)
[docs]
def get_asset_administration_shell_by_id(
server: http.Server, aas_identifier: str
) -> aas_types.AssetAdministrationShell:
"""
Get the Asset Administration Shell with the given identifier.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:returns: the shell
:implements GetAssetAdministrationShellById: ``GET /shells/{aasIdentifier}``
"""
request = _build_get_asset_administration_shell_by_id(
server.base_url, aas_identifier
)
response = http.send(server.transport, request)
return _parse_get_asset_administration_shell_by_id(response)
def _build_put_asset_administration_shell_by_id(
base_url: str,
aas_identifier: str,
asset_administration_shell: aas_types.AssetAdministrationShell,
) -> http.Request:
"""Build the request of ``PutAssetAdministrationShellById``."""
return _json.build_request(
"PUT",
http.build_url(base_url, _shell_path(aas_identifier)),
asset_administration_shell,
)
def _parse_put_asset_administration_shell_by_id(response: http.Response) -> None:
"""
Parse the response of ``PutAssetAdministrationShellById``.
The server responds with 201 and the shell if it created the shell, or with
204 if it updated an existing one. We do not parse the shell, since it is
the one which the users sent.
"""
errors.raise_for_unexpected_status(response, {201, 204})
[docs]
def put_asset_administration_shell_by_id(
server: http.Server,
aas_identifier: str,
asset_administration_shell: aas_types.AssetAdministrationShell,
) -> None:
"""
Create or replace the Asset Administration Shell with the given identifier.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:param asset_administration_shell: the shell to be stored
:implements PutAssetAdministrationShellById: ``PUT /shells/{aasIdentifier}``
"""
request = _build_put_asset_administration_shell_by_id(
server.base_url, aas_identifier, asset_administration_shell
)
response = http.send(server.transport, request)
_parse_put_asset_administration_shell_by_id(response)
def _build_delete_asset_administration_shell_by_id(
base_url: str, aas_identifier: str
) -> http.Request:
"""Build the request of ``DeleteAssetAdministrationShellById``."""
return _json.build_request(
"DELETE", http.build_url(base_url, _shell_path(aas_identifier))
)
def _parse_delete_asset_administration_shell_by_id(response: http.Response) -> None:
"""Parse the response of ``DeleteAssetAdministrationShellById``."""
errors.raise_for_unexpected_status(response, {204})
[docs]
def delete_asset_administration_shell_by_id(
server: http.Server, aas_identifier: str
) -> None:
"""
Delete the Asset Administration Shell with the given identifier.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:implements DeleteAssetAdministrationShellById: ``DELETE /shells/{aasIdentifier}``
"""
request = _build_delete_asset_administration_shell_by_id(
server.base_url, aas_identifier
)
response = http.send(server.transport, request)
_parse_delete_asset_administration_shell_by_id(response)
def _build_get_asset_administration_shell_by_id_reference(
base_url: str, aas_identifier: str
) -> http.Request:
"""
Build the request of ``GetAssetAdministrationShellById-Reference_AasRepository``.
"""
return _json.build_request(
"GET", http.build_url(base_url, _shell_path(aas_identifier) + "/$reference")
)
def _parse_get_asset_administration_shell_by_id_reference(
response: http.Response,
) -> aas_types.Reference:
"""
Parse the response of ``GetAssetAdministrationShellById-Reference_AasRepository``.
"""
errors.raise_for_unexpected_status(response, {200})
return _json.parse(response, aas_jsonization.reference_from_jsonable)
[docs]
def get_asset_administration_shell_by_id_reference(
server: http.Server, aas_identifier: str
) -> aas_types.Reference:
"""
Get a reference to the Asset Administration Shell with the given identifier.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:returns: the reference to the shell
:implements GetAssetAdministrationShellById-Reference_AasRepository: ``GET /shells/{aasIdentifier}/$reference``
"""
request = _build_get_asset_administration_shell_by_id_reference(
server.base_url, aas_identifier
)
response = http.send(server.transport, request)
return _parse_get_asset_administration_shell_by_id_reference(response)
def _build_get_asset_information(base_url: str, aas_identifier: str) -> http.Request:
"""Build the request of ``GetAssetInformation_AasRepository``."""
return _json.build_request(
"GET",
http.build_url(base_url, _shell_path(aas_identifier) + "/asset-information"),
)
def _parse_get_asset_information(
response: http.Response,
) -> aas_types.AssetInformation:
"""Parse the response of ``GetAssetInformation_AasRepository``."""
errors.raise_for_unexpected_status(response, {200})
return _json.parse(response, aas_jsonization.asset_information_from_jsonable)
def _build_put_asset_information(
base_url: str, aas_identifier: str, asset_information: aas_types.AssetInformation
) -> http.Request:
"""Build the request of ``PutAssetInformation_AasRepository``."""
return _json.build_request(
"PUT",
http.build_url(base_url, _shell_path(aas_identifier) + "/asset-information"),
asset_information,
)
def _parse_put_asset_information(response: http.Response) -> None:
"""Parse the response of ``PutAssetInformation_AasRepository``."""
errors.raise_for_unexpected_status(response, {204})
def _build_get_all_submodel_references(
base_url: str,
aas_identifier: str,
*,
limit: Optional[int] = None,
cursor: Optional[str] = None,
) -> http.Request:
"""Build the request of ``GetAllSubmodelReferences_AasRepository``."""
return _json.build_request(
"GET",
http.build_url(
base_url,
_shell_path(aas_identifier) + "/submodel-refs",
_query.page(limit, cursor),
),
)
def _parse_get_all_submodel_references(
response: http.Response,
) -> aas_types.GetReferencesResult:
"""Parse the response of ``GetAllSubmodelReferences_AasRepository``."""
errors.raise_for_unexpected_status(response, {200})
return _json.parse(response, aas_jsonization.get_references_result_from_jsonable)
[docs]
def get_all_submodel_references(
server: http.Server,
aas_identifier: str,
*,
limit: Optional[int] = None,
cursor: Optional[str] = None,
) -> aas_types.GetReferencesResult:
"""
List a page of the submodel references of the Asset Administration Shell.
This is not to be confused with ``get_all_submodels_reference`` of the Submodel
Repository API, which lists a reference for each submodel in a repository.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:param limit: maximum number of the references in the page
:param cursor: where to continue the listing from
:returns: a page of the submodel references
:implements GetAllSubmodelReferences_AasRepository: ``GET /shells/{aasIdentifier}/submodel-refs``
"""
request = _build_get_all_submodel_references(
server.base_url, aas_identifier, limit=limit, cursor=cursor
)
response = http.send(server.transport, request)
return _parse_get_all_submodel_references(response)
def _build_post_submodel_reference(
base_url: str, aas_identifier: str, submodel_reference: aas_types.Reference
) -> http.Request:
"""Build the request of ``PostSubmodelReference_AasRepository``."""
return _json.build_request(
"POST",
http.build_url(base_url, _shell_path(aas_identifier) + "/submodel-refs"),
submodel_reference,
)
def _parse_post_submodel_reference(response: http.Response) -> aas_types.Reference:
"""Parse the response of ``PostSubmodelReference_AasRepository``."""
errors.raise_for_unexpected_status(response, {201})
return _json.parse(response, aas_jsonization.reference_from_jsonable)
[docs]
def post_submodel_reference(
server: http.Server, aas_identifier: str, submodel_reference: aas_types.Reference
) -> aas_types.Reference:
"""
Add a submodel reference to the Asset Administration Shell.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:param submodel_reference: reference to the submodel
:returns: the created submodel reference, as stored by the server
:implements PostSubmodelReference_AasRepository: ``POST /shells/{aasIdentifier}/submodel-refs``
"""
request = _build_post_submodel_reference(
server.base_url, aas_identifier, submodel_reference
)
response = http.send(server.transport, request)
return _parse_post_submodel_reference(response)
def _build_delete_submodel_reference(
base_url: str, aas_identifier: str, submodel_identifier: str
) -> http.Request:
"""Build the request of ``DeleteSubmodelReference_AasRepository``."""
return _json.build_request(
"DELETE",
http.build_url(
base_url,
_shell_path(aas_identifier)
+ "/submodel-refs/"
+ http.encode_base64url(submodel_identifier),
),
)
def _parse_delete_submodel_reference(response: http.Response) -> None:
"""Parse the response of ``DeleteSubmodelReference_AasRepository``."""
errors.raise_for_unexpected_status(response, {204})
[docs]
def delete_submodel_reference(
server: http.Server, aas_identifier: str, submodel_identifier: str
) -> None:
"""
Remove the reference to the submodel from the Asset Administration Shell.
The submodel itself is not deleted.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:param submodel_identifier: identifier of the referenced submodel
:implements DeleteSubmodelReference_AasRepository: ``DELETE /shells/{aasIdentifier}/submodel-refs/{submodelIdentifier}``
"""
request = _build_delete_submodel_reference(
server.base_url, aas_identifier, submodel_identifier
)
response = http.send(server.transport, request)
_parse_delete_submodel_reference(response)
def _thumbnail_path(aas_identifier: str) -> str:
"""Build the path of the thumbnail of the Asset Administration Shell."""
return _shell_path(aas_identifier) + "/asset-information/thumbnail"
def _build_get_thumbnail(base_url: str, aas_identifier: str) -> http.Request:
"""Build the request of ``GetThumbnail_AasRepository``."""
return _files.build_download_request(
http.build_url(base_url, _thumbnail_path(aas_identifier))
)
[docs]
def get_thumbnail(
server: http.Server, aas_identifier: str
) -> ContextManager[http.Download]:
"""
Download the thumbnail of the asset of the Asset Administration Shell.
The content is streamed, so use the result as a context manager:
.. code-block:: python
with aas_repository.get_thumbnail(server, "urn:example:aas:1") as download:
with open("thumbnail.png", "wb") as fid:
download.write_to(fid)
The connection is released when the context is exited. If the thumbnail 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 aas_identifier: identifier of the Asset Administration Shell
:returns: a context manager which gives the download
:raises: :py:class:`~aas_client3_2.errors.NotFound` if there is no such
Asset Administration Shell, or it has no thumbnail
:implements GetThumbnail_AasRepository: ``GET /shells/{aasIdentifier}/asset-information/thumbnail``
"""
request = _build_get_thumbnail(server.base_url, aas_identifier)
return _files.download(server, request, {200})
def _build_put_thumbnail(
base_url: str,
aas_identifier: str,
content: Union[bytes, IO[bytes]],
*,
file_name: Optional[str] = None,
content_type: Optional[str] = None,
) -> http.Request:
"""Build the request of ``PutThumbnail_AasRepository``."""
return _files.build_upload_request(
"PUT",
http.build_url(base_url, _thumbnail_path(aas_identifier)),
content,
file_name,
content_type,
)
def _parse_put_thumbnail(response: http.Response) -> None:
"""Parse the response of ``PutThumbnail_AasRepository``."""
errors.raise_for_unexpected_status(response, {204})
[docs]
def put_thumbnail(
server: http.Server,
aas_identifier: str,
content: Union[bytes, IO[bytes]],
*,
file_name: Optional[str] = None,
content_type: Optional[str] = None,
) -> None:
"""
Upload the thumbnail of the asset of the Asset Administration Shell.
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. It must be seekable so that the client
knows the length of the body up-front, and can send the content again, for
example, after a refreshed token. The file object must not be modified during
the upload.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:param content: content of the thumbnail
:param file_name: if set, the name of the file, such as ``thumbnail.png``
:param content_type:
if set, the content type of the thumbnail, such as ``image/png``,
otherwise ``application/octet-stream``. The servers may take it as
the new content type of the thumbnail.
: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
:implements PutThumbnail_AasRepository: ``PUT /shells/{aasIdentifier}/asset-information/thumbnail``
"""
request = _build_put_thumbnail(
server.base_url,
aas_identifier,
content,
file_name=file_name,
content_type=content_type,
)
response = http.send(server.transport, request)
_parse_put_thumbnail(response)
def _build_delete_thumbnail(base_url: str, aas_identifier: str) -> http.Request:
"""Build the request of ``DeleteThumbnail_AasRepository``."""
return _json.build_request(
"DELETE", http.build_url(base_url, _thumbnail_path(aas_identifier))
)
def _parse_delete_thumbnail(response: http.Response) -> None:
"""Parse the response of ``DeleteThumbnail_AasRepository``."""
# NOTE (mristin):
# The OpenAPI gives 204, and still 200 as deprecated.
errors.raise_for_unexpected_status(response, {200, 204})
[docs]
def delete_thumbnail(server: http.Server, aas_identifier: str) -> None:
"""
Delete the thumbnail of the asset of the Asset Administration Shell.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:implements DeleteThumbnail_AasRepository: ``DELETE /shells/{aasIdentifier}/asset-information/thumbnail``
"""
request = _build_delete_thumbnail(server.base_url, aas_identifier)
response = http.send(server.transport, request)
_parse_delete_thumbnail(response)
def _build_get_asset_administration_shell_version_by_id_and_date(
base_url: str,
aas_identifier: str,
*,
date: Optional[datetime.datetime] = None,
) -> http.Request:
"""Build the request of ``GetAssetAdministrationShellVersionByIdAndDate``."""
return _json.build_request(
"GET",
http.build_url(
base_url, _shell_path(aas_identifier) + "/$history", _query.date(date)
),
)
def _parse_get_asset_administration_shell_version_by_id_and_date(
response: http.Response,
) -> aas_types.AssetAdministrationShell:
"""Parse the response of ``GetAssetAdministrationShellVersionByIdAndDate``."""
errors.raise_for_unexpected_status(response, {200})
return _json.parse(
response, aas_jsonization.asset_administration_shell_from_jsonable
)
[docs]
def get_asset_administration_shell_version_by_id_and_date(
server: http.Server,
aas_identifier: str,
*,
date: Optional[datetime.datetime] = None,
) -> aas_types.AssetAdministrationShell:
"""
Get the version of the Asset Administration Shell valid at the given point in time.
The version is not the attribute ``version`` of the administrative information,
but the state of the Asset Administration Shell as stored by the server; which
changes make a new version is up to the server.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:param date:
point in time with a time zone; if not set, the server gives the latest
version
:returns: the version of the Asset Administration Shell
: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 Asset Administration Shell at that point in time
:implements GetAssetAdministrationShellVersionByIdAndDate: ``GET /shells/{aasIdentifier}/$history``
"""
request = _build_get_asset_administration_shell_version_by_id_and_date(
server.base_url, aas_identifier, date=date
)
response = http.send(server.transport, request)
return _parse_get_asset_administration_shell_version_by_id_and_date(response)
def _build_get_asset_administration_shell_by_id_signed(
base_url: str, aas_identifier: str
) -> http.Request:
"""Build the request of ``GetAssetAdministrationShellByIdSigned``."""
return _signed.build_request(
http.build_url(base_url, _shell_path(aas_identifier) + "/$signed")
)
def _parse_get_asset_administration_shell_by_id_signed(
response: http.Response,
) -> str:
"""Parse the response of ``GetAssetAdministrationShellByIdSigned``."""
return _signed.parse(response)
[docs]
def get_asset_administration_shell_by_id_signed(
server: http.Server, aas_identifier: str
) -> str:
"""
Get the Asset Administration Shell with the given identifier, signed by the server.
The Asset Administration Shell 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, and the certificate in the JWS
itself proves nothing. Verify it with a JWS library, and parse the verified
payload with
:py:func:`aas_core3_2.jsonization.asset_administration_shell_from_jsonable`.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:returns: the JWS in the compact serialization
:implements GetAssetAdministrationShellByIdSigned: ``GET /shells/{aasIdentifier}/$signed``
"""
request = _build_get_asset_administration_shell_by_id_signed(
server.base_url, aas_identifier
)
response = http.send(server.transport, request)
return _parse_get_asset_administration_shell_by_id_signed(response)
def _build_get_all_asset_administration_shells_recent_changes(
base_url: str,
*,
asset_ids: Optional[Sequence[aas_types.SpecificAssetID]] = 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 ``GetAllAssetAdministrationShellsRecentChanges``."""
return _json.build_request(
"GET",
http.build_url(
base_url,
"/shells/$recent-changes",
_query_of_shells(
asset_ids, id_short, created_from, updated_from, limit, cursor
),
),
)
def _parse_get_all_asset_administration_shells_recent_changes(
response: http.Response,
) -> aas_types.GetAllAssetAdministrationShellsRecentChangesResult:
"""Parse the response of ``GetAllAssetAdministrationShellsRecentChanges``."""
errors.raise_for_unexpected_status(response, {200})
return _json.parse(
response,
aas_jsonization.get_all_asset_administration_shells_recent_changes_result_from_jsonable,
)
[docs]
def get_all_asset_administration_shells_recent_changes(
server: http.Server,
*,
asset_ids: Optional[Sequence[aas_types.SpecificAssetID]] = 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.GetAllAssetAdministrationShellsRecentChangesResult:
"""
List a page of the changes of the Asset Administration Shells in the repository.
A change gives only the identifier of a shell, the IDs of its asset, and when
the shell was created and last updated, so that also a large number of
changes can be listed; get the shells themselves with
:py:func:`get_asset_administration_shell_by_id`.
The filters are combined with "and", except :paramref:`created_from` and
:paramref:`updated_from`, which are combined with "or": a shell 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 shell
without them is not listed.
:param server: where to send the request
:param asset_ids: if set, only the shells with all these specific asset IDs
:param id_short: if set, only the shells with this ID-short
:param created_from: if set, the shells created at or after this time
:param updated_from: if set, the shells 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 GetAllAssetAdministrationShellsRecentChanges: ``GET /shells/$recent-changes``
"""
request = _build_get_all_asset_administration_shells_recent_changes(
server.base_url,
asset_ids=asset_ids,
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_asset_administration_shells_recent_changes(response)
def _build_query_asset_administration_shells(
base_url: str,
query: aas_types.Query,
*,
limit: Optional[int] = None,
cursor: Optional[str] = None,
) -> http.Request:
"""Build the request of ``QueryAssetAdministrationShells`` for the full AAS."""
_query_language.check_selects_objects(query, "query_asset_administration_shell_ids")
return _query_language.build_request(
base_url, "/query/shells", query, limit, cursor
)
def _parse_query_asset_administration_shells(
response: http.Response,
) -> aas_types.GetAssetAdministrationShellsResult:
"""Parse the response of ``QueryAssetAdministrationShells`` with the full AAS."""
errors.raise_for_unexpected_status(response, {200})
return _json.parse(
response,
aas_jsonization.get_asset_administration_shells_result_from_jsonable,
_query_language.make_page_adapter(
"AssetAdministrationShell", paging_metadata_required=False
),
)
[docs]
def query_asset_administration_shells(
server: http.Server,
query: aas_types.Query,
*,
limit: Optional[int] = None,
cursor: Optional[str] = None,
) -> aas_types.GetAssetAdministrationShellsResult:
"""
List a page of the Asset Administration Shells which match :paramref:`query`.
The :paramref:`query` must not select the identifiers (``"$select": "id"``);
use :py:func:`query_asset_administration_shell_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 Asset Administration Shells, so the shells 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 Asset Administration Shells in the page
:param cursor: where to continue the listing from
:returns: a page of the matching Asset Administration Shells
: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 QueryAssetAdministrationShells: ``POST /query/shells``
"""
request = _build_query_asset_administration_shells(
server.base_url, query, limit=limit, cursor=cursor
)
response = http.send(server.transport, request)
return _parse_query_asset_administration_shells(response)
def _build_query_asset_administration_shell_ids(
base_url: str,
query: aas_types.Query,
*,
limit: Optional[int] = None,
cursor: Optional[str] = None,
) -> http.Request:
"""Build the request of ``QueryAssetAdministrationShells`` for the identifiers."""
_query_language.check_selects_ids(query, "query_asset_administration_shells")
return _query_language.build_request(
base_url, "/query/shells", query, limit, cursor
)
def _parse_query_asset_administration_shell_ids(
response: http.Response,
) -> query_results.IdsResult:
"""Parse the response of ``QueryAssetAdministrationShells`` 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=False
),
)
[docs]
def query_asset_administration_shell_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 shells which match :paramref:`query`.
The :paramref:`query` must select the identifiers (``"$select": "id"``); use
:py:func:`query_asset_administration_shells` for the full Asset Administration
Shells. 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 Asset Administration Shells
: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 QueryAssetAdministrationShells: ``POST /query/shells``
"""
request = _build_query_asset_administration_shell_ids(
server.base_url, query, limit=limit, cursor=cursor
)
response = http.send(server.transport, request)
return _parse_query_asset_administration_shell_ids(response)
def _submodel_path(aas_identifier: str, submodel_identifier: str) -> str:
"""Build the path of the submodel through the Asset Administration Shell."""
return (
_shell_path(aas_identifier)
+ "/submodels/"
+ http.encode_base64url(submodel_identifier)
)
def _build_get_submodel_by_id(
base_url: str,
aas_identifier: str,
submodel_identifier: str,
*,
level: Optional[aas_types.Level] = None,
extent: Optional[aas_types.Extent] = None,
) -> http.Request:
"""Build the request of ``GetSubmodelById_AasRepository``."""
return _submodel_operations.build_get_submodel_by_id(
base_url,
_submodel_path(aas_identifier, submodel_identifier),
level=level,
extent=extent,
)
def _parse_get_submodel_by_id(response: http.Response) -> aas_types.Submodel:
"""Parse the response of ``GetSubmodelById_AasRepository``."""
return _submodel_operations.parse_get_submodel_by_id(response)
[docs]
def get_submodel_by_id(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}``
"""
request = _build_get_submodel_by_id(
server.base_url, aas_identifier, 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,
aas_identifier: str,
submodel_identifier: str,
submodel: aas_types.Submodel,
) -> http.Request:
"""Build the request of ``PutSubmodelById_AasRepository``."""
return _submodel_operations.build_put_submodel_by_id(
base_url, _submodel_path(aas_identifier, submodel_identifier), submodel
)
def _parse_put_submodel_by_id(response: http.Response) -> None:
"""Parse the response of ``PutSubmodelById_AasRepository``."""
return _submodel_operations.parse_put_submodel_by_id(response)
[docs]
def put_submodel_by_id(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
:param submodel_identifier: identifier of the submodel
:param submodel: the submodel to be stored
:implements PutSubmodelById_AasRepository: ``PUT /shells/{aasIdentifier}/submodels/{submodelIdentifier}``
"""
request = _build_put_submodel_by_id(
server.base_url, aas_identifier, submodel_identifier, submodel
)
response = http.send(server.transport, request)
_parse_put_submodel_by_id(response)
def _build_patch_submodel(
base_url: str,
aas_identifier: str,
submodel_identifier: str,
submodel: aas_types.Submodel,
) -> http.Request:
"""Build the request of ``PatchSubmodel_AasRepository``."""
return _submodel_operations.build_patch_submodel_by_id(
base_url, _submodel_path(aas_identifier, submodel_identifier), submodel
)
def _parse_patch_submodel(response: http.Response) -> None:
"""Parse the response of ``PatchSubmodel_AasRepository``."""
return _submodel_operations.parse_patch_submodel_by_id(response)
[docs]
def patch_submodel(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
:param submodel_identifier: identifier of the submodel
:param submodel: the submodel with the updates
:implements PatchSubmodel_AasRepository: ``PATCH /shells/{aasIdentifier}/submodels/{submodelIdentifier}``
"""
request = _build_patch_submodel(
server.base_url, aas_identifier, submodel_identifier, submodel
)
response = http.send(server.transport, request)
_parse_patch_submodel(response)
def _build_delete_submodel_by_id(
base_url: str, aas_identifier: str, submodel_identifier: str
) -> http.Request:
"""Build the request of ``DeleteSubmodelById_AasRepository``."""
return _submodel_operations.build_delete_submodel_by_id(
base_url, _submodel_path(aas_identifier, submodel_identifier)
)
def _parse_delete_submodel_by_id(response: http.Response) -> None:
"""Parse the response of ``DeleteSubmodelById_AasRepository``."""
return _submodel_operations.parse_delete_submodel_by_id(response)
[docs]
def delete_submodel_by_id(
server: http.Server, aas_identifier: str, submodel_identifier: str
) -> None:
"""
Delete the submodel with the given identifier.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:param submodel_identifier: identifier of the submodel
:implements DeleteSubmodelById_AasRepository: ``DELETE /shells/{aasIdentifier}/submodels/{submodelIdentifier}``
"""
request = _build_delete_submodel_by_id(
server.base_url, aas_identifier, submodel_identifier
)
response = http.send(server.transport, request)
_parse_delete_submodel_by_id(response)
def _build_get_submodel_by_id_metadata(
base_url: str, aas_identifier: str, submodel_identifier: str
) -> http.Request:
"""Build the request of ``GetSubmodelById-Metadata_AasRepository``."""
return _submodel_operations.build_get_submodel_by_id_metadata(
base_url, _submodel_path(aas_identifier, submodel_identifier)
)
def _parse_get_submodel_by_id_metadata(
response: http.Response,
) -> aas_types.SubmodelMetadata:
"""Parse the response of ``GetSubmodelById-Metadata_AasRepository``."""
return _submodel_operations.parse_get_submodel_by_id_metadata(response)
def _build_patch_submodel_by_id_metadata(
base_url: str,
aas_identifier: str,
submodel_identifier: str,
submodel_metadata: aas_types.SubmodelMetadata,
) -> http.Request:
"""Build the request of ``PatchSubmodelById-Metadata_AasRepository``."""
return _submodel_operations.build_patch_submodel_by_id_metadata(
base_url, _submodel_path(aas_identifier, submodel_identifier), submodel_metadata
)
def _parse_patch_submodel_by_id_metadata(response: http.Response) -> None:
"""Parse the response of ``PatchSubmodelById-Metadata_AasRepository``."""
return _submodel_operations.parse_patch_submodel_by_id_metadata(response)
def _build_get_submodel_by_id_value_only(
base_url: str,
aas_identifier: str,
submodel_identifier: str,
*,
level: Optional[aas_types.Level] = None,
extent: Optional[aas_types.Extent] = None,
) -> http.Request:
"""Build the request of ``GetSubmodelById-ValueOnly_AasRepository``."""
return _submodel_operations.build_get_submodel_by_id_value_only(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_get_submodel_by_id_value_only(response)
[docs]
def get_submodel_by_id_value_only(
server: http.Server,
aas_identifier: str,
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 ValueOnly serialization drops
the model types: a range ``{"min": 1, "max": 5}`` looks exactly like
a collection with the properties ``min`` and ``max``.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/$value``
"""
request = _build_get_submodel_by_id_value_only(
server.base_url, aas_identifier, 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,
aas_identifier: str,
submodel_identifier: str,
submodel: aas_types.Submodel,
) -> http.Request:
"""Build the request of ``PatchSubmodelById-ValueOnly_AasRepository``."""
return _submodel_operations.build_patch_submodel_by_id_value_only(
base_url, _submodel_path(aas_identifier, submodel_identifier), submodel
)
def _parse_patch_submodel_by_id_value_only(response: http.Response) -> None:
"""Parse the response of ``PatchSubmodelById-ValueOnly_AasRepository``."""
return _submodel_operations.parse_patch_submodel_by_id_value_only(response)
[docs]
def patch_submodel_by_id_value_only(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``PATCH /shells/{aasIdentifier}/submodels/{submodelIdentifier}/$value``
"""
request = _build_patch_submodel_by_id_value_only(
server.base_url, aas_identifier, submodel_identifier, submodel
)
response = http.send(server.transport, request)
_parse_patch_submodel_by_id_value_only(response)
def _build_get_submodel_by_id_reference(
base_url: str, aas_identifier: str, submodel_identifier: str
) -> http.Request:
"""Build the request of ``GetSubmodelById-Reference_AasRepository``."""
return _submodel_operations.build_get_submodel_by_id_reference(
base_url, _submodel_path(aas_identifier, submodel_identifier)
)
def _parse_get_submodel_by_id_reference(response: http.Response) -> aas_types.Reference:
"""Parse the response of ``GetSubmodelById-Reference_AasRepository``."""
return _submodel_operations.parse_get_submodel_by_id_reference(response)
[docs]
def get_submodel_by_id_reference(
server: http.Server, aas_identifier: str, submodel_identifier: str
) -> aas_types.Reference:
"""
Get a reference to the submodel with the given identifier.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
:param submodel_identifier: identifier of the submodel
:returns: the reference to the submodel
:implements GetSubmodelById-Reference_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/$reference``
"""
request = _build_get_submodel_by_id_reference(
server.base_url, aas_identifier, submodel_identifier
)
response = http.send(server.transport, request)
return _parse_get_submodel_by_id_reference(response)
def _build_get_submodel_by_id_path(
base_url: str,
aas_identifier: str,
submodel_identifier: str,
*,
level: Optional[aas_types.Level] = None,
) -> http.Request:
"""Build the request of ``GetSubmodelById-Path_AasRepository``."""
return _submodel_operations.build_get_submodel_by_id_path(
base_url, _submodel_path(aas_identifier, submodel_identifier), level=level
)
def _parse_get_submodel_by_id_path(response: http.Response) -> List[str]:
"""Parse the response of ``GetSubmodelById-Path_AasRepository``."""
return _submodel_operations.parse_get_submodel_by_id_path(response)
[docs]
def get_submodel_by_id_path(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
:param submodel_identifier: identifier of the submodel
:param level: depth of the returned paths
:returns: the paths
:implements GetSubmodelById-Path_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/$path``
"""
request = _build_get_submodel_by_id_path(
server.base_url, aas_identifier, 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,
aas_identifier: 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_AasRepository``."""
return _submodel_operations.build_get_all_submodel_elements(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_get_all_submodel_elements(response)
[docs]
def get_all_submodel_elements(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements``
"""
request = _build_get_all_submodel_elements(
server.base_url,
aas_identifier,
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,
aas_identifier: str,
submodel_identifier: str,
submodel_element: aas_types.SubmodelElement,
) -> http.Request:
"""Build the request of ``PostSubmodelElement_AasRepository``."""
return _submodel_operations.build_post_submodel_element(
base_url, _submodel_path(aas_identifier, submodel_identifier), submodel_element
)
def _parse_post_submodel_element(response: http.Response) -> aas_types.SubmodelElement:
"""Parse the response of ``PostSubmodelElement_AasRepository``."""
return _submodel_operations.parse_post_submodel_element(response)
[docs]
def post_submodel_element(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``POST /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements``
"""
request = _build_post_submodel_element(
server.base_url, aas_identifier, 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,
aas_identifier: str,
submodel_identifier: str,
*,
limit: Optional[int] = None,
cursor: Optional[str] = None,
) -> http.Request:
"""Build the request of ``GetAllSubmodelElements-Metadata_AasRepository``."""
return _submodel_operations.build_get_all_submodel_elements_metadata(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_get_all_submodel_elements_metadata(response)
def _build_get_all_submodel_elements_value_only(
base_url: str,
aas_identifier: 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-ValueOnly_AasRepository``."""
return _submodel_operations.build_get_all_submodel_elements_value_only(
base_url,
_submodel_path(aas_identifier, submodel_identifier),
limit=limit,
cursor=cursor,
level=level,
)
def _parse_get_all_submodel_elements_value_only(
response: http.Response,
) -> aas_types.GetSubmodelElementsValueResult:
"""Parse the response of ``GetAllSubmodelElements-ValueOnly_AasRepository``."""
return _submodel_operations.parse_get_all_submodel_elements_value_only(response)
[docs]
def get_all_submodel_elements_value_only(
server: http.Server,
aas_identifier: str,
submodel_identifier: str,
*,
limit: Optional[int] = None,
cursor: Optional[str] = None,
level: Optional[aas_types.Level] = 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 aas_identifier: identifier of the Asset Administration Shell
: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
:returns: a page of the values of the submodel elements
:implements GetAllSubmodelElements-ValueOnly_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/$value``
"""
request = _build_get_all_submodel_elements_value_only(
server.base_url,
aas_identifier,
submodel_identifier,
limit=limit,
cursor=cursor,
level=level,
)
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,
aas_identifier: str,
submodel_identifier: str,
*,
limit: Optional[int] = None,
cursor: Optional[str] = None,
) -> http.Request:
"""Build the request of ``GetAllSubmodelElements-Reference_AasRepository``."""
return _submodel_operations.build_get_all_submodel_elements_reference(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_get_all_submodel_elements_reference(response)
[docs]
def get_all_submodel_elements_reference(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/$reference``
"""
request = _build_get_all_submodel_elements_reference(
server.base_url, aas_identifier, 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,
aas_identifier: 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-Path_AasRepository``."""
return _submodel_operations.build_get_all_submodel_elements_path(
base_url,
_submodel_path(aas_identifier, submodel_identifier),
limit=limit,
cursor=cursor,
level=level,
extent=extent,
)
def _parse_get_all_submodel_elements_path(
response: http.Response,
) -> aas_types.GetPathItemsResult:
"""Parse the response of ``GetAllSubmodelElements-Path_AasRepository``."""
return _submodel_operations.parse_get_all_submodel_elements_path(response)
[docs]
def get_all_submodel_elements_path(
server: http.Server,
aas_identifier: str,
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.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 aas_identifier: identifier of the Asset Administration Shell
: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
:param extent: whether to include the values of blobs; the OpenAPI gives
the parameter here, although the paths carry no values
:returns: a page of the paths
:implements GetAllSubmodelElements-Path_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/$path``
"""
request = _build_get_all_submodel_elements_path(
server.base_url,
aas_identifier,
submodel_identifier,
limit=limit,
cursor=cursor,
level=level,
extent=extent,
)
response = http.send(server.transport, request)
return _parse_get_all_submodel_elements_path(response)
def _build_get_submodel_element_by_path(
base_url: str,
aas_identifier: 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_AasRepository``."""
return _submodel_operations.build_get_submodel_element_by_path(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_get_submodel_element_by_path(response)
[docs]
def get_submodel_element_by_path(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}``
"""
request = _build_get_submodel_element_by_path(
server.base_url,
aas_identifier,
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,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
submodel_element: aas_types.SubmodelElement,
) -> http.Request:
"""Build the request of ``PostSubmodelElementByPath_AasRepository``."""
return _submodel_operations.build_post_submodel_element_by_path(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_post_submodel_element_by_path(response)
[docs]
def post_submodel_element_by_path(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``POST /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}``
"""
request = _build_post_submodel_element_by_path(
server.base_url,
aas_identifier,
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,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
submodel_element: aas_types.SubmodelElement,
) -> http.Request:
"""Build the request of ``PutSubmodelElementByPath_AasRepository``."""
return _submodel_operations.build_put_submodel_element_by_path(
base_url,
_submodel_path(aas_identifier, submodel_identifier),
id_short_path,
submodel_element,
)
def _parse_put_submodel_element_by_path(response: http.Response) -> None:
"""Parse the response of ``PutSubmodelElementByPath_AasRepository``."""
return _submodel_operations.parse_put_submodel_element_by_path(response)
[docs]
def put_submodel_element_by_path(
server: http.Server,
aas_identifier: str,
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.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``PUT /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}``
"""
request = _build_put_submodel_element_by_path(
server.base_url,
aas_identifier,
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_value_by_path(
base_url: str,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
submodel_element: aas_types.SubmodelElement,
*,
level: Optional[aas_types.Level] = None,
) -> http.Request:
"""Build the request of ``PatchSubmodelElementValueByPath_AasRepository``."""
return _submodel_operations.build_patch_submodel_element_by_path(
base_url,
_submodel_path(aas_identifier, submodel_identifier),
id_short_path,
submodel_element,
level=level,
)
def _parse_patch_submodel_element_value_by_path(response: http.Response) -> None:
"""Parse the response of ``PatchSubmodelElementValueByPath_AasRepository``."""
return _submodel_operations.parse_patch_submodel_element_by_path(response)
[docs]
def patch_submodel_element_value_by_path(
server: http.Server,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
submodel_element: aas_types.SubmodelElement,
*,
level: Optional[aas_types.Level] = None,
) -> 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.
Unlike the Submodel Repository API, the OpenAPI allows both values of
the query parameter ``level`` here.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
: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
:param level: depth of the update
:implements PatchSubmodelElementValueByPath_AasRepository: ``PATCH /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}``
"""
request = _build_patch_submodel_element_value_by_path(
server.base_url,
aas_identifier,
submodel_identifier,
id_short_path,
submodel_element,
level=level,
)
response = http.send(server.transport, request)
_parse_patch_submodel_element_value_by_path(response)
def _build_delete_submodel_element_by_path(
base_url: str, aas_identifier: str, submodel_identifier: str, id_short_path: str
) -> http.Request:
"""Build the request of ``DeleteSubmodelElementByPath_AasRepository``."""
return _submodel_operations.build_delete_submodel_element_by_path(
base_url, _submodel_path(aas_identifier, submodel_identifier), id_short_path
)
def _parse_delete_submodel_element_by_path(response: http.Response) -> None:
"""Parse the response of ``DeleteSubmodelElementByPath_AasRepository``."""
return _submodel_operations.parse_delete_submodel_element_by_path(response)
[docs]
def delete_submodel_element_by_path(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
:param submodel_identifier: identifier of the submodel
:param id_short_path: ID-short path of the element
:implements DeleteSubmodelElementByPath_AasRepository: ``DELETE /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}``
"""
request = _build_delete_submodel_element_by_path(
server.base_url, aas_identifier, 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, aas_identifier: str, submodel_identifier: str, id_short_path: str
) -> http.Request:
"""Build the request of ``GetSubmodelElementByPath-Metadata_AasRepository``."""
return _submodel_operations.build_get_submodel_element_by_path_metadata(
base_url, _submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_get_submodel_element_by_path_metadata(response)
def _build_patch_submodel_element_value_by_path_metadata(
base_url: str,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
submodel_element_metadata: aas_types.SubmodelElementMetadata,
) -> http.Request:
"""Build the request of ``PatchSubmodelElementValueByPath-Metadata``."""
return _submodel_operations.build_patch_submodel_element_by_path_metadata(
base_url,
_submodel_path(aas_identifier, submodel_identifier),
id_short_path,
submodel_element_metadata,
)
def _parse_patch_submodel_element_value_by_path_metadata(
response: http.Response,
) -> None:
"""Parse the response of ``PatchSubmodelElementValueByPath-Metadata``."""
return _submodel_operations.parse_patch_submodel_element_by_path_metadata(response)
def _build_get_submodel_element_by_path_value_only(
base_url: str,
aas_identifier: 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_AasRepository``."""
return _submodel_operations.build_get_submodel_element_by_path_value_only(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_get_submodel_element_by_path_value_only(response)
[docs]
def get_submodel_element_by_path_value_only(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/$value``
"""
request = _build_get_submodel_element_by_path_value_only(
server.base_url,
aas_identifier,
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_value_by_path_value_only(
base_url: str,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
submodel_element: aas_types.SubmodelElement,
*,
level: Optional[aas_types.Level] = None,
) -> http.Request:
"""Build the request of ``PatchSubmodelElementValueByPath-ValueOnly``."""
return _submodel_operations.build_patch_submodel_element_by_path_value_only(
base_url,
_submodel_path(aas_identifier, submodel_identifier),
id_short_path,
submodel_element,
level=level,
)
def _parse_patch_submodel_element_value_by_path_value_only(
response: http.Response,
) -> None:
"""Parse the response of ``PatchSubmodelElementValueByPath-ValueOnly``."""
return _submodel_operations.parse_patch_submodel_element_by_path_value_only(
response
)
[docs]
def patch_submodel_element_value_by_path_value_only(
server: http.Server,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
submodel_element: aas_types.SubmodelElement,
*,
level: Optional[aas_types.Level] = None,
) -> 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.
Unlike the Submodel Repository API, the OpenAPI allows both values of
the query parameter ``level`` here.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
: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
:param level: depth of the update
: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 PatchSubmodelElementValueByPath-ValueOnly: ``PATCH /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/$value``
"""
request = _build_patch_submodel_element_value_by_path_value_only(
server.base_url,
aas_identifier,
submodel_identifier,
id_short_path,
submodel_element,
level=level,
)
response = http.send(server.transport, request)
_parse_patch_submodel_element_value_by_path_value_only(response)
def _build_get_submodel_element_by_path_reference(
base_url: str, aas_identifier: str, submodel_identifier: str, id_short_path: str
) -> http.Request:
"""Build the request of ``GetSubmodelElementByPath-Reference_AasRepository``."""
return _submodel_operations.build_get_submodel_element_by_path_reference(
base_url, _submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_get_submodel_element_by_path_reference(response)
[docs]
def get_submodel_element_by_path_reference(
server: http.Server,
aas_identifier: str,
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``.
The deprecated query parameter ``level`` is omitted, since it allows only
the value ``core``.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/$reference``
"""
request = _build_get_submodel_element_by_path_reference(
server.base_url, aas_identifier, 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,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
*,
level: Optional[aas_types.Level] = None,
) -> http.Request:
"""Build the request of ``GetSubmodelElementByPath-Path_AasRepository``."""
return _submodel_operations.build_get_submodel_element_by_path_path(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_get_submodel_element_by_path_path(response)
[docs]
def get_submodel_element_by_path_path(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/$path``
"""
request = _build_get_submodel_element_by_path_path(
server.base_url, aas_identifier, 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, aas_identifier: str, submodel_identifier: str, id_short_path: str
) -> http.Request:
"""Build the request of ``GetFileByPath_AasRepository``."""
return _submodel_operations.build_get_file_by_path(
base_url, _submodel_path(aas_identifier, submodel_identifier), id_short_path
)
[docs]
def get_file_by_path(
server: http.Server,
aas_identifier: str,
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 aas_repository.get_file_by_path(
server,
"urn:example:aas:1",
"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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/attachment``
"""
request = _build_get_file_by_path(
server.base_url, aas_identifier, submodel_identifier, id_short_path
)
return _files.download(server, request, {200})
def _build_put_file_by_path(
base_url: str,
aas_identifier: 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_AasRepository``."""
return _submodel_operations.build_put_file_by_path(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_put_file_by_path(response)
[docs]
def put_file_by_path(
server: http.Server,
aas_identifier: str,
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. It must be seekable so that the client
knows the length of the body up-front, and can send the content again, for
example, after a refreshed token. The file object must not be modified during
the upload.
:param server: where to send the request
:param aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``PUT /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/attachment``
"""
request = _build_put_file_by_path(
server.base_url,
aas_identifier,
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, aas_identifier: str, submodel_identifier: str, id_short_path: str
) -> http.Request:
"""Build the request of ``DeleteFileByPath_AasRepository``."""
return _submodel_operations.build_delete_file_by_path(
base_url, _submodel_path(aas_identifier, submodel_identifier), id_short_path
)
def _parse_delete_file_by_path(response: http.Response) -> None:
"""Parse the response of ``DeleteFileByPath_AasRepository``."""
return _submodel_operations.parse_delete_file_by_path(response)
[docs]
def delete_file_by_path(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
:param submodel_identifier: identifier of the submodel
:param id_short_path: ID-short path of the file element, such as ``Manual``
:implements DeleteFileByPath_AasRepository: ``DELETE /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/attachment``
"""
request = _build_delete_file_by_path(
server.base_url, aas_identifier, submodel_identifier, id_short_path
)
response = http.send(server.transport, request)
_parse_delete_file_by_path(response)
def _build_invoke_operation(
base_url: str,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
operation_request: aas_types.OperationRequest,
) -> http.Request:
"""Build the request of ``InvokeOperation_AasRepository``."""
return _submodel_operations.build_invoke_operation(
base_url,
_submodel_path(aas_identifier, submodel_identifier),
id_short_path,
operation_request,
)
def _parse_invoke_operation(response: http.Response) -> aas_types.OperationResult:
"""Parse the response of ``InvokeOperation_AasRepository``."""
return _submodel_operations.parse_invoke_operation(response)
[docs]
def invoke_operation(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``POST /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/invoke``
"""
request = _build_invoke_operation(
server.base_url,
aas_identifier,
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,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
operation_request: aas_types.OperationRequestValueOnly,
) -> http.Request:
"""Build the request of ``InvokeOperation-ValueOnly_AasRepository``."""
return _submodel_operations.build_invoke_operation_value_only(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_invoke_operation_value_only(response)
[docs]
def invoke_operation_value_only(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``POST /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/invoke/$value``
"""
request = _build_invoke_operation_value_only(
server.base_url,
aas_identifier,
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,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
operation_request: aas_types.OperationRequestAsync,
) -> http.Request:
"""Build the request of ``InvokeOperationAsync_AasRepository``."""
return _submodel_operations.build_invoke_operation_async(
base_url,
_submodel_path(aas_identifier, submodel_identifier),
id_short_path,
operation_request,
)
def _parse_invoke_operation_async(response: http.Response) -> aas_types.OperationHandle:
"""Parse the response of ``InvokeOperationAsync_AasRepository``."""
return _submodel_operations.parse_invoke_operation_async(response)
[docs]
def invoke_operation_async(
server: http.Server,
aas_identifier: str,
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 = aas_repository.invoke_operation_async(
server,
"urn:example:aas:1",
"urn:example:submodel:1",
"Control.Start",
aas_types.OperationRequestAsync(client_timeout_duration="PT60S"),
)
while True:
status = aas_repository.get_operation_async_status(
server,
"urn:example:aas:1",
"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 = aas_repository.get_operation_async_result(
server,
"urn:example:aas:1",
"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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``POST /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/invoke-async``
"""
request = _build_invoke_operation_async(
server.base_url,
aas_identifier,
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,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
operation_request: aas_types.OperationRequestAsyncValueOnly,
) -> http.Request:
"""Build the request of ``InvokeOperationAsync-ValueOnly_AasRepository``."""
return _submodel_operations.build_invoke_operation_async_value_only(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_invoke_operation_async_value_only(response)
[docs]
def invoke_operation_async_value_only(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``POST /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/invoke-async/$value``
"""
request = _build_invoke_operation_async_value_only(
server.base_url,
aas_identifier,
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,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
handle_id: str,
) -> http.Request:
"""Build the request of ``GetOperationAsyncStatus_AasRepository``."""
return _submodel_operations.build_get_operation_async_status(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_get_operation_async_status(response)
[docs]
def get_operation_async_status(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/operation-status/{handleId}``
"""
request = _build_get_operation_async_status(
server.base_url, aas_identifier, 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,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
handle_id: str,
) -> http.Request:
"""Build the request of ``GetOperationAsyncResult_AasRepository``."""
return _submodel_operations.build_get_operation_async_result(
base_url,
_submodel_path(aas_identifier, submodel_identifier),
id_short_path,
handle_id,
)
def _parse_get_operation_async_result(
response: http.Response,
) -> aas_types.OperationResult:
"""Parse the response of ``GetOperationAsyncResult_AasRepository``."""
return _submodel_operations.parse_get_operation_async_result(response)
[docs]
def get_operation_async_result(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/operation-results/{handleId}``
"""
request = _build_get_operation_async_result(
server.base_url, aas_identifier, 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,
aas_identifier: str,
submodel_identifier: str,
id_short_path: str,
handle_id: str,
) -> http.Request:
"""Build the request of ``GetOperationAsyncResult-ValueOnly_AasRepository``."""
return _submodel_operations.build_get_operation_async_result_value_only(
base_url,
_submodel_path(aas_identifier, 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_AasRepository``."""
return _submodel_operations.parse_get_operation_async_result_value_only(response)
[docs]
def get_operation_async_result_value_only(
server: http.Server,
aas_identifier: str,
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 aas_identifier: identifier of the Asset Administration Shell
: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_AasRepository: ``GET /shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/operation-results/{handleId}/$value``
"""
request = _build_get_operation_async_result_value_only(
server.base_url, aas_identifier, submodel_identifier, id_short_path, handle_id
)
response = http.send(server.transport, request)
return _parse_get_operation_async_result_value_only(response)