aas-http-client 0.3.1__py3-none-any.whl → 0.3.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of aas-http-client might be problematic. Click here for more details.

aas_http_client/client.py CHANGED
@@ -4,6 +4,7 @@ import json
4
4
  import logging
5
5
  import time
6
6
  from pathlib import Path
7
+ from typing import Any
7
8
 
8
9
  import basyx.aas.adapter.json
9
10
  import basyx.aas.adapter.json.json_serialization as js
@@ -26,7 +27,7 @@ STATUS_CODE_404 = 404
26
27
  HEADERS = {"Content-Type": "application/json"}
27
28
 
28
29
 
29
- def log_response_errors(response: Response):
30
+ def log_response_errors(response: Response): # noqa: C901
30
31
  """Create error messages from the response and log them.
31
32
 
32
33
  :param response: response
@@ -561,6 +562,32 @@ class AasHttpClient(BaseModel):
561
562
 
562
563
  return True
563
564
 
565
+ def patch_submodel_element_by_path_value_only_submodel_repo(self, submodel_id: str, submodel_element_path: str, value: str) -> bool:
566
+ """Updates the value of an existing SubmodelElement.
567
+
568
+ :param submodel_id: Encoded ID of the Submodel to update submodel element for
569
+ :param submodel_element_path: Path of the Submodel element to update
570
+ :param value: Submodel element value to update as string
571
+ :return: True if the patch was successful, False otherwise
572
+ """
573
+ decoded_submodel_id: str = decode_base_64(submodel_id)
574
+
575
+ url = f"{self.base_url}/submodels/{decoded_submodel_id}/submodel-elements/{submodel_element_path}/$value"
576
+
577
+ try:
578
+ response = self._session.patch(url, headers=HEADERS, json=value, timeout=self.time_out)
579
+ logger.debug(f"Call REST API url '{response.url}'")
580
+
581
+ if response.status_code != STATUS_CODE_204:
582
+ log_response_errors(response)
583
+ return False
584
+
585
+ except requests.exceptions.RequestException as e:
586
+ logger.error(f"Error call REST API: {e}")
587
+ return False
588
+
589
+ return True
590
+
564
591
 
565
592
  # endregion
566
593
 
@@ -577,19 +604,19 @@ def create_client_by_url(
577
604
  connection_time_out: int = 60,
578
605
  ssl_verify: str = True, # noqa: FBT002
579
606
  ) -> AasHttpClient | None:
580
- """Create a AAS HTTP client from the given parameters.
607
+ """Create a HTTP client for a AAS server connection from the given parameters.
581
608
 
582
- :param base_url: base URL of the BaSyx server, e.g. "http://basyx_python_server:80/"_
583
- :param username: username for the BaSyx server interface client, defaults to ""_
584
- :param password: password for the BaSyx server interface client, defaults to ""_
609
+ :param base_url: Base URL of the AAS server, e.g. "http://basyx_python_server:80/"_
610
+ :param username: Username for the AAS server, defaults to ""_
611
+ :param password: Password for the AAS server, defaults to ""_
585
612
  :param http_proxy: http proxy URL, defaults to ""_
586
613
  :param https_proxy: https proxy URL, defaults to ""_
587
- :param time_out: timeout for the API calls, defaults to 200
588
- :param connection_time_out: timeout for the connection to the API, defaults to 60
589
- :param ssl_verify: whether to verify SSL certificates, defaults to True
590
- :return: An instance of AasHttpClient initialized with the provided parameters.
614
+ :param time_out: Timeout for the API calls, defaults to 200
615
+ :param connection_time_out: Timeout for the connection to the API, defaults to 60
616
+ :param ssl_verify: Whether to verify SSL certificates, defaults to True
617
+ :return: An instance of Http client initialized with the provided parameters.
591
618
  """
592
- logger.info(f"Create BaSyx server interface client from URL '{base_url}'")
619
+ logger.info(f"Create AAS server http client from URL '{base_url}'")
593
620
  config_dict: dict[str, str] = {}
