naeural-client 2.0.1__py3-none-any.whl → 2.0.2__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.
naeural_client/_ver.py CHANGED
@@ -1,4 +1,4 @@
1
- __VER__ = "2.0.1"
1
+ __VER__ = "2.0.2"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
@@ -1640,7 +1640,9 @@ class GenericSession(BaseDecentrAIObject):
1640
1640
  *,
1641
1641
  node,
1642
1642
  name,
1643
- signature,
1643
+ signature="CUSTOM_CODE_FASTAPI_01",
1644
+ endpoints=None,
1645
+ use_ngrok=True,
1644
1646
  **kwargs
1645
1647
  ):
1646
1648
 
@@ -1652,8 +1654,16 @@ class GenericSession(BaseDecentrAIObject):
1652
1654
  instance = pipeline.create_plugin_instance(
1653
1655
  signature=signature,
1654
1656
  instance_id=self.log.get_unique_id(),
1657
+ use_ngrok=use_ngrok,
1655
1658
  **kwargs
1656
1659
  )
1660
+
1661
+ if endpoints is not None:
1662
+ for endpoint in endpoints:
1663
+ assert isinstance(endpoint, dict), "Each endpoint must be a dictionary defining the endpoint configuration."
1664
+ instance.add_new_endpoint(**endpoint)
1665
+ # end for
1666
+ # end if we have endpoints defined in the call
1657
1667
 
1658
1668
  return pipeline, instance
1659
1669
 
@@ -1,3 +1,34 @@
1
+ """
2
+ CustomPluginTemplate
3
+ ====================
4
+
5
+ The `CustomPluginTemplate` class provides an interface to the on-edge `BasePluginExecutor`, facilitating the creation of custom plugins within the Neural Edge Protocol framework system.
6
+ It exposes all methods and properties defined on the target edge nodes, allowing developers to access any functionality needed for their custom plugins.
7
+ This interface supports code completion and documentation features, enhancing the development experience.
8
+
9
+ Note that code using this class will be executed in a dedicated thread on the edge node during the plugin execution cycle.
10
+
11
+ **Example Usage:**
12
+
13
+ ```python
14
+ def some_custom_code(plugin: CustomPluginTemplate):
15
+ plugin.P("Hello World") # Log a message on the edge node
16
+ obj = plugin.obj_cache.get('MyDict')
17
+ if obj is None:
18
+ obj = {
19
+ 'counter': 0,
20
+ 'some_data': 'some_value'
21
+ }
22
+ plugin.obj_cache['MyDict'] = obj
23
+
24
+ obj['counter'] += 1
25
+ plugin.P(f"Counter: {obj['counter']}") # Log the counter value
26
+ # Finally, send a payload from the edge node to the client
27
+ return obj
28
+ ```
29
+ """
30
+
31
+
1
32
  class CustomPluginTemplate:
2
33
  @property
3
34
  def BytesIO(self):
@@ -9,7 +9,10 @@ import ctypes
9
9
  import threading
10
10
  import queue
11
11
 
12
- from .checker import ASTChecker, CheckerConstants
12
+ try:
13
+ from .checker import ASTChecker, CheckerConstants
14
+ except:
15
+ from naeural_client.code_cheker.checker import ASTChecker, CheckerConstants
13
16
 
14
17
  __VER__ = '0.6.1'
15
18
 
@@ -496,7 +499,7 @@ class BaseCodeChecker:
496
499
 
497
500
  def get_function_source_code(self, func):
