1"""BaSyx Server interface for REST API communication."""
6from pathlib
import Path
10from basyx.aas
import model
12from aas_http_client.classes.client.aas_client
import AasHttpClient, _create_client
13from aas_http_client.classes.wrapper.attachment
import Attachment
14from aas_http_client.classes.wrapper.pagination
import (
15 ReferencePaginatedData,
17 SubmodelElementPaginatedData,
18 SubmodelPaginatedData,
19 create_reference_paging_data,
20 create_shell_paging_data,
21 create_submodel_element_paging_data,
22 create_submodel_paging_data,
27_logger = logging.getLogger(__name__)
31 """Determines the ID encoding mode for API requests."""
38 """String representation of the IdMode enum."""
39 if self == IdEncoding.encoded:
41 if self == IdEncoding.decoded:
48 """Determines the structural depth of the respective resource content."""
55 """String representation of the Level enum."""
56 if self == Level.core:
58 if self == Level.deep:
65 """Determines to which extent the resource is being serialized."""
69 without_blob_value = 2
72 """String representation of the Extent enum."""
73 if self == Extent.with_blob_value:
74 return "withBlobValue"
75 if self == Extent.without_blob_value:
76 return "withoutBlobValue"
82 """Determines to which asset kind the resource is being serialized."""
90 """String representation of the Extent enum."""
91 if self == AssetKind.instance:
93 if self == AssetKind.not_applicable:
94 return "NotApplicable"
95 if self == AssetKind.type:
105 """Represents a wrapper for the BaSyx Python SDK to communicate with a REST API."""
107 _client: AasHttpClient
110 def __init__(self, config_string: str, basic_auth_password: str =
"", o_auth_client_secret: str =
"", bearer_auth_token: str =
""):
111 """Initializes the wrapper with the given configuration.
113 :param config_string: Configuration string for the BaSyx server connection.
114 :param basic_auth_password: Password for the BaSyx server interface client, defaults to "".
115 :param o_auth_client_secret: Client secret for OAuth authentication, defaults to "".
116 :param bearer_auth_token: Bearer token for authentication, defaults to "".
118 client = _create_client(config_string, basic_auth_password, o_auth_client_secret, bearer_auth_token)
121 raise ValueError(
"Failed to create AAS HTTP client with the provided configuration.")
127 """Sets whether to use encoded IDs for API requests.
129 :param encoded_ids: If enabled, all IDs used in API requests have to be base64-encoded
131 if encoded_ids == IdEncoding.encoded:
137 """Gets whether encoded IDs are used for API requests.
139 :return: True if encoded IDs are used, False otherwise
142 return IdEncoding.encoded
144 return IdEncoding.decoded
147 """Returns the underlying AAS HTTP client.
149 :return: The AAS HTTP client instance.
159 """Returns a specific Asset Administration Shell.
161 :param aas_identifier: The Asset Administration Shells unique id (decoded)
162 :return: Asset Administration Shells or None if an error occurred
165 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
168 content = self.
_client_client.shells.get_asset_administration_shell_by_id(aas_identifier)
171 _logger.warning(f
"No shell found with ID '{aas_identifier}' on server.")
174 return _to_object(content)
178 """Creates or replaces an existing Asset Administration Shell.
180 :param aas_identifier: The Asset Administration Shells unique id (decoded)
181 :param aas: Asset Administration Shell to put
182 :return: True if the update was successful, False otherwise
185 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
188 aas_data = _to_dict(aas)
191 _logger.error(f
"Failed to serialize Asset Administration Shell with ID '{aas_identifier}' to dictionary.")
194 return self.
_client_client.shells.put_asset_administration_shell_by_id(aas_identifier, aas_data)
198 """Deletes an Asset Administration Shell.
200 :param aas_identifier: The Asset Administration Shells unique id (decoded)
201 :return: True if the deletion was successful, False otherwise
204 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
207 return self.
_client_client.shells.delete_asset_administration_shell_by_id(aas_identifier)
211 """Downloads the thumbnail of a specific Asset Administration Shell.
213 :param aas_identifier: The Asset Administration Shells unique id (decoded)
214 :return: Attachment object with thumbnail content as bytes (octet-stream) or None if an error occurred
217 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
220 byte_content = self.
_client_client.shells.get_thumbnail_aas_repository(aas_identifier)
223 _logger.warning(f
"No thumbnail found for AAS with ID '{aas_identifier}' on server.")
227 content=byte_content,
228 content_type=puremagic.from_string(byte_content, mime=
True),
229 filename=
"thumbnail",
234 """Creates or updates the thumbnail of the Asset Administration Shell.
236 :param aas_identifier: The Asset Administration Shells unique id
237 :param file_name: The name of the thumbnail file
238 :param file: Path to the thumbnail file to upload as attachment
239 :return: True if the update was successful, False otherwise
242 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
245 return self.
_client_client.shells.put_thumbnail_aas_repository(aas_identifier, file_name, file)
249 """Deletes the thumbnail of a specific Asset Administration Shell.
251 :param aas_identifier: The Asset Administration Shells unique id (decoded)
252 :return: True if the deletion was successful, False otherwise
255 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
258 return self.
_client_client.shells.delete_thumbnail_aas_repository(aas_identifier)
262 self, asset_ids: list[dict] |
None =
None, id_short: str =
"", limit: int = 100, cursor: str =
""
263 ) -> ShellPaginatedData |
None:
264 """Returns all Asset Administration Shells.
266 :param assetIds: A list of specific Asset identifiers (format: {"identifier": "string", "encodedIdentifier": "string"})
267 :param idShort: The Asset Administration Shell's IdShort
268 :param limit: The maximum number of elements in the response array
269 :param cursor: A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue
270 :return: List of paginated Asset Administration Shells or None if an error occurred
273 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
276 content = self.
_client_client.shells.get_all_asset_administration_shells(asset_ids, id_short, limit, cursor)
281 return create_shell_paging_data(content)
285 """Creates a new Asset Administration Shell.
287 :param aas: Asset Administration Shell to post
288 :return: Asset Administration Shell or None if an error occurred
291 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
294 aas_data = _to_dict(aas)
298 content = self.
_client_client.shells.post_asset_administration_shell(aas_data)
302 return _to_object(content)
306 """Returns all submodel references.
308 :param aas_identifier: The Asset Administration Shells unique id
309 :param limit: The maximum number of elements in the response array
310 :param cursor: A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue
311 :return: List of paginated Submodel References or None if an error occurred
314 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
317 references_result = self.
_client_client.shells.get_all_submodel_references_aas_repository(aas_identifier, limit, cursor)
319 if not references_result:
322 return create_reference_paging_data(references_result)
326 """Creates a submodel reference at the Asset Administration Shell.
328 :param aas_identifier: The Asset Administration Shells unique id
329 :param submodel_reference: Reference to the Submodel
330 :return: Reference Submodel object or None if an error occurred
333 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
336 ref_data = _to_dict(submodel_reference)
340 content = self.
_client_client.shells.post_submodel_reference_aas_repository(aas_identifier, ref_data)
344 return _to_object(content)
348 """Deletes the submodel reference from the Asset Administration Shell. Does not delete the submodel itself.
350 :param aas_identifier: The Asset Administration Shells unique id
351 :param submodel_identifier: The Submodels unique id
352 :return: True if the deletion was successful, False otherwise
355 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
358 return self.
_client_client.shells.delete_submodel_reference_by_id_aas_repository(aas_identifier, submodel_identifier)
364 """Updates the Submodel.
366 :param aas_identifier: The Asset Administration Shells unique id (decoded)
367 :param submodel_identifier: ID of the submodel to put
368 :param submodel: Submodel to put
369 :return: True if the update was successful, False otherwise
372 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
375 sm_data = _to_dict(submodel)
380 return self.
_client_client.shells.put_submodel_by_id_aas_repository(aas_identifier, submodel_identifier, sm_data)
384 """Returns a specific Asset Administration Shell as a Reference.
386 :param aas_identifier: ID of the AAS reference to retrieve
387 :return: Asset Administration Shells reference object or None if an error occurred
395 return model.ModelReference.from_referable(aas)
399 """Returns the Submodel.
401 :param aas_identifier: ID of the AAS to retrieve the submodel from
402 :param submodel_identifier: ID of the submodel to retrieve
403 :return: Submodel or None if an error occurred
406 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
409 content = self.
_client_client.shells.get_submodel_by_id_aas_repository(aas_identifier, submodel_identifier)
414 return _to_object(content)
421 def get_submodel_by_id(self, submodel_identifier: str, level: Level = Level.default, extent: Extent = Extent.default) -> model.Submodel |
None:
422 """Returns a specific Submodel.
424 :param submodel_identifier: Encoded ID of the Submodel to retrieve
425 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
426 :param extent: Determines to which extent the resource is being serialized. Available values : withBlobValue, withoutBlobValue
427 :return: Submodel data or None if an error occurred
430 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
433 content = self.
_client_client.submodels.get_submodel_by_id(submodel_identifier, str(level), str(extent))
438 return _to_object(content)
442 """Updates a existing Submodel.
444 :param submodel_identifier: Identifier of the submodel to update
445 :param submodel: Submodel data to update
446 :return: True if the update was successful, False otherwise
449 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
452 sm_data = _to_dict(submodel)
457 return self.
_client_client.submodels.put_submodels_by_id(submodel_identifier, sm_data)
461 """Deletes a Submodel.
463 :param submodel_identifier: ID of the submodel to delete
464 :return: True if the deletion was successful, False otherwise
467 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
470 return self.
_client_client.submodels.delete_submodel_by_id(submodel_identifier)
474 self, submodel_identifier: str, id_short_path: str, level: Level = Level.default, extent: Extent = Extent.default
475 ) -> model.SubmodelElement |
None:
476 """Returns a specific submodel element from the Submodel at a specified path.
478 :param submodel_identifier: Encoded ID of the Submodel to retrieve element from
479 :param id_short_path: Path of the Submodel element to retrieve
480 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
481 :param extent: Determines to which extent the resource is being serialized. Available values : withBlobValue, withoutBlobValue
482 :return: Submodel element data or None if an error occurred
485 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
488 content = self.
_client_client.submodels.get_submodel_element_by_path_submodel_repo(submodel_identifier, id_short_path, str(level), str(extent))
493 return _to_object(content)
497 self, submodel_identifier: str, id_short_path: str, submodel_element: model.SubmodelElement, level: Level = Level.default
499 """Updates a submodel element at a specified path within the submodel elements hierarchy.
501 :param submodel_identifier: Encoded ID of the Submodel to update element for
502 :param id_short_path: Path of the Submodel element to update
503 :param request_body: Submodel element data to update as dictionary
504 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
505 :return: True if the update was successful, False otherwise
508 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
511 sme_data = _to_dict(submodel_element)
516 return self.
_client_client.submodels.put_submodel_element_by_path_submodel_repo(submodel_identifier, id_short_path, sme_data, str(level))
521 submodel_identifier: str,
523 submodel_element: model.SubmodelElement,
524 level: Level = Level.default,
525 extent: Extent = Extent.default,
526 ) -> model.SubmodelElement |
None:
527 """Creates a new submodel element at a specified path within submodel elements hierarchy.
529 :param submodel_identifier: Encoded ID of the submodel to create elements for
530 :param id_short_path: Path within the Submodel elements hierarchy
531 :param submodel_element: The new Submodel element
532 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
533 :param extent: Determines to which extent the resource is being serialized. Available values : withBlobValue, withoutBlobValue
534 :return: Submodel element object or None if an error occurred
537 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
540 sme_data = _to_dict(submodel_element)
545 content = self.
_client_client.submodels.post_submodel_element_by_path_submodel_repo(
546 submodel_identifier, id_short_path, sme_data, str(level), str(extent)
552 return _to_object(content)
557 """Deletes a submodel element at a specified path within the submodel elements hierarchy.
559 :param submodel_identifier: Encoded ID of the Submodel to delete submodel element from
560 :param id_short_path: Path of the Submodel element to delete
561 :return: True if the deletion was successful, False otherwise
564 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
567 return self.
_client_client.submodels.delete_submodel_element_by_path_submodel_repo(submodel_identifier, id_short_path)
572 semantic_id: str =
"",
576 level: Level = Level.default,
577 extent: Extent = Extent.default,
578 ) -> SubmodelPaginatedData |
None:
579 """Returns all Submodels.
581 :param semantic_id: The value of the semantic id reference (UTF8-BASE64-URL-encoded)
582 :param id_short: The idShort of the Submodel
583 :param limit: Maximum number of Submodels to return
584 :param cursor: Cursor for pagination
585 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
586 :param extent: Determines to which extent the resource is being serialized. Available values : withBlobValue, withoutBlobValue
587 :return: List of Submodel or None if an error occurred
590 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
593 content = self.
_client_client.submodels.get_all_submodels(semantic_id, id_short, limit, cursor, str(level), str(extent))
598 return create_submodel_paging_data(content)
601 def post_submodel(self, submodel: model.Submodel) -> model.Submodel |
None:
602 """Creates a new Submodel.
604 :param submodel: Submodel to post
605 :return: Submodel or None if an error occurred
608 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
611 sm_data = _to_dict(submodel)
621 return _to_object(content)
626 submodel_identifier: str,
627 ) -> SubmodelElementPaginatedData |
None:
628 """Returns all submodel elements including their hierarchy. !!!Serialization to model.SubmodelElement currently not possible.
630 :param submodel_identifier: Encoded ID of the Submodel to retrieve elements from
631 :return: List of Submodel elements or None if an error occurred
634 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
637 content = self.
_client_client.submodels.get_all_submodel_elements_submodel_repository(submodel_identifier)
642 return create_submodel_element_paging_data(content)
646 """Creates a new submodel element.
648 :param submodel_identifier: Encoded ID of the Submodel to create elements for
649 :param request_body: Submodel element
650 :return: Submodel or None if an error occurred
653 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
656 sme_data = _to_dict(submodel_element)
661 content = self.
_client_client.submodels.post_submodel_element_submodel_repo(submodel_identifier, sme_data)
666 return _to_object(content)
670 """Synchronously invokes an Operation at a specified path.
672 :param submodel_identifier: The Submodels unique id
673 :param id_short_path: IdShort path to the operation element (dot-separated)
674 :param request_body: Input parameters for the operation
675 :param async_: Determines whether an operation invocation is performed asynchronously or synchronously
676 :return: Operation result or None if an error occurred
679 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
682 content = self.
_client_client.submodels.invoke_operation_submodel_repo(submodel_identifier, id_short_path, request_body, async_)
690 """Retrieves the value of a specific SubmodelElement.
692 :param submodel_identifier: The Submodels unique id
693 :param id_short_path: IdShort path to the submodel element (dot-separated)
694 :return: Submodel element value or None if an error occurred
697 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
700 return self.
_client_client.submodels.get_submodel_element_by_path_value_only_submodel_repo(submodel_identifier, id_short_path)
704 """Updates the value of an existing SubmodelElement.
706 :param submodel_identifier: Encoded ID of the Submodel to update submodel element for
707 :param submodel_element_path: Path of the Submodel element to update
708 :param value: Submodel element value to update as string
709 :return: True if the patch was successful, False otherwise
712 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
715 return self.
_client_client.submodels.patch_submodel_element_by_path_value_only_submodel_repo(submodel_identifier, submodel_element_path, value)
718 def get_submodel_by_id_value_only(self, submodel_identifier: str, level: Level = Level.default, extent: Extent = Extent.default) -> dict |
None:
719 """Returns the value of a specific Submodel.
721 :param submodel_identifier: Encoded ID of the Submodel to retrieve
722 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
723 :param extent: Determines to which extent the resource is being serialized. Available values : withBlobValue, withoutBlobValue
724 :return: Submodel value as dictionary or None if an error occurred
727 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
730 content = self.
_client_client.submodels.get_submodel_by_id_value_only(submodel_identifier, str(level), str(extent))
739 """Updates the values of an existing Submodel.
741 :param submodel_identifier: The Submodels unique id
742 :param request_body: Submodel values to update as dict
743 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
744 :return: True if the patch was successful, False otherwise
747 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
750 return self.
_client_client.submodels.patch_submodel_by_id_value_only(submodel_identifier, request_body, str(level))
754 """Returns the metadata attributes of a specific Submodel.
756 :param submodel_identifier: The Submodels unique id
757 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
758 :return: Metadata attributes of the Submodel as dict or None if an error occurred
761 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
764 content = self.
_client_client.submodels.get_submodel_by_id_metadata(submodel_identifier, str(level))
775 """Updates an existing Submodel.
777 :param submodel_identifier: Encoded ID of the Submodel to delete
778 :return: True if the patch was successful, False otherwise
781 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
784 sm_data = _to_dict(submodel)
789 return self.
_client_client.submodels.patch_submodel_by_id(submodel_identifier, sm_data)
803 """Downloads file content from a specific submodel element from the Submodel at a specified path. Experimental feature - may not be supported by all servers.
805 :param submodel_identifier: The Submodels unique id
806 :param id_short_path: IdShort path to the submodel element (dot-separated)
807 :return: Attachment object with file content as bytes (octet-stream) or None if an error occurred
810 _logger.error(
"Experimental API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
815 if not sme
or not isinstance(sme, model.File):
816 _logger.warning(f
"No submodel element found at path '{id_short_path}' in submodel '{submodel_identifier}' on server.")
819 byte_content = self.
_client_client.experimental.get_file_by_path_submodel_repo(submodel_identifier, id_short_path)
822 _logger.warning(f
"No file found at path '{id_short_path}' in submodel '{submodel_identifier}' on server.")
826 content=byte_content,
827 content_type=puremagic.from_string(byte_content, mime=
True),
833 """Uploads file content to an existing submodel element at a specified path within submodel elements hierarchy. Experimental feature - may not be supported by all servers.
835 :param submodel_identifier: The Submodels unique id
836 :param id_short_path: IdShort path to the submodel element (dot-separated)
837 :param file: Path to the file to upload as attachment
838 :return: Attachment data as bytes or None if an error occurred
841 _logger.error(
"Experimental API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
844 return self.
_client_client.experimental.post_file_by_path_submodel_repo(submodel_identifier, id_short_path, file)
847 """Uploads file content to an existing submodel element at a specified path within submodel elements hierarchy. Experimental feature - may not be supported by all servers.
849 :param submodel_identifier: The Submodels unique id
850 :param id_short_path: IdShort path to the submodel element (dot-separated)
851 :param file: Path to the file to upload as attachment
852 :return: Attachment data as bytes or None if an error occurred
855 _logger.error(
"Experimental API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
858 return self.
_client_client.experimental.put_file_by_path_submodel_repo(submodel_identifier, id_short_path, file)
861 """Deletes file content of an existing submodel element at a specified path within submodel elements hierarchy. Experimental feature - may not be supported by all servers.
863 :param submodel_identifier: The Submodels unique id
864 :param id_short_path: IdShort path to the submodel element (dot-separated)
865 :return: True if deletion was successful, False otherwise
868 _logger.error(
"Experimental API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
871 return self.
_client_client.experimental.delete_file_by_path_submodel_repo(submodel_identifier, id_short_path)
879def create_wrapper_by_url(
881 basic_auth_username: str =
"",
882 basic_auth_password: str =
"",
883 o_auth_client_id: str =
"",
884 o_auth_client_secret: str =
"",
885 o_auth_token_url: str =
"",
886 bearer_auth_token: str =
"",
887 http_proxy: str =
"",
888 https_proxy: str =
"",
890 connection_time_out: int = 60,
891 ssl_verify: bool =
True,
892 trust_env: bool =
True,
893 encoded_ids: bool =
True,
894) -> SdkWrapper |
None:
895 """Create a wrapper for a AAS server connection from the given parameters.
897 :param base_url: Base URL of the AAS server, e.g. "http://basyx_python_server:80/"
898 :param basic_auth_username: Username for the AAS server basic authentication, defaults to ""
899 :param basic_auth_password: Password for the AAS server basic authentication, defaults to ""
900 :param o_auth_client_id: Client ID for OAuth authentication, defaults to ""
901 :param o_auth_client_secret: Client secret for OAuth authentication, defaults to ""
902 :param o_auth_token_url: Token URL for OAuth authentication, defaults to ""
903 :param bearer_auth_token: Bearer token for authentication, defaults to ""
904 :param http_proxy: HTTP proxy URL, defaults to ""
905 :param https_proxy: HTTPS proxy URL, defaults to ""
906 :param time_out: Timeout for the API calls, defaults to 200
907 :param connection_time_out: Timeout for the connection to the API, defaults to 60
908 :param ssl_verify: Whether to verify SSL certificates, defaults to True
909 :param trust_env: Whether to trust environment variables for proxy settings, defaults to True
910 :param encoded_ids: If enabled, all IDs used in API requests have to be base64-encoded
911 :return: An instance of SdkWrapper initialized with the provided parameters or None if initialization fails
913 _logger.info(f
"Create AAS server http client from URL '{base_url}'.")
914 config_dict: dict[str, Any] = {}
915 config_dict[
"BaseUrl"] = base_url
916 config_dict[
"HttpProxy"] = http_proxy
917 config_dict[
"HttpsProxy"] = https_proxy
918 config_dict[
"TimeOut"] = str(time_out)
919 config_dict[
"ConnectionTimeOut"] = str(connection_time_out)
920 config_dict[
"SslVerify"] = str(ssl_verify)
921 config_dict[
"TrustEnv"] = str(trust_env)
922 config_dict[
"EncodedIds"] = str(encoded_ids)
924 config_dict[
"AuthenticationSettings"] = {
925 "BasicAuth": {
"Username": basic_auth_username},
927 "ClientId": o_auth_client_id,
928 "TokenUrl": o_auth_token_url,
932 return create_wrapper_by_dict(config_dict, basic_auth_password, o_auth_client_secret, bearer_auth_token)
935def create_wrapper_by_dict(
936 configuration: dict, basic_auth_password: str =
"", o_auth_client_secret: str =
"", bearer_auth_token: str =
""
937) -> SdkWrapper |
None:
938 """Create a wrapper for a AAS server connection from the given configuration.
940 :param configuration: Dictionary containing the AAS server connection settings
941 :param basic_auth_password: Password for the AAS server basic authentication, defaults to ""
942 :param o_auth_client_secret: Client secret for OAuth authentication, defaults to ""
943 :param bearer_auth_token: Bearer token for authentication, defaults to ""
944 :return: An instance of SdkWrapper initialized with the provided parameters or None if initialization fails
946 _logger.info(
"Create AAS server wrapper from dictionary.")
947 config_string = json.dumps(configuration, indent=4)
948 return SdkWrapper(config_string, basic_auth_password, o_auth_client_secret, bearer_auth_token)
951def create_wrapper_by_config(
952 config_file: Path, basic_auth_password: str =
"", o_auth_client_secret: str =
"", bearer_auth_token: str =
""
953) -> SdkWrapper |
None:
954 """Create a wrapper for a AAS server connection from a given configuration file.
956 :param config_file: Path to the configuration file containing the AAS server connection settings
957 :param basic_auth_password: Password for the AAS server basic authentication, defaults to ""
958 :param o_auth_client_secret: Client secret for OAuth authentication, defaults to ""
959 :param bearer_auth_token: Bearer token for authentication, defaults to ""
960 :return: An instance of SdkWrapper initialized with the provided parameters or None if initialization fails
962 _logger.info(f
"Create AAS wrapper client from configuration file '{config_file}'.")
963 if not config_file.exists():
965 _logger.warning(f
"Configuration file '{config_file}' not found. Using default config.")
967 config_string = config_file.read_text(encoding=
"utf-8")
968 _logger.debug(f
"Configuration file '{config_file}' found.")
969 return SdkWrapper(config_string, basic_auth_password, o_auth_client_secret, bearer_auth_token)
Determines to which asset kind the resource is being serialized.
str __str__(self)
String representation of the Extent enum.
Determines to which extent the resource is being serialized.
str __str__(self)
String representation of the Extent enum.
Determines the ID encoding mode for API requests.
str __str__(self)
String representation of the IdMode enum.
Determines the structural depth of the respective resource content.
str __str__(self)
String representation of the Level enum.
Represents a wrapper for the BaSyx Python SDK to communicate with a REST API.
bool experimental_put_file_by_path_submodel_repo(self, str submodel_identifier, str id_short_path, Path file)
Uploads file content to an existing submodel element at a specified path within submodel elements hie...
bool put_thumbnail_aas_repository(self, str aas_identifier, str file_name, Path file)
Creates or updates the thumbnail of the Asset Administration Shell.
bool experimental_delete_file_by_path_submodel_repo(self, str submodel_identifier, str id_short_path)
Deletes file content of an existing submodel element at a specified path within submodel elements hie...
bool put_asset_administration_shell_by_id(self, str aas_identifier, model.AssetAdministrationShell aas)
Creates or replaces an existing Asset Administration Shell.
bool delete_asset_administration_shell_by_id(self, str aas_identifier)
Deletes an Asset Administration Shell.
bool put_submodel_element_by_path_submodel_repo(self, str submodel_identifier, str id_short_path, model.SubmodelElement submodel_element, Level level=Level.default)
Updates a submodel element at a specified path within the submodel elements hierarchy.
bool put_submodels_by_id(self, str submodel_identifier, model.Submodel submodel)
Updates a existing Submodel.
model.SubmodelElement|None get_submodel_element_by_path_submodel_repo(self, str submodel_identifier, str id_short_path, Level level=Level.default, Extent extent=Extent.default)
Returns a specific submodel element from the Submodel at a specified path.
bool delete_thumbnail_aas_repository(self, str aas_identifier)
Deletes the thumbnail of a specific Asset Administration Shell.
bool patch_submodel_element_by_path_value_only_submodel_repo(self, str submodel_identifier, str submodel_element_path, str value)
Updates the value of an existing SubmodelElement.
model.Submodel|None get_submodel_by_id(self, str submodel_identifier, Level level=Level.default, Extent extent=Extent.default)
Returns a specific Submodel.
AasHttpClient get_client(self)
Returns the underlying AAS HTTP client.
dict|None invoke_operation_submodel_repo(self, str submodel_identifier, str id_short_path, dict request_body, str async_="async")
Synchronously invokes an Operation at a specified path.
bool patch_submodel_by_id_value_only(self, str submodel_identifier, dict request_body, Level level=Level.default)
Updates the values of an existing Submodel.
model.AssetAdministrationShell|None get_asset_administration_shell_by_id(self, str aas_identifier)
Returns a specific Asset Administration Shell.
ReferencePaginatedData|None get_all_submodel_references_aas_repository(self, str aas_identifier, int limit=100, str cursor="")
Returns all submodel references.
Attachment|None experimental_get_file_by_path_submodel_repo(self, str submodel_identifier, str id_short_path)
Downloads file content from a specific submodel element from the Submodel at a specified path.
SubmodelElementPaginatedData|None get_all_submodel_elements_submodel_repository(self, str submodel_identifier)
Returns all submodel elements including their hierarchy.
set_encoded_ids(self, IdEncoding encoded_ids)
Sets whether to use encoded IDs for API requests.
SubmodelPaginatedData|None get_all_submodels(self, str semantic_id="", str id_short="", int limit=0, str cursor="", Level level=Level.default, Extent extent=Extent.default)
Returns all Submodels.
model.Reference|None get_asset_administration_shell_by_id_reference_aas_repository(self, str aas_identifier)
Returns a specific Asset Administration Shell as a Reference.
bool patch_submodel_by_id(self, str submodel_identifier, model.Submodel submodel)
Updates an existing Submodel.
model.SubmodelElement|None post_submodel_element_submodel_repo(self, str submodel_identifier, model.SubmodelElement submodel_element)
Creates a new submodel element.
IdEncoding get_encoded_ids(self)
Gets whether encoded IDs are used for API requests.
dict|None get_submodel_by_id_value_only(self, str submodel_identifier, Level level=Level.default, Extent extent=Extent.default)
Returns the value of a specific Submodel.
model.SubmodelElement|None post_submodel_element_by_path_submodel_repo(self, str submodel_identifier, str id_short_path, model.SubmodelElement submodel_element, Level level=Level.default, Extent extent=Extent.default)
Creates a new submodel element at a specified path within submodel elements hierarchy.
__init__(self, str config_string, str basic_auth_password="", str o_auth_client_secret="", str bearer_auth_token="")
Initializes the wrapper with the given configuration.
str|None get_submodel_element_by_path_value_only_submodel_repo(self, str submodel_identifier, str id_short_path)
Retrieves the value of a specific SubmodelElement.
Attachment|None get_thumbnail_aas_repository(self, str aas_identifier)
Downloads the thumbnail of a specific Asset Administration Shell.
bool put_submodel_by_id_aas_repository(self, str aas_identifier, str submodel_identifier, model.Submodel submodel)
Updates the Submodel.
model.Submodel|None post_submodel(self, model.Submodel submodel)
Creates a new Submodel.
model.AssetAdministrationShell|None post_asset_administration_shell(self, model.AssetAdministrationShell aas)
Creates a new Asset Administration Shell.
model.ModelReference|None post_submodel_reference_aas_repository(self, str aas_identifier, model.ModelReference submodel_reference)
Creates a submodel reference at the Asset Administration Shell.
dict|None get_submodel_by_id_metadata(self, str submodel_identifier, str level="")
Returns the metadata attributes of a specific Submodel.
bool delete_submodel_by_id(self, str submodel_identifier)
Deletes a Submodel.
model.Submodel|None get_submodel_by_id_aas_repository(self, str aas_identifier, str submodel_identifier)
Returns the Submodel.
bool experimental_post_file_by_path_submodel_repo(self, str submodel_identifier, str id_short_path, Path file)
Uploads file content to an existing submodel element at a specified path within submodel elements hie...
bool delete_submodel_element_by_path_submodel_repo(self, str submodel_identifier, str id_short_path)
Deletes a submodel element at a specified path within the submodel elements hierarchy.
ShellPaginatedData|None get_all_asset_administration_shells(self, list[dict]|None asset_ids=None, str id_short="", int limit=100, str cursor="")
Returns all Asset Administration Shells.
bool delete_submodel_reference_by_id_aas_repository(self, str aas_identifier, str submodel_identifier)
Deletes the submodel reference from the Asset Administration Shell.