594
621
  config_dict["base_url"] = base_url
595
622
  config_dict["username"] = username
@@ -598,19 +625,31 @@ def create_client_by_url(
598
625
  config_dict["time_out"] = time_out
599
626
  config_dict["connection_time_out"] = connection_time_out
600
627
  config_dict["ssl_verify"] = ssl_verify
601
- config_string = json.dumps(config_dict, indent=4)
628
+ return create_client_by_dict(config_dict, password)
629
+
630
+
631
+ def create_client_by_dict(configuration: dict, password: str = "") -> AasHttpClient | None:
632
+ """Create a HTTP client for a AAS server connection from the given configuration.
633
+
634
+ :param configuration: Dictionary containing the BaSyx server connection settings.
635
+ :param password: Password for the AAS server, defaults to ""_
636
+ :return: An instance of Http client initialized with the provided parameters.
637
+ """
638
+ logger.info(f"Create AAS server http client from configuration '{configuration}'")
639
+ config_string = json.dumps(configuration, indent=4)
640
+
602
641
  return _create_client(config_string, password)
603
642
 
604
643
 
605
644
  def create_client_by_config(config_file: Path, password: str = "") -> AasHttpClient | None:
606
- """Create a AAS HTTP client from the given parameters.
645
+ """Create a HTTP client for a AAS server connection from a given configuration file.
607
646
 
608
- :param config_file: Path to the configuration file containing the BaSyx server connection settings.
647
+ :param config_file: Path to the configuration file containing the AAS server connection settings.
609
648
  :param password: password for the BaSyx server interface client, defaults to ""_
610
- :return: An instance of HttpClient initialized with the provided parameters.
649
+ :return: An instance of Http client initialized with the provided parameters.
611
650
  """
612
651
  config_file = config_file.resolve()
613
- logger.info(f"Create AAS HTTP client from Configuration file '{config_file}'")
652
+ logger.info(f"Create AAS server http client from configuration file '{config_file}'")
614
653
  if not config_file.exists():
615
654
  config_string = "{}"
616
655
  logger.warning(f"Configuration file '{config_file}' not found. Using default configuration.")
@@ -623,8 +662,7 @@ def create_client_by_config(config_file: Path, password: str = "") -> AasHttpCli
623
662
 
624
663
  def _create_client(config_string: str, password) -> AasHttpClient | None:
625
664
  try:
626
- connection_settings = AasHttpClient.model_validate_json(config_string)
627
- client = AasHttpClient(**connection_settings.model_dump())
665
+ client = AasHttpClient.model_validate_json(config_string)
628
666
  except ValidationError as ve:
629
667
  raise ValidationError(f"Invalid BaSyx server connection file: {ve}") from ve
630
668
 
@@ -19,6 +19,20 @@ class SdkWrapper:
19
19
  _client: AasHttpClient = None
20
20
  base_url: str = ""
21
21
 
22
+ def __init__(self, config_string: str, password: str = ""):
23
+ """Initializes the wrapper with the given configuration.
24
+
25
+ :param config_string: Configuration string for the BaSyx server connection.
26
+ :param password: Password for the BaSyx server interface client, defaults to "".
27
+ """
28
+ client = _create_client(config_string, password)
29
+
30
+ if not client:
31
+ raise ValueError("Failed to create AAS HTTP client with the provided configuration.")
32
+
33
+ self._client = client
34
+ self.base_url = client.base_url
35
+
22
36
  # region shells
23
37
 
24
38
  def post_asset_administration_shell(self, aas: model.AssetAdministrationShell) -> model.AssetAdministrationShell | None:
@@ -261,11 +275,24 @@ class SdkWrapper:
261
275
  :return: Submodel element object or None if an error occurred
262
276
  """
263
277
  content: dict = self._client.get_submodel_element_by_path_submodel_repo(submodel_id, submodel_element_path)
278
+ print(content)
264
279
  return _to_object(content)
265
280
 
281
+ def patch_submodel_element_by_path_value_only_submodel_repo(self, submodel_id: str, submodel_element_path: str, value: str) -> bool:
282
+ """Updates the value of an existing SubmodelElement.
283
+
284
+ :param submodel_id: Encoded ID of the Submodel to update submodel element for
285
+ :param submodel_element_path: Path of the Submodel element to update
286
+ :param value: Submodel element value to update as string
287
+ :return: True if the patch was successful, False otherwise
288
+ """
289
+ return self._client.patch_submodel_element_by_path_value_only_submodel_repo(submodel_id, submodel_element_path, value)
290
+
266
291
 
267
292
  # endregion
268
293
 
294
+ # region utils
295
+
269
296
 
270
297
  def _to_object(content: dict) -> Any | None:
271
298
  try:
@@ -287,6 +314,8 @@ def _to_dict(object: Any) -> dict | None:
287
314
  return None
288
315
 
289
316
 
317
+ # endregion
318
+
290
319
  # region wrapper
291
320
 
292
321
 
@@ -300,7 +329,7 @@ def create_wrapper_by_url(
300
329
  connection_time_out: int = 60,
301
330
  ssl_verify: str = True, # noqa: FBT002
302
331
  ) -> SdkWrapper | None:
303
- """Create a wrapper for the BaSyx Python SDK from the given parameters.
332
+ """Create a wrapper for a AAS server connection from the given parameters.
304
333
 
305
334
  :param base_url: base URL of the BaSyx server, e.g. "http://basyx_python_server:80/"_
306
335
  :param username: username for the BaSyx server interface client, defaults to ""_
@@ -312,7 +341,7 @@ def create_wrapper_by_url(
312
341
  :param ssl_verify: whether to verify SSL certificates, defaults to True
313
342
  :return: An instance of SdkWrapper initialized with the provided parameters.
314
343
  """
315
- logger.info(f"Create BaSyx Python SDK wrapper from URL '{base_url}'")
344
+ logger.info(f"Create AAS server wrapper from URL '{base_url}'")
316
345
  config_dict: dict[str, str] = {}
317
346
  config_dict["base_url"] = base_url
318
347
  config_dict["username"] = username
@@ -321,43 +350,36 @@ def create_wrapper_by_url(
321
350
  config_dict["time_out"] = time_out
322
351
  config_dict["connection_time_out"] = connection_time_out
323
352
  config_dict["ssl_verify"] = ssl_verify
324
- config_string = json.dumps(config_dict, indent=4)
353
+ return create_wrapper_by_dict(config_dict, password)
325
354
 
326
- wrapper = SdkWrapper()
327
- client = _create_client(config_string, password)
328
355
 
329
- if not client:
330
- return None
356
+ def create_wrapper_by_dict(configuration: dict, password: str = "") -> SdkWrapper | None:
357
+ """Create a wrapper for a AAS server connection from the given configuration.
331
358
 
332
- wrapper._client = client
333
- wrapper.base_url = client.base_url
334
- return wrapper
359
+ :param config: Dictionary containing the BaSyx server connection settings.
360
+ :param password: Password for the BaSyx server interface client, defaults to "".
361
+ :return: An instance of SdkWrapper initialized with the provided parameters.
362
+ """
363
+ logger.info(f"Create AAS server wrapper from configuration '{configuration}'")
364
+ config_string = json.dumps(configuration, indent=4)
365
+ return SdkWrapper(config_string, password)
335
366
 
336
367
 
337
368
  def create_wrapper_by_config(config_file: Path, password: str = "") -> SdkWrapper | None:
338
- """Create a wrapper for the BaSyx Python SDK from the given parameters.
369
+ """Create a wrapper for a AAS server connection from a given configuration file.
339
370
 
340
371
  :param config_file: Path to the configuration file containing the BaSyx server connection settings.
341
372
  :param password: password for the BaSyx server interface client, defaults to ""_
342
373
  :return: An instance of SdkWrapper initialized with the provided parameters.
343
374
  """
344
- logger.info(f"Create BaSyx Python SDK wrapper from configuration file '{config_file}'")
375
+ logger.info(f"Create AAS wrapper client from configuration file '{config_file}'")
345
376
  if not config_file.exists():
346
377
  config_string = "{}"
347
378
  logger.warning(f"Configuration file '{config_file}' not found. Using default config.")
348
379
  else:
349
380
  config_string = config_file.read_text(encoding="utf-8")
350
381
  logger.debug(f"Configuration file '{config_file}' found.")
351
-
352
- wrapper = SdkWrapper()
353
- client = _create_client(config_string, password)
354
-
355
- if not client:
356
- return None
357
-
358
- wrapper._client = client
359
- wrapper.base_url = client.base_url
360
- return wrapper
382
+ return SdkWrapper(config_string, password)
361
383
 
362
384
 
363
385
  # endregion
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: Generic python HTTP client for communication with various types of AAS servers
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: # :em engineering methods AG Software License
@@ -1,14 +1,14 @@
1
1
  aas_http_client/__init__.py,sha256=cAr1mQzWp0G0LKtkAOYzc9t95OY3jM3Aj4bKnxx0Dso,901
2
- aas_http_client/client.py,sha256=neuEMk1lyOHOgVv3OBzNeXDWEtkN4qfox-hMRjtDWHM,25350
2
+ aas_http_client/client.py,sha256=LXqhMLkNO9Itu9Pj369vJurBCd0kiqvhrgnahEmkUtI,27041
3
3
  aas_http_client/core/encoder.py,sha256=FS7P0FPakzFsGz70eRFDHQZFA_2nlKLlWIxavtnFrPg,660
4
4
  aas_http_client/core/version_check.py,sha256=721Zs3xSRrJTYZtAxkaUWg9LLKtpU7oFM62DzQHZdE4,705
5
5
  aas_http_client/demo/demo_process.py,sha256=6sN_N3QbA4iLUmzeg1Y_XOwVAuDNtwkR4grAg7EkjWM,3301
6
6
  aas_http_client/demo/logging_handler.py,sha256=VJtZ4u3x_LhYZQtfNck7FuXhGFZm7gid0uDhvf9GjJ8,5596
7
7
  aas_http_client/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  aas_http_client/utilities/model_builder.py,sha256=EUqVvKgXiyJNtyUeFrL6ronfF4hiF1KCipxSaLj6EiE,4465
9
- aas_http_client/wrapper/sdk_wrapper.py,sha256=pphxkTwnaoG44hOqelwnqBWupGfDX2ExBDhAdZNFQuQ,13512
10
- aas_http_client-0.3.1.dist-info/licenses/LICENSE,sha256=ayt4HY-Tjoe1Uvj47j6UdNq8mEufKcKFangurChIHxQ,5990
11
- aas_http_client-0.3.1.dist-info/METADATA,sha256=LAC3u23U1X84glQ5zg77p3oPn-pl1mAOGHOgYaWsTdU,10467
12
- aas_http_client-0.3.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- aas_http_client-0.3.1.dist-info/top_level.txt,sha256=vzvoz2vjeTLwpuz-Y-eEfoQ7T3byoaKshVlFMFH5NaM,16
14
- aas_http_client-0.3.1.dist-info/RECORD,,
9
+ aas_http_client/wrapper/sdk_wrapper.py,sha256=KOPcnW0SrpoH6Z6ycDtzSmMdbk2MHj_UqbEbKGgGfWA,15010
10
+ aas_http_client-0.3.3.dist-info/licenses/LICENSE,sha256=ayt4HY-Tjoe1Uvj47j6UdNq8mEufKcKFangurChIHxQ,5990
11
+ aas_http_client-0.3.3.dist-info/METADATA,sha256=RtgD4C2wO1BBzPXRaU7xVRxZHuGuSQX6M7ca5B-tJHM,10467
12
+ aas_http_client-0.3.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ aas_http_client-0.3.3.dist-info/top_level.txt,sha256=vzvoz2vjeTLwpuz-Y-eEfoQ7T3byoaKshVlFMFH5NaM,16
14
+ aas_http_client-0.3.3.dist-info/RECORD,,