498
501
  """
499
- Get the source code of a function and remove the indentation.
502
+ Get the source code of a function including the docstring and remove the indentation.
500
503
 
501
504
  Parameters
502
505
  ----------
@@ -518,3 +521,27 @@ class BaseCodeChecker:
518
521
  plain_code = '\n'.join([line.rstrip()[indent:] for line in plain_code])
519
522
 
520
523
  return plain_code
524
+
525
+
526
+ if __name__ == '__main__':
527
+
528
+ def some_function(x):
529
+ """
530
+ A simple function that adds 1 to the input.
531
+
532
+ Parameters
533
+ ----------
534
+ x : _type_
535
+ _description_
536
+
537
+ Returns
538
+ -------
539
+ _type_
540
+ _description_
541
+ """
542
+ return x + 1
543
+
544
+ checker = BaseCodeChecker()
545
+ source_code = checker.get_function_source_code(some_function)
546
+ print("some_function:\n" + source_code)
547
+
@@ -20,7 +20,54 @@ class CustomWebApp01(Instance):
20
20
 
21
21
  return name, args, base64_code
22
22
 
23
- def add_new_endpoint(self, function, method="get"):
23
+
24
+ def get_proposed_assets(self):
25
+ from copy import deepcopy
26
+ proposed_config = self._get_proposed_config_dictionary(full=True)
27
+ if "ASSETS" in proposed_config:
28
+ return deepcopy(proposed_config["ASSETS"])
29
+ return deepcopy(self.config.get("ASSETS", {}))
30
+
31
+
32
+ def get_proposed_jinja_args(self):
33
+ from copy import deepcopy
34
+ proposed_config = self._get_proposed_config_dictionary(full=True)
35
+ if "JINJA_ARGS" in proposed_config:
36
+ return deepcopy(proposed_config["JINJA_ARGS"])
37
+ return deepcopy(self.config.get("JINJA_ARGS", {}))
38
+
39
+
40
+ def add_new_endpoint(self, endpoint_type="default", **kwargs):
41
+ """
42
+ Add a new endpoint to a existing web app instance.
43
+
44
+ Parameters
45
+ ----------
46
+ endpoint_type : str, optional
47
+ The type of the endpoint. Can be "default", "file" or "html". The default is "default".
48
+
49
+ Raises
50
+ ------
51
+ ValueError
52
+ If the endpoint_type is invalid.
53
+ """
54
+ self.P("Attempting to add a new `{}` endpoint: {}".format(endpoint_type, kwargs))
55
+ if endpoint_type == "default":
56
+ self.add_new_function_endpoint(**kwargs)
57
+ elif endpoint_type == "file":
58
+ self.add_new_file_endpoint(**kwargs)
59
+ elif endpoint_type == "html":
60
+ self.add_new_html_endpoint(**kwargs)
61
+ else:
62
+ raise ValueError("Invalid endpoint type.")
63
+ return
64
+
65
+
66
+ def add_new_file_endpoint(self, str_code, file_name, endpoint_name):
67
+ raise NotImplementedError("This method is not implemented yet.")
68
+
69
+
70
+ def add_new_function_endpoint(self, function, method="get"):
24
71
  name, args, base64_code = self.get_endpoint_fields(function)
25
72
  dct_endpoint = {
26
73
  "NAME": name
@@ -40,23 +87,8 @@ class CustomWebApp01(Instance):
40
87
  dct_endpoint["ARGS"] = args
41
88
 
42
89
  self.update_instance_config(config={"ENDPOINTS": proposed_endpoints})
90
+ return
43
91
 
44
- def get_proposed_assets(self):
45
- from copy import deepcopy
46
- proposed_config = self._get_proposed_config_dictionary(full=True)
47
- if "ASSETS" in proposed_config:
48
- return deepcopy(proposed_config["ASSETS"])
49
- return deepcopy(self.config.get("ASSETS", {}))
50
-
51
- def get_proposed_jinja_args(self):
52
- from copy import deepcopy
53
- proposed_config = self._get_proposed_config_dictionary(full=True)
54
- if "JINJA_ARGS" in proposed_config:
55
- return deepcopy(proposed_config["JINJA_ARGS"])
56
- return deepcopy(self.config.get("JINJA_ARGS", {}))
57
-
58
- def add_new_file_endpoint(self, str_code, file_name, endpoint_name):
59
- raise NotImplementedError("This method is not implemented yet.")
60
92
 
61
93
  def add_new_html_endpoint(self, html_path, web_app_file_name, endpoint_route):
62
94
  str_code = None
@@ -116,3 +148,4 @@ class CustomWebApp01(Instance):
116
148
  dict_name_route_method["route"] = endpoint_route
117
149
 
118
150
  self.update_instance_config(config={"ASSETS": proposed_assets, "JINJA_ARGS": proposed_jinja_args})
151
+ return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: naeural_client
3
- Version: 2.0.1
3
+ Version: 2.0.2
4
4
  Summary: `naeural_client` is the Python SDK required for client app development for the Naeural Edge Protocol framework
5
5
  Project-URL: Homepage, https://github.com/NaeuralEdgeProtocol/naeural_client
6
6
  Project-URL: Bug Tracker, https://github.com/NaeuralEdgeProtocol/naeural_client/issues
@@ -1,13 +1,13 @@
1
1
  naeural_client/__init__.py,sha256=ZNoadMrxrd1EZqxni0zpoqjFIBrS8Jg-vfZrr7xwe9I,498
2
- naeural_client/_ver.py,sha256=fIub_Shqx2sNADxzGW-jCCOKc15lrptdhn9y12jgzfM,330
2
+ naeural_client/_ver.py,sha256=l7yLqLlJKbOAi0-Y1OLeSMEafEsEAQAHaqoBwPAaV3U,330
3
3
  naeural_client/base_decentra_object.py,sha256=TBBnShUybWhjcbEIT8_27FGzxcQUVh23jm-HlaD9Qbw,4173
4
4
  naeural_client/plugins_manager_mixin.py,sha256=X1JdGLDz0gN1rPnTN_5mJXR8JmqoBFQISJXmPR9yvCo,11106
5
5
  naeural_client/base/__init__.py,sha256=hACh83_cIv7-PwYMM3bQm2IBmNqiHw-3PAfDfAEKz9A,259
6
6
  naeural_client/base/distributed_custom_code_presets.py,sha256=cvz5R88P6Z5V61Ce1vHVVh8bOkgXd6gve_vdESDNAsg,2544
7
- naeural_client/base/generic_session.py,sha256=Dop4vI8mjB30OUFuMZ3gEDwvzDOXGqCrWsENtS-PRnI,65979
7
+ naeural_client/base/generic_session.py,sha256=xlFonVvfgpuMqLHeRzIcVuqiZXxsJB4KvwAMY36yh64,66389
8
8
  naeural_client/base/instance.py,sha256=pZSYC_WQNa5YqU2cVN9vbDyCg8ums8EQCd5Cx95a_VQ,19942
9
9
  naeural_client/base/pipeline.py,sha256=21V9SN1v86iMm80jOikZIkooyBF9FMs_3_0Q9-Qp4sc,57288
10
- naeural_client/base/plugin_template.py,sha256=CzIMJIh36pDAtUIddlAPJ9OmHbmcFmph_F00rEKUp_0,136987
10
+ naeural_client/base/plugin_template.py,sha256=qGaXByd_JZFpjvH9GXNbT7KaitRxIJB6-1IhbKrZjq4,138123
11
11
  naeural_client/base/responses.py,sha256=ZKBZmRhYDv8M8mQ5C_ahGsQvtWH4b9ImRcuerQdZmNw,6937
12
12
  naeural_client/base/transaction.py,sha256=bfs6td5M0fINgPQNxhrl_AUjb1YiilLDQ-Cd_o3OR_E,5146
13
13
  naeural_client/base/payload/__init__.py,sha256=y8fBI8tG2ObNfaXFWjyWZXwu878FRYj_I8GIbHT4GKE,29
@@ -19,7 +19,7 @@ naeural_client/bc/ec.py,sha256=8ryEvc3__lVXSoYxd1WoTy9c8uC5Q_8R1uME7CeloIg,8578
19
19
  naeural_client/certs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  naeural_client/certs/r9092118.ala.eu-central-1.emqxsl.com.crt,sha256=y-6io0tseyx9-a4Pmde1z1gPULtJNSYUpG_YFkYaMKU,1337
21
21
  naeural_client/code_cheker/__init__.py,sha256=pwkdeZGVL16ZA4Qf2mRahEhoOvKhL7FyuQbMFLr1E5M,33
22
- naeural_client/code_cheker/base.py,sha256=cJzQD_Y-Z7lkiiQY65oJQAVABOmYez7TZB8xYSiuRl8,16669
22
+ naeural_client/code_cheker/base.py,sha256=WIHP8LICypTBt7HR0FeC1KtIQ-PASTPaeFmCKvT5vuU,17190
23
23
  naeural_client/code_cheker/checker.py,sha256=QWupeM7ToancVIq1tRUxRNUrI8B5l5eoY0kDU4-O5aE,7365
24
24
  naeural_client/comm/__init__.py,sha256=za3B2HUKNXzYtjElMgGM9xbxNsdQfFY4JB_YzdyFkVU,76
25
25
  naeural_client/comm/amqp_wrapper.py,sha256=hzj6ih07DnLQy2VSfA88giDIFHaCp9uSdGLTA-IFE4s,8535
@@ -36,7 +36,7 @@ naeural_client/const/payload.py,sha256=k24vH9iJIBBPnCXx7HAEuli2fNAETK7h8ZuVKyKLg
36
36
  naeural_client/default/__init__.py,sha256=ozU6CMMuWl0LhG8Ae3LrZ65a6tLrptfscVYGf83zjxM,46
37
37
  naeural_client/default/instance/__init__.py,sha256=k1YZhbhLh7-Q7avnvwuQ2Ij-BhGbTlgwiWsOj9cS9xU,205
38
38
  naeural_client/default/instance/chain_dist_custom_job_01_plugin.py,sha256=-YO26dH3774wkMbj0Z0GACpVeVYblkxV4KhidtPEqcI,1891
39
- naeural_client/default/instance/custom_web_app_01_plugin.py,sha256=gjckmyp0yoN24ouxelgc2Eb2p7YxrrAoSRQpshPZFDY,3991
39
+ naeural_client/default/instance/custom_web_app_01_plugin.py,sha256=9swEcfEzpL_P29WDkP9kTZ8oHNS0s9TXwd5BfIGiDZI,4805
40
40
  naeural_client/default/instance/net_mon_01_plugin.py,sha256=1k1Ul6pKyhSfAYbcfj38t404Z3KyMVvfhlMJdzIgV-c,1154
41
41
  naeural_client/default/instance/view_scene_01_plugin.py,sha256=bQtkQKrZRvzenlH3JYVvBXe2Tow5qdKYlmuvjpBLYn4,666
42
42
  naeural_client/default/session/mqtt_session.py,sha256=dpQcBhhVZDo458v0IqJMZb1CsTn-TxXhYjNlyJp9Rp8,2414
@@ -72,7 +72,7 @@ naeural_client/logging/tzlocal/windows_tz.py,sha256=Sv9okktjZJfRGGUOOppsvQuX_eXy
72
72
  naeural_client/utils/__init__.py,sha256=mAnke3-MeRzz3nhQvhuHqLnpaaCSmDxicd7Ck9uwpmI,77
73
73
  naeural_client/utils/comm_utils.py,sha256=4cS9llRr_pK_3rNgDcRMCQwYPO0kcNU7AdWy_LtMyCY,1072
74
74
  naeural_client/utils/dotenv.py,sha256=_AgSo35n7EnQv5yDyu7C7i0kHragLJoCGydHjvOkrYY,2008
75
- naeural_client-2.0.1.dist-info/METADATA,sha256=zmbnuRiXoI-A0Xhuy_Xqiyw9z9tjyJ3Qf5NY9B7oiHw,14339
76
- naeural_client-2.0.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
77
- naeural_client-2.0.1.dist-info/licenses/LICENSE,sha256=7P07j9ez3_ovbZ8L_ZJuPXVOgqTS19-ECkezwOtFqOI,11340
78
- naeural_client-2.0.1.dist-info/RECORD,,
75
+ naeural_client-2.0.2.dist-info/METADATA,sha256=y7AtPpCgmqhD-SMgBnndpNqkKOEV2LhM4Vxt6mM-5ts,14339
76
+ naeural_client-2.0.2.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
77
+ naeural_client-2.0.2.dist-info/licenses/LICENSE,sha256=7P07j9ez3_ovbZ8L_ZJuPXVOgqTS19-ECkezwOtFqOI,11340
78
+ naeural_client-2.0.2.dist-info/RECORD,,