aas-http-client 0.3.0__tar.gz → 0.3.2__tar.gz

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.

Files changed (21) hide show
  1. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/PKG-INFO +1 -1
  2. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client/client.py +52 -15
  3. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client/wrapper/sdk_wrapper.py +33 -23
  4. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client.egg-info/PKG-INFO +1 -1
  5. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/pyproject.toml +1 -1
  6. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/tests/test_client.py +16 -1
  7. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/tests/test_wrapper.py +16 -1
  8. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/LICENSE +0 -0
  9. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/README.md +0 -0
  10. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client/__init__.py +0 -0
  11. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client/core/encoder.py +0 -0
  12. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client/core/version_check.py +0 -0
  13. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client/demo/demo_process.py +0 -0
  14. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client/demo/logging_handler.py +0 -0
  15. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client/utilities/__init__.py +0 -0
  16. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client/utilities/model_builder.py +0 -0
  17. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client.egg-info/SOURCES.txt +0 -0
  18. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client.egg-info/dependency_links.txt +0 -0
  19. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client.egg-info/requires.txt +0 -0
  20. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/aas_http_client.egg-info/top_level.txt +0 -0
  21. {aas_http_client-0.3.0 → aas_http_client-0.3.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.3.0
3
+ Version: 0.3.2
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
@@ -109,7 +109,7 @@ class AasHttpClient(BaseModel):
109
109
  url = f"{self.base_url}/shells"
110
110
 
111
111
  try:
112
- response = self._session.get(url, headers=HEADERS, timeout=2)
112
+ response = self._session.get(url, headers=HEADERS, timeout=10)
113
113
  logger.debug(f"Call REST API url '{response.url}'")
114
114
 
115
115
  if response.status_code != STATUS_CODE_200:
@@ -536,6 +536,31 @@ class AasHttpClient(BaseModel):
536
536
  content = response.content.decode("utf-8")
537
537
  return json.loads(content)
538
538
 
539
+ def delete_submodel_element_by_path_submodel_repo(self, submodel_id: str, submodel_element_path: str):
540
+ """Deletes a submodel element at a specified path within the submodel elements hierarchy.
541
+
542
+ :param submodel_id: Encoded ID of the Submodel to delete submodel element from
543
+ :param submodel_element_path: Path of the Submodel element to delete
544
+ :return: True if the deletion was successful, False otherwise
545
+ """
546
+ decoded_submodel_id: str = decode_base_64(submodel_id)
547
+
548
+ url = f"{self.base_url}/submodels/{decoded_submodel_id}/submodel-elements/{submodel_element_path}"
549
+
550
+ try:
551
+ response = self._session.delete(url, headers=HEADERS, timeout=self.time_out)
552
+ logger.debug(f"Call REST API url '{response.url}'")
553
+
554
+ if response.status_code != STATUS_CODE_204:
555
+ log_response_errors(response)
556
+ return False
557
+
558
+ except requests.exceptions.RequestException as e:
559
+ logger.error(f"Error call REST API: {e}")
560
+ return False
561
+
562
+ return True
563
+
539
564
 
540
565
  # endregion
541
566
 
@@ -552,19 +577,19 @@ def create_client_by_url(
552
577
  connection_time_out: int = 60,
553
578
  ssl_verify: str = True, # noqa: FBT002
554
579
  ) -> AasHttpClient | None:
555
- """Create a AAS HTTP client from the given parameters.
580
+ """Create a HTTP client for a AAS server connection from the given parameters.
556
581
 
557
- :param base_url: base URL of the BaSyx server, e.g. "http://basyx_python_server:80/"_
558
- :param username: username for the BaSyx server interface client, defaults to ""_
559
- :param password: password for the BaSyx server interface client, defaults to ""_
582
+ :param base_url: Base URL of the AAS server, e.g. "http://basyx_python_server:80/"_
583
+ :param username: Username for the AAS server, defaults to ""_
584
+ :param password: Password for the AAS server, defaults to ""_
560
585
  :param http_proxy: http proxy URL, defaults to ""_
561
586
  :param https_proxy: https proxy URL, defaults to ""_
562
- :param time_out: timeout for the API calls, defaults to 200
563
- :param connection_time_out: timeout for the connection to the API, defaults to 60
564
- :param ssl_verify: whether to verify SSL certificates, defaults to True
565
- :return: An instance of AasHttpClient initialized with the provided parameters.
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 Http client initialized with the provided parameters.
566
591
  """
567
- logger.info(f"Create BaSyx server interface client from URL '{base_url}'")
592
+ logger.info(f"Create AAS server http client from URL '{base_url}'")
568
593
  config_dict: dict[str, str] = {}
569
594
  config_dict["base_url"] = base_url
570
595
  config_dict["username"] = username
@@ -573,19 +598,31 @@ def create_client_by_url(
573
598
  config_dict["time_out"] = time_out
574
599
  config_dict["connection_time_out"] = connection_time_out
575
600
  config_dict["ssl_verify"] = ssl_verify
576
- config_string = json.dumps(config_dict, indent=4)
601
+ return create_client_by_dict(config_dict, password)
602
+
603
+
604
+ def create_client_by_dict(configuration: dict, password: str = "") -> AasHttpClient | None:
605
+ """Create a HTTP client for a AAS server connection from the given configuration.
606
+
607
+ :param configuration: Dictionary containing the BaSyx server connection settings.
608
+ :param password: Password for the AAS server, defaults to ""_
609
+ :return: An instance of Http client initialized with the provided parameters.
610
+ """
611
+ logger.info(f"Create AAS server http client from configuration '{configuration}'")
612
+ config_string = json.dumps(configuration, indent=4)
613
+
577
614
  return _create_client(config_string, password)
578
615
 
579
616
 
580
617
  def create_client_by_config(config_file: Path, password: str = "") -> AasHttpClient | None:
581
- """Create a AAS HTTP client from the given parameters.
618
+ """Create a HTTP client for a AAS server connection from a given configuration file.
582
619
 
583
- :param config_file: Path to the configuration file containing the BaSyx server connection settings.
620
+ :param config_file: Path to the configuration file containing the AAS server connection settings.
584
621
  :param password: password for the BaSyx server interface client, defaults to ""_
585
- :return: An instance of HttpClient initialized with the provided parameters.
622
+ :return: An instance of Http client initialized with the provided parameters.
586
623
  """
587
624
  config_file = config_file.resolve()
588
- logger.info(f"Create AAS HTTP client from Configuration file '{config_file}'")
625
+ logger.info(f"Create AAS server http client from configuration file '{config_file}'")
589
626
  if not config_file.exists():
590
627
  config_string = "{}"
591
628
  logger.warning(f"Configuration file '{config_file}' not found. Using default configuration.")
@@ -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:
@@ -266,11 +280,12 @@ class SdkWrapper:
266
280
 
267
281
  # endregion
268
282
 
283
+ # region utils
284
+
269
285
 
270
286
  def _to_object(content: dict) -> Any | None:
271
287
  try:
272
288
  dict_string = json.dumps(content)
273
- print(dict_string)
274
289
  return json.loads(dict_string, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
275
290
  except Exception as e:
276
291
  logger.error(f"Decoding error: {e}")
@@ -288,6 +303,8 @@ def _to_dict(object: Any) -> dict | None:
288
303
  return None
289
304
 
290
305
 
306
+ # endregion
307
+
291
308
  # region wrapper
292
309
 
293
310
 
@@ -301,7 +318,7 @@ def create_wrapper_by_url(
301
318
  connection_time_out: int = 60,
302
319
  ssl_verify: str = True, # noqa: FBT002
303
320
  ) -> SdkWrapper | None:
304
- """Create a wrapper for the BaSyx Python SDK from the given parameters.
321
+ """Create a wrapper for a AAS server connection from the given parameters.
305
322
 
306
323
  :param base_url: base URL of the BaSyx server, e.g. "http://basyx_python_server:80/"_
307
324
  :param username: username for the BaSyx server interface client, defaults to ""_
@@ -313,7 +330,7 @@ def create_wrapper_by_url(
313
330
  :param ssl_verify: whether to verify SSL certificates, defaults to True
314
331
  :return: An instance of SdkWrapper initialized with the provided parameters.
315
332
  """
316
- logger.info(f"Create BaSyx Python SDK wrapper from URL '{base_url}'")
333
+ logger.info(f"Create AAS server wrapper from URL '{base_url}'")
317
334
  config_dict: dict[str, str] = {}
318
335
  config_dict["base_url"] = base_url
319
336
  config_dict["username"] = username
@@ -322,43 +339,36 @@ def create_wrapper_by_url(
322
339
  config_dict["time_out"] = time_out
323
340
  config_dict["connection_time_out"] = connection_time_out
324
341
  config_dict["ssl_verify"] = ssl_verify
325
- config_string = json.dumps(config_dict, indent=4)
342
+ return create_wrapper_by_dict(config_dict, password)
326
343
 
327
- wrapper = SdkWrapper()
328
- client = _create_client(config_string, password)
329
344
 
330
- if not client:
331
- return None
345
+ def create_wrapper_by_dict(configuration: dict, password: str = "") -> SdkWrapper | None:
346
+ """Create a wrapper for a AAS server connection from the given configuration.
332
347
 
333
- wrapper._client = client
334
- wrapper.base_url = client.base_url
335
- return wrapper
348
+ :param config: Dictionary containing the BaSyx server connection settings.
349
+ :param password: Password for the BaSyx server interface client, defaults to "".
350
+ :return: An instance of SdkWrapper initialized with the provided parameters.
351
+ """
352
+ logger.info(f"Create AAS server wrapper from configuration '{configuration}'")
353
+ config_string = json.dumps(configuration, indent=4)
354
+ return SdkWrapper(config_string, password)
336
355
 
337
356
 
338
357
  def create_wrapper_by_config(config_file: Path, password: str = "") -> SdkWrapper | None:
339
- """Create a wrapper for the BaSyx Python SDK from the given parameters.
358
+ """Create a wrapper for a AAS server connection from a given configuration file.
340
359
 
341
360
  :param config_file: Path to the configuration file containing the BaSyx server connection settings.
342
361
  :param password: password for the BaSyx server interface client, defaults to ""_
343
362
  :return: An instance of SdkWrapper initialized with the provided parameters.
344
363
  """
345
- logger.info(f"Create BaSyx Python SDK wrapper from configuration file '{config_file}'")
364
+ logger.info(f"Create AAS wrapper client from configuration file '{config_file}'")
346
365
  if not config_file.exists():
347
366
  config_string = "{}"
348
367
  logger.warning(f"Configuration file '{config_file}' not found. Using default config.")
349
368
  else:
350
369
  config_string = config_file.read_text(encoding="utf-8")
351
370
  logger.debug(f"Configuration file '{config_file}' found.")
352
-
353
- wrapper = SdkWrapper()
354
- client = _create_client(config_string, password)
355
-
356
- if not client:
357
- return None
358
-
359
- wrapper._client = client
360
- wrapper.base_url = client.base_url
361
- return wrapper
371
+ return SdkWrapper(config_string, password)
362
372
 
363
373
 
364
374
  # endregion
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.3.0
3
+ Version: 0.3.2
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "aas-http-client"
7
- version = "0.3.0"
7
+ version = "0.3.2"
8
8
  description = "Generic python HTTP client for communication with various types of AAS servers"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -1,6 +1,6 @@
1
1
  import pytest
2
2
  from pathlib import Path
3
- from aas_http_client.client import create_client_by_config, AasHttpClient
3
+ from aas_http_client.client import create_client_by_config, AasHttpClient, create_client_by_dict, create_client_by_url
4
4
  from basyx.aas import model
5
5
  import aas_http_client.utilities.model_builder as model_builder
6
6
  import json
@@ -54,6 +54,21 @@ def shared_aas(shared_sm: model.Submodel) -> model.AssetAdministrationShell:
54
54
 
55
55
  return aas
56
56
 
57
+ def test_000a_create_client_by_url(client: AasHttpClient):
58
+ base_url: str = client.base_url
59
+ new_client: AasHttpClient = create_client_by_url(base_url=base_url)
60
+ assert new_client is not None
61
+
62
+ def test_000b_create_client_by_dict(client: AasHttpClient):
63
+ base_url: str = client.base_url
64
+
65
+ config_dict: dict = {
66
+ "base_url": base_url
67
+ }
68
+
69
+ new_client: AasHttpClient = create_client_by_dict(configuration=config_dict)
70
+ assert new_client is not None
71
+
57
72
  def test_001a_connect(client: AasHttpClient):
58
73
  assert client is not None
59
74
 
@@ -1,6 +1,6 @@
1
1
  import pytest
2
2
  from pathlib import Path
3
- from aas_http_client.wrapper.sdk_wrapper import create_wrapper_by_config, SdkWrapper
3
+ from aas_http_client.wrapper.sdk_wrapper import create_wrapper_by_config, SdkWrapper, create_wrapper_by_dict, create_wrapper_by_url
4
4
  from basyx.aas import model
5
5
  import aas_http_client.utilities.model_builder as model_builder
6
6
  from urllib.parse import urlparse
@@ -55,6 +55,21 @@ def shared_aas(shared_sm: model.Submodel) -> model.AssetAdministrationShell:
55
55
 
56
56
  return aas
57
57
 
58
+ def test_000a_create_wrapper_by_url(wrapper: SdkWrapper):
59
+ base_url: str = wrapper.base_url
60
+ new_client: SdkWrapper = create_wrapper_by_url(base_url=base_url)
61
+ assert new_client is not None
62
+
63
+ def test_000b_create_wrapper_by_dict(wrapper: SdkWrapper):
64
+ base_url: str = wrapper.base_url
65
+
66
+ config_dict: dict = {
67
+ "base_url": base_url
68
+ }
69
+
70
+ new_client: SdkWrapper = create_wrapper_by_dict(configuration=config_dict)
71
+ assert new_client is not None
72
+
58
73
  def test_001_connect(wrapper: SdkWrapper):
59
74
  assert wrapper is not None
60
75
 
File without changes