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,
28_logger = logging.getLogger(__name__)
32 """Determines the ID encoding mode for API requests."""
39 """String representation of the IdMode enum."""
40 if self == IdEncoding.encoded:
42 if self == IdEncoding.decoded:
49 """Determines the structural depth of the respective resource content."""
56 """String representation of the Level enum."""
57 if self == Level.core:
59 if self == Level.deep:
66 """Determines to which extent the resource is being serialized."""
70 without_blob_value = 2
73 """String representation of the Extent enum."""
74 if self == Extent.with_blob_value:
75 return "withBlobValue"
76 if self == Extent.without_blob_value:
77 return "withoutBlobValue"
83 """Determines to which asset kind the resource is being serialized."""
91 """String representation of the Extent enum."""
92 if self == AssetKind.instance:
94 if self == AssetKind.not_applicable:
95 return "NotApplicable"
96 if self == AssetKind.type:
106 """Represents a wrapper for the BaSyx Python SDK to communicate with a REST API."""
108 _client: AasHttpClient
111 def __init__(self, configuration: dict, basic_auth_password: str =
"", o_auth_client_secret: str =
"", bearer_auth_token: str =
""):
112 """Initializes the wrapper with the given configuration.
114 :param configuration: Dictionary containing the BaSyx server connection settings.
115 :param basic_auth_password: Password for the BaSyx server interface client, defaults to "".
116 :param o_auth_client_secret: Client secret for OAuth authentication, defaults to "".
117 :param bearer_auth_token: Bearer token for authentication, defaults to "".
119 client = _create_client(configuration, basic_auth_password, o_auth_client_secret, bearer_auth_token)
122 raise ValueError(
"Failed to create AAS HTTP client with the provided configuration.")
128 """Sets the log intensity level for the client.
130 :param intensity: LogIntensity level to set (Standard or High)
135 """Sets whether to use encoded IDs for API requests.
137 :param encoded_ids: If enabled, all IDs used in API requests have to be base64-encoded
139 if encoded_ids == IdEncoding.encoded:
145 """Gets whether encoded IDs are used for API requests.
147 :return: True if encoded IDs are used, False otherwise
150 return IdEncoding.encoded
152 return IdEncoding.decoded
155 """Returns the underlying AAS HTTP client.
157 :return: The AAS HTTP client instance.
167 """Returns a specific Asset Administration Shell.
169 :param aas_identifier: The Asset Administration Shells unique id (decoded)
170 :return: Asset Administration Shells or None if an error occurred
173 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
176 content = self.
_client_client.shells.get_asset_administration_shell_by_id(aas_identifier)
179 _logger.warning(f
"No shell found with ID '{aas_identifier}' on server.")
182 return _to_object(content)
186 """Creates or replaces an existing Asset Administration Shell.
188 :param aas_identifier: The Asset Administration Shells unique id (decoded)
189 :param aas: Asset Administration Shell to put
190 :return: True if the update was successful, False otherwise
193 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
196 aas_data = _to_dict(aas)
199 _logger.error(f
"Failed to serialize Asset Administration Shell with ID '{aas_identifier}' to dictionary.")
202 return self.
_client_client.shells.put_asset_administration_shell_by_id(aas_identifier, aas_data)
206 """Deletes an Asset Administration Shell.
208 :param aas_identifier: The Asset Administration Shells unique id (decoded)
209 :return: True if the deletion was successful, False otherwise
212 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
215 return self.
_client_client.shells.delete_asset_administration_shell_by_id(aas_identifier)
219 """Downloads the thumbnail of a specific Asset Administration Shell.
221 :param aas_identifier: The Asset Administration Shells unique id (decoded)
222 :return: Attachment object with thumbnail content as bytes (octet-stream) or None if an error occurred
225 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
228 byte_content = self.
_client_client.shells.get_thumbnail_aas_repository(aas_identifier)
231 _logger.warning(f
"No thumbnail found for AAS with ID '{aas_identifier}' on server.")
235 content=byte_content,
236 content_type=puremagic.from_string(byte_content, mime=
True),
237 filename=
"thumbnail",
242 """Creates or updates the thumbnail of the Asset Administration Shell.
244 :param aas_identifier: The Asset Administration Shells unique id
245 :param file_name: The name of the thumbnail file
246 :param file: Path to the thumbnail file to upload as attachment
247 :return: True if the update was successful, False otherwise
250 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
253 return self.
_client_client.shells.put_thumbnail_aas_repository(aas_identifier, file_name, file)
257 """Deletes the thumbnail of a specific Asset Administration Shell.
259 :param aas_identifier: The Asset Administration Shells unique id (decoded)
260 :return: True if the deletion was successful, False otherwise
263 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
266 return self.
_client_client.shells.delete_thumbnail_aas_repository(aas_identifier)
270 self, asset_ids: list[dict] |
None =
None, id_short: str =
"", limit: int = 100, cursor: str =
""
271 ) -> ShellPaginatedData |
None:
272 """Returns all Asset Administration Shells.
274 :param assetIds: A list of specific Asset identifiers (format: {"identifier": "string", "encodedIdentifier": "string"})
275 :param idShort: The Asset Administration Shell's IdShort
276 :param limit: The maximum number of elements in the response array
277 :param cursor: A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue
278 :return: List of paginated Asset Administration Shells or None if an error occurred
281 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
284 content = self.
_client_client.shells.get_all_asset_administration_shells(asset_ids, id_short, limit, cursor)
289 return create_shell_paging_data(content)
293 """Creates a new Asset Administration Shell.
295 :param aas: Asset Administration Shell to post
296 :return: Asset Administration Shell or None if an error occurred
299 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
302 aas_data = _to_dict(aas)
306 content = self.
_client_client.shells.post_asset_administration_shell(aas_data)
310 return _to_object(content)
314 """Returns all submodel references.
316 :param aas_identifier: The Asset Administration Shells unique id
317 :param limit: The maximum number of elements in the response array
318 :param cursor: A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue
319 :return: List of paginated Submodel References or None if an error occurred
322 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
325 references_result = self.
_client_client.shells.get_all_submodel_references_aas_repository(aas_identifier, limit, cursor)
327 if not references_result:
330 return create_reference_paging_data(references_result)
334 """Creates a submodel reference at the Asset Administration Shell.
336 :param aas_identifier: The Asset Administration Shells unique id
337 :param submodel_reference: Reference to the Submodel
338 :return: Reference Submodel object or None if an error occurred
341 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
344 ref_data = _to_dict(submodel_reference)
348 content = self.
_client_client.shells.post_submodel_reference_aas_repository(aas_identifier, ref_data)
352 return _to_object(content)
356 """Deletes the submodel reference from the Asset Administration Shell. Does not delete the submodel itself.
358 :param aas_identifier: The Asset Administration Shells unique id
359 :param submodel_identifier: The Submodels unique id
360 :return: True if the deletion was successful, False otherwise
363 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
366 return self.
_client_client.shells.delete_submodel_reference_by_id_aas_repository(aas_identifier, submodel_identifier)
372 """Updates the Submodel.
374 :param aas_identifier: The Asset Administration Shells unique id (decoded)
375 :param submodel_identifier: ID of the submodel to put
376 :param submodel: Submodel to put
377 :return: True if the update was successful, False otherwise
380 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
383 sm_data = _to_dict(submodel)
388 return self.
_client_client.shells.put_submodel_by_id_aas_repository(aas_identifier, submodel_identifier, sm_data)
392 """Returns a specific Asset Administration Shell as a Reference.
394 :param aas_identifier: ID of the AAS reference to retrieve
395 :return: Asset Administration Shells reference object or None if an error occurred
403 return model.ModelReference.from_referable(aas)
407 """Returns the Submodel.
409 :param aas_identifier: ID of the AAS to retrieve the submodel from
410 :param submodel_identifier: ID of the submodel to retrieve
411 :return: Submodel or None if an error occurred
414 _logger.error(
"Shell API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
417 content = self.
_client_client.shells.get_submodel_by_id_aas_repository(aas_identifier, submodel_identifier)
422 return _to_object(content)
429 def get_submodel_by_id(self, submodel_identifier: str, level: Level = Level.default, extent: Extent = Extent.default) -> model.Submodel |
None:
430 """Returns a specific Submodel.
432 :param submodel_identifier: Encoded ID of the Submodel to retrieve
433 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
434 :param extent: Determines to which extent the resource is being serialized. Available values : withBlobValue, withoutBlobValue
435 :return: Submodel data or None if an error occurred
438 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
441 content = self.
_client_client.submodels.get_submodel_by_id(submodel_identifier, str(level), str(extent))
446 return _to_object(content)
450 """Updates a existing Submodel.
452 :param submodel_identifier: Identifier of the submodel to update
453 :param submodel: Submodel data to update
454 :return: True if the update was successful, False otherwise
457 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
460 sm_data = _to_dict(submodel)
465 return self.
_client_client.submodels.put_submodels_by_id(submodel_identifier, sm_data)
469 """Deletes a Submodel.
471 :param submodel_identifier: ID of the submodel to delete
472 :return: True if the deletion was successful, False otherwise
475 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
478 return self.
_client_client.submodels.delete_submodel_by_id(submodel_identifier)
482 self, submodel_identifier: str, id_short_path: str, level: Level = Level.default, extent: Extent = Extent.default
483 ) -> model.SubmodelElement |
None:
484 """Returns a specific submodel element from the Submodel at a specified path.
486 :param submodel_identifier: Encoded ID of the Submodel to retrieve element from
487 :param id_short_path: Path of the Submodel element to retrieve
488 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
489 :param extent: Determines to which extent the resource is being serialized. Available values : withBlobValue, withoutBlobValue
490 :return: Submodel element data or None if an error occurred
493 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
496 content = self.
_client_client.submodels.get_submodel_element_by_path_submodel_repo(submodel_identifier, id_short_path, str(level), str(extent))
501 return _to_object(content)
505 self, submodel_identifier: str, id_short_path: str, submodel_element: model.SubmodelElement, level: Level = Level.default
507 """Updates a submodel element at a specified path within the submodel elements hierarchy.
509 :param submodel_identifier: Encoded ID of the Submodel to update element for
510 :param id_short_path: Path of the Submodel element to update
511 :param request_body: Submodel element data to update as dictionary
512 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
513 :return: True if the update was successful, False otherwise
516 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
519 sme_data = _to_dict(submodel_element)
524 return self.
_client_client.submodels.put_submodel_element_by_path_submodel_repo(submodel_identifier, id_short_path, sme_data, str(level))
529 submodel_identifier: str,
531 submodel_element: model.SubmodelElement,
532 level: Level = Level.default,
533 extent: Extent = Extent.default,
534 ) -> model.SubmodelElement |
None:
535 """Creates a new submodel element at a specified path within submodel elements hierarchy.
537 :param submodel_identifier: Encoded ID of the submodel to create elements for
538 :param id_short_path: Path within the Submodel elements hierarchy
539 :param submodel_element: The new Submodel element
540 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
541 :param extent: Determines to which extent the resource is being serialized. Available values : withBlobValue, withoutBlobValue
542 :return: Submodel element object or None if an error occurred
545 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
548 sme_data = _to_dict(submodel_element)
553 content = self.
_client_client.submodels.post_submodel_element_by_path_submodel_repo(
554 submodel_identifier, id_short_path, sme_data, str(level), str(extent)
560 return _to_object(content)
565 """Deletes a submodel element at a specified path within the submodel elements hierarchy.
567 :param submodel_identifier: Encoded ID of the Submodel to delete submodel element from
568 :param id_short_path: Path of the Submodel element to delete
569 :return: True if the deletion was successful, False otherwise
572 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
575 return self.
_client_client.submodels.delete_submodel_element_by_path_submodel_repo(submodel_identifier, id_short_path)
580 semantic_id: str =
"",
584 level: Level = Level.default,
585 extent: Extent = Extent.default,
586 ) -> SubmodelPaginatedData |
None:
587 """Returns all Submodels.
589 :param semantic_id: The value of the semantic id reference (UTF8-BASE64-URL-encoded)
590 :param id_short: The idShort of the Submodel
591 :param limit: Maximum number of Submodels to return
592 :param cursor: Cursor for pagination
593 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
594 :param extent: Determines to which extent the resource is being serialized. Available values : withBlobValue, withoutBlobValue
595 :return: List of Submodel or None if an error occurred
598 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
601 content = self.
_client_client.submodels.get_all_submodels(semantic_id, id_short, limit, cursor, str(level), str(extent))
606 return create_submodel_paging_data(content)
609 def post_submodel(self, submodel: model.Submodel) -> model.Submodel |
None:
610 """Creates a new Submodel.
612 :param submodel: Submodel to post
613 :return: Submodel or None if an error occurred
616 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
619 sm_data = _to_dict(submodel)
629 return _to_object(content)
634 submodel_identifier: str,
635 ) -> SubmodelElementPaginatedData |
None:
636 """Returns all submodel elements including their hierarchy. !!!Serialization to model.SubmodelElement currently not possible.
638 :param submodel_identifier: Encoded ID of the Submodel to retrieve elements from
639 :return: List of Submodel elements or None if an error occurred
642 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
645 content = self.
_client_client.submodels.get_all_submodel_elements_submodel_repository(submodel_identifier)
650 return create_submodel_element_paging_data(content)
654 """Creates a new submodel element.
656 :param submodel_identifier: Encoded ID of the Submodel to create elements for
657 :param request_body: Submodel element
658 :return: Submodel or None if an error occurred
661 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
664 sme_data = _to_dict(submodel_element)
669 content = self.
_client_client.submodels.post_submodel_element_submodel_repo(submodel_identifier, sme_data)
674 return _to_object(content)
678 """Synchronously invokes an Operation at a specified path.
680 :param submodel_identifier: The Submodels unique id
681 :param id_short_path: IdShort path to the operation element (dot-separated)
682 :param request_body: Input parameters for the operation
683 :param async_: Determines whether an operation invocation is performed asynchronously or synchronously
684 :return: Operation result or None if an error occurred
687 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
690 content = self.
_client_client.submodels.invoke_operation_submodel_repo(submodel_identifier, id_short_path, request_body, async_)
698 """Retrieves the value of a specific SubmodelElement.
700 :param submodel_identifier: The Submodels unique id
701 :param id_short_path: IdShort path to the submodel element (dot-separated)
702 :return: Submodel element value or None if an error occurred
705 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
708 return self.
_client_client.submodels.get_submodel_element_by_path_value_only_submodel_repo(submodel_identifier, id_short_path)
712 """Updates the value of an existing SubmodelElement.
714 :param submodel_identifier: Encoded ID of the Submodel to update submodel element for
715 :param submodel_element_path: Path of the Submodel element to update
716 :param value: Submodel element value to update as string
717 :return: True if the patch was successful, False otherwise
720 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
723 return self.
_client_client.submodels.patch_submodel_element_by_path_value_only_submodel_repo(submodel_identifier, submodel_element_path, value)
726 def get_submodel_by_id_value_only(self, submodel_identifier: str, level: Level = Level.default, extent: Extent = Extent.default) -> dict |
None:
727 """Returns the value of a specific Submodel.
729 :param submodel_identifier: Encoded ID of the Submodel to retrieve
730 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
731 :param extent: Determines to which extent the resource is being serialized. Available values : withBlobValue, withoutBlobValue
732 :return: Submodel value as dictionary or None if an error occurred
735 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
738 content = self.
_client_client.submodels.get_submodel_by_id_value_only(submodel_identifier, str(level), str(extent))
747 """Updates the values of an existing Submodel.
749 :param submodel_identifier: The Submodels unique id
750 :param request_body: Submodel values to update as dict
751 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
752 :return: True if the patch was successful, False otherwise
755 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
758 return self.
_client_client.submodels.patch_submodel_by_id_value_only(submodel_identifier, request_body, str(level))
762 """Returns the metadata attributes of a specific Submodel.
764 :param submodel_identifier: The Submodels unique id
765 :param level: Determines the structural depth of the respective resource content. Available values : deep, core
766 :return: Metadata attributes of the Submodel as dict or None if an error occurred
769 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
772 content = self.
_client_client.submodels.get_submodel_by_id_metadata(submodel_identifier, str(level))
783 """Updates an existing Submodel.
785 :param submodel_identifier: Encoded ID of the Submodel to delete
786 :return: True if the patch was successful, False otherwise
789 _logger.error(
"Submodel API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
792 sm_data = _to_dict(submodel)
797 return self.
_client_client.submodels.patch_submodel_by_id(submodel_identifier, sm_data)
811 """Downloads file content from a specific submodel element from the Submodel at a specified path. Experimental feature - may not be supported by all servers.
813 :param submodel_identifier: The Submodels unique id
814 :param id_short_path: IdShort path to the submodel element (dot-separated)
815 :return: Attachment object with file content as bytes (octet-stream) or None if an error occurred
818 _logger.error(
"Experimental API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
823 if not sme
or not isinstance(sme, model.File):
824 _logger.warning(f
"No submodel element found at path '{id_short_path}' in submodel '{submodel_identifier}' on server.")
827 byte_content = self.
_client_client.experimental.get_file_by_path_submodel_repo(submodel_identifier, id_short_path)
830 _logger.warning(f
"No file found at path '{id_short_path}' in submodel '{submodel_identifier}' on server.")
834 content=byte_content,
835 content_type=puremagic.from_string(byte_content, mime=
True),
841 """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.
843 :param submodel_identifier: The Submodels unique id
844 :param id_short_path: IdShort path to the submodel element (dot-separated)
845 :param file: Path to the file to upload as attachment
846 :return: Attachment data as bytes or None if an error occurred
849 _logger.error(
"Experimental API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
852 return self.
_client_client.experimental.post_file_by_path_submodel_repo(submodel_identifier, id_short_path, file)
856 self, submodel_identifier: str, id_short_path: str, file_octet_stream: Any, mime_type: str =
"application/octet-stream"
858 """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.
860 :param submodel_identifier: The Submodels unique id
861 :param id_short_path: IdShort path to the submodel element (dot-separated)
862 :param file_octet_stream: File content as a byte stream
863 :param mime_type: MIME type of the file content, defaults to "application/octet-stream"
864 :return: Attachment data as bytes or None if an error occurred
867 _logger.error(
"Experimental API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
870 return self.
_client_client.experimental.post_file_by_path_submodel_repo_stream(submodel_identifier, id_short_path, file_octet_stream, mime_type)
874 """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.
876 :param submodel_identifier: The Submodels unique id
877 :param id_short_path: IdShort path to the submodel element (dot-separated)
878 :param file: Path to the file to upload as attachment
879 :return: Attachment data as bytes or None if an error occurred
882 _logger.error(
"Experimental API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
885 return self.
_client_client.experimental.put_file_by_path_submodel_repo(submodel_identifier, id_short_path, file)
889 self, submodel_identifier: str, id_short_path: str, file_octet_stream: Any, mime_type: str =
"application/octet-stream"
891 """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.
893 :param submodel_identifier: The Submodels unique id
894 :param id_short_path: IdShort path to the submodel element (dot-separated)
895 :param file: Path to the file to upload as attachment
896 :return: Attachment data as bytes or None if an error occurred
899 _logger.error(
"Experimental API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
902 return self.
_client_client.experimental.put_file_by_path_submodel_repo_stream(submodel_identifier, id_short_path, file_octet_stream, mime_type)
905 """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.
907 :param submodel_identifier: The Submodels unique id
908 :param id_short_path: IdShort path to the submodel element (dot-separated)
909 :return: True if deletion was successful, False otherwise
912 _logger.error(
"Experimental API is not initialized in the client. Call 'initialize()' method of the client before calling this method.")
915 return self.
_client_client.experimental.delete_file_by_path_submodel_repo(submodel_identifier, id_short_path)
925 basic_auth_username: str =
"",
926 basic_auth_password: str =
"",
927 o_auth_client_id: str =
"",
928 o_auth_client_secret: str =
"",
929 o_auth_token_url: str =
"",
930 bearer_auth_token: str =
"",
931 http_proxy: str =
"",
932 https_proxy: str =
"",
934 connection_time_out: int = 60,
935 ssl_verify: bool =
True,
936 trust_env: bool =
True,
937 encoded_ids: bool =
True,
938) -> SdkWrapper |
None:
939 """Create a wrapper for a AAS server connection from the given parameters.
941 :param base_url: Base URL of the AAS server, e.g. "http://basyx_python_server:80/"
942 :param basic_auth_username: Username for the AAS server basic authentication, defaults to ""
943 :param basic_auth_password: Password for the AAS server basic authentication, defaults to ""
944 :param o_auth_client_id: Client ID for OAuth authentication, defaults to ""
945 :param o_auth_client_secret: Client secret for OAuth authentication, defaults to ""
946 :param o_auth_token_url: Token URL for OAuth authentication, defaults to ""
947 :param bearer_auth_token: Bearer token for authentication, defaults to ""
948 :param http_proxy: HTTP proxy URL, defaults to ""
949 :param https_proxy: HTTPS proxy URL, defaults to ""
950 :param time_out: Timeout for the API calls, defaults to 200
951 :param connection_time_out: Timeout for the connection to the API, defaults to 60
952 :param ssl_verify: Whether to verify SSL certificates, defaults to True
953 :param trust_env: Whether to trust environment variables for proxy settings, defaults to True
954 :param encoded_ids: If enabled, all IDs used in API requests have to be base64-encoded
955 :return: An instance of SdkWrapper initialized with the provided parameters or None if initialization fails
957 _logger.debug(f
"Create AAS server http client from URL '{base_url}'.")
958 config_dict: dict[str, Any] = {}
959 config_dict[
"BaseUrl"] = base_url
960 config_dict[
"HttpProxy"] = http_proxy
961 config_dict[
"HttpsProxy"] = https_proxy
962 config_dict[
"TimeOut"] = str(time_out)
963 config_dict[
"ConnectionTimeOut"] = str(connection_time_out)
964 config_dict[
"SslVerify"] = str(ssl_verify)
965 config_dict[
"TrustEnv"] = str(trust_env)
966 config_dict[
"EncodedIds"] = str(encoded_ids)
968 config_dict[
"AuthenticationSettings"] = {
969 "BasicAuth": {
"Username": basic_auth_username},
971 "ClientId": o_auth_client_id,
972 "TokenUrl": o_auth_token_url,
976 return create_by_dict(config_dict, basic_auth_password, o_auth_client_secret, bearer_auth_token)
980 configuration: dict, basic_auth_password: str =
"", o_auth_client_secret: str =
"", bearer_auth_token: str =
""
981) -> SdkWrapper |
None:
982 """Create a wrapper for a AAS server connection from the given configuration.
984 :param configuration: Dictionary containing the AAS server connection settings
985 :param basic_auth_password: Password for the AAS server basic authentication, defaults to ""
986 :param o_auth_client_secret: Client secret for OAuth authentication, defaults to ""
987 :param bearer_auth_token: Bearer token for authentication, defaults to ""
988 :return: An instance of SdkWrapper initialized with the provided parameters or None if initialization fails
990 _logger.debug(
"Create AAS server wrapper from dictionary.")
991 return SdkWrapper(configuration, basic_auth_password, o_auth_client_secret, bearer_auth_token)
995 config_file: Path, basic_auth_password: str =
"", o_auth_client_secret: str =
"", bearer_auth_token: str =
""
996) -> SdkWrapper |
None:
997 """Create a wrapper for a AAS server connection from a given configuration file.
999 :param config_file: Path to the configuration file containing the AAS server connection settings
1000 :param basic_auth_password: Password for the AAS server basic authentication, defaults to ""
1001 :param o_auth_client_secret: Client secret for OAuth authentication, defaults to ""
1002 :param bearer_auth_token: Bearer token for authentication, defaults to ""
1003 :return: An instance of SdkWrapper initialized with the provided parameters or None if initialization fails
1005 _logger.debug(f
"Create AAS wrapper client from configuration file '{config_file}'.")
1006 if not config_file.exists():
1008 _logger.warning(f
"Configuration file '{config_file}' not found. Using default config.")
1010 config_string = config_file.read_text(encoding=
"utf-8")
1012 configuration = json.loads(config_string)
1013 except json.JSONDecodeError
as e:
1014 _logger.error(f
"Configuration file '{config_file}' is not a valid JSON file: {e}")
1016 _logger.debug(f
"Configuration file '{config_file}' found.")
1017 return SdkWrapper(configuration, 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.
bool experimental_put_file_by_path_submodel_repo_stream(self, str submodel_identifier, str id_short_path, Any file_octet_stream, str mime_type="application/octet-stream")
Uploads file content to an existing submodel element at a specified path within submodel elements hie...
bool experimental_post_file_by_path_submodel_repo_stream(self, str submodel_identifier, str id_short_path, Any file_octet_stream, str mime_type="application/octet-stream")
Uploads file content to an existing submodel element at a specified path within submodel elements hie...
__init__(self, dict configuration, str basic_auth_password="", str o_auth_client_secret="", str bearer_auth_token="")
Initializes the wrapper with the given configuration.
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.
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.
set_log_intensity(self, LogIntensity intensity)
Sets the log intensity level for the client.
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.