naeural-client 2.0.3__tar.gz → 2.1.0__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.
Files changed (122) hide show
  1. {naeural_client-2.0.3 → naeural_client-2.1.0}/PKG-INFO +1 -2
  2. {naeural_client-2.0.3 → naeural_client-2.1.0}/__init__.py +3 -0
  3. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/__init__.py +2 -0
  4. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/_ver.py +1 -1
  5. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/base/generic_session.py +73 -3
  6. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/const/__init__.py +1 -0
  7. naeural_client-2.1.0/naeural_client/const/apps.py +11 -0
  8. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/const/environment.py +2 -0
  9. naeural_client-2.1.0/naeural_client/default/instance/__init__.py +16 -0
  10. naeural_client-2.1.0/naeural_client/default/instance/basic_telegram_bot_01_plugin.py +5 -0
  11. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/default/instance/chain_dist_custom_job_01_plugin.py +2 -1
  12. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/default/instance/custom_web_app_01_plugin.py +2 -2
  13. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/default/instance/net_mon_01_plugin.py +2 -2
  14. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/default/instance/view_scene_01_plugin.py +2 -2
  15. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/base_logger.py +5 -4
  16. {naeural_client-2.0.3 → naeural_client-2.1.0}/pyproject.toml +1 -1
  17. naeural_client-2.1.0/tutorials/ex01_part1_connect.py +61 -0
  18. naeural_client-2.0.3/tutorials/ex1_connect_to_network.py → naeural_client-2.1.0/tutorials/ex01_part2_filter.py +12 -6
  19. naeural_client-2.0.3/tutorials/ex7_custom_code_on_multiple_remotes__example_2.py → naeural_client-2.1.0/tutorials/ex07_custom_code_on_multiple_remotes__example_2.py +0 -1
  20. naeural_client-2.0.3/tutorials/ex8_custom_web_app.py → naeural_client-2.1.0/tutorials/ex08_custom_web_app.py +2 -3
  21. naeural_client-2.0.3/tutorials/ex9_code_sandbox_from_scratch.py → naeural_client-2.1.0/tutorials/ex09_code_sandbox_from_scratch.py +3 -4
  22. naeural_client-2.1.0/tutorials/ex10_telegram_echo_bot.py +48 -0
  23. naeural_client-2.0.3/naeural_client/default/instance/__init__.py +0 -4
  24. {naeural_client-2.0.3 → naeural_client-2.1.0}/.devcontainer/Dockerfile +0 -0
  25. {naeural_client-2.0.3 → naeural_client-2.1.0}/.devcontainer/devcontainer.json +0 -0
  26. {naeural_client-2.0.3 → naeural_client-2.1.0}/.gitattributes +0 -0
  27. {naeural_client-2.0.3 → naeural_client-2.1.0}/.github/workflows/python-publish.yml +0 -0
  28. {naeural_client-2.0.3 → naeural_client-2.1.0}/.gitignore +0 -0
  29. {naeural_client-2.0.3 → naeural_client-2.1.0}/.vscode/launch.json +0 -0
  30. {naeural_client-2.0.3 → naeural_client-2.1.0}/LICENSE +0 -0
  31. {naeural_client-2.0.3 → naeural_client-2.1.0}/README.md +0 -0
  32. {naeural_client-2.0.3 → naeural_client-2.1.0}/TODOs.md +0 -0
  33. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/base/__init__.py +0 -0
  34. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/base/distributed_custom_code_presets.py +0 -0
  35. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/base/instance.py +0 -0
  36. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/base/payload/__init__.py +0 -0
  37. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/base/payload/payload.py +0 -0
  38. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/base/pipeline.py +0 -0
  39. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/base/plugin_template.py +0 -0
  40. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/base/responses.py +0 -0
  41. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/base/transaction.py +0 -0
  42. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/base_decentra_object.py +0 -0
  43. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/bc/__init__.py +0 -0
  44. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/bc/base.py +0 -0
  45. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/bc/chain.py +0 -0
  46. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/bc/ec.py +0 -0
  47. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/certs/__init__.py +0 -0
  48. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/certs/r9092118.ala.eu-central-1.emqxsl.com.crt +0 -0
  49. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/code_cheker/__init__.py +0 -0
  50. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/code_cheker/base.py +0 -0
  51. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/code_cheker/checker.py +0 -0
  52. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/comm/__init__.py +0 -0
  53. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/comm/amqp_wrapper.py +0 -0
  54. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/comm/mqtt_wrapper.py +0 -0
  55. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/const/README.md +0 -0
  56. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/const/base.py +0 -0
  57. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/const/comms.py +0 -0
  58. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/const/formatter.py +0 -0
  59. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/const/heartbeat.py +0 -0
  60. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/const/misc.py +0 -0
  61. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/const/payload.py +0 -0
  62. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/default/__init__.py +0 -0
  63. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/default/session/mqtt_session.py +0 -0
  64. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/io_formatter/__init__.py +0 -0
  65. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/io_formatter/base/__init__.py +0 -0
  66. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/io_formatter/base/base_formatter.py +0 -0
  67. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/io_formatter/default/__init__.py +0 -0
  68. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/io_formatter/default/a_dummy.py +0 -0
  69. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/io_formatter/default/aixp1.py +0 -0
  70. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/io_formatter/default/default.py +0 -0
  71. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/io_formatter/io_formatter_manager.py +0 -0
  72. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/__init__.py +0 -0
  73. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/__init__.py +0 -0
  74. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/class_instance_mixin.py +0 -0
  75. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/computer_vision_mixin.py +0 -0
  76. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/datetime_mixin.py +0 -0
  77. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/download_mixin.py +0 -0
  78. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/general_serialization_mixin.py +0 -0
  79. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/json_serialization_mixin.py +0 -0
  80. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/pickle_serialization_mixin.py +0 -0
  81. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/process_mixin.py +0 -0
  82. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/resource_size_mixin.py +0 -0
  83. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/timers_mixin.py +0 -0
  84. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/upload_mixin.py +0 -0
  85. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/logger_mixins/utils_mixin.py +0 -0
  86. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/small_logger.py +0 -0
  87. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/tzlocal/__init__.py +0 -0
  88. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/tzlocal/unix.py +0 -0
  89. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/tzlocal/utils.py +0 -0
  90. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/tzlocal/win32.py +0 -0
  91. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/logging/tzlocal/windows_tz.py +0 -0
  92. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/plugins_manager_mixin.py +0 -0
  93. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/utils/__init__.py +0 -0
  94. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/utils/comm_utils.py +0 -0
  95. {naeural_client-2.0.3 → naeural_client-2.1.0}/naeural_client/utils/dotenv.py +0 -0
  96. {naeural_client-2.0.3 → naeural_client-2.1.0}/requirements.txt +0 -0
  97. {naeural_client-2.0.3 → naeural_client-2.1.0}/tutorials/.example_env +0 -0
  98. {naeural_client-2.0.3 → naeural_client-2.1.0}/tutorials/8. custom_code_fastapi_assets/index.html +0 -0
  99. {naeural_client-2.0.3 → naeural_client-2.1.0}/tutorials/9. code_sandbox_from_scratch_assets/index.html +0 -0
  100. {naeural_client-2.0.3 → naeural_client-2.1.0}/tutorials/_example_pk_sdk.pem +0 -0
  101. /naeural_client-2.0.3/tutorials/ex2_first_deploy.py → /naeural_client-2.1.0/tutorials/ex02_first_deploy.py +0 -0
  102. /naeural_client-2.0.3/tutorials/ex3_custom_code_on_one_remote__example_1.py → /naeural_client-2.1.0/tutorials/ex03_custom_code_on_one_remote__example_1.py +0 -0
  103. /naeural_client-2.0.3/tutorials/ex4_custom_code_on_one_remote__example_2.py → /naeural_client-2.1.0/tutorials/ex04_custom_code_on_one_remote__example_2.py +0 -0
  104. /naeural_client-2.0.3/tutorials/ex5_custom_code_on_one_remote__example_3.py → /naeural_client-2.1.0/tutorials/ex05_custom_code_on_one_remote__example_3.py +0 -0
  105. /naeural_client-2.0.3/tutorials/ex6_custom_code_on_multiple_remotes__example_1.py → /naeural_client-2.1.0/tutorials/ex06_custom_code_on_multiple_remotes__example_1.py +0 -0
  106. {naeural_client-2.0.3 → naeural_client-2.1.0}/tutorials/video_presentation/1. hello_world.ipynb +0 -0
  107. {naeural_client-2.0.3 → naeural_client-2.1.0}/winrun.bat +0 -0
  108. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/.example_env +0 -0
  109. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/README.md +0 -0
  110. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/_archive/test.py +0 -0
  111. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/_tutorials/3. simple_real_time_custom_code.py +0 -0
  112. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/_tutorials/4. real_time_custom_code_2.py +0 -0
  113. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/_tutorials/8. chatbot.py +0 -0
  114. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/attach_example.py +0 -0
  115. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/decentralized/chain_dist_example.py +0 -0
  116. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/decentralized/chain_dist_example_initiator.py +0 -0
  117. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/decentralized/chain_dist_example_worker.py +0 -0
  118. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/ex1.py +0 -0
  119. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/hello.py +0 -0
  120. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/remote_exec.py +0 -0
  121. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/save_images.py +0 -0
  122. {naeural_client-2.0.3 → naeural_client-2.1.0}/xperimental/utils/get_documentation.py +0 -0
@@ -1,11 +1,10 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: naeural_client
3
- Version: 2.0.3
3
+ Version: 2.1.0
4
4
  Summary: `naeural_client` is the Python SDK required for client app development for the Naeural Edge Protocol Edge Protocol framework
5
5
  Project-URL: Homepage, https://github.com/Naeural Edge ProtocolEdgeProtocol/naeural_client
6
6
  Project-URL: Bug Tracker, https://github.com/Naeural Edge ProtocolEdgeProtocol/naeural_client/issues
7
7
  Author-email: Stefan Saraev <saraevstefan@gmail.com>, Andrei Ionut Damian <andrei.damian@me.com>, Cristan Bleotiu <cristibleotiu@gmail.com>
8
- License-File: LICENSE
9
8
  Classifier: License :: OSI Approved :: MIT License
10
9
  Classifier: Operating System :: OS Independent
11
10
  Classifier: Programming Language :: Python :: 3
@@ -9,3 +9,6 @@ from .naeural_client import load_dotenv
9
9
  from .naeural_client import __version__
10
10
  from .naeural_client import BaseDecentrAIObject, _PluginsManagerMixin, Logger
11
11
  from .naeural_client import BaseCodeChecker
12
+ from .naeural_client import PLUGIN_SIGNATURES
13
+ from .naeural_client import PLUGIN_TYPES
14
+
@@ -11,3 +11,5 @@ from .base_decentra_object import BaseDecentrAIObject
11
11
  from .plugins_manager_mixin import _PluginsManagerMixin
12
12
  from .logging import Logger
13
13
  from .code_cheker import BaseCodeChecker
14
+ from .const import PLUGIN_SIGNATURES
15
+ from .default.instance import PLUGIN_TYPES
@@ -1,4 +1,4 @@
1
- __VER__ = "2.0.3"
1
+ __VER__ = "2.1.0"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
@@ -9,7 +9,7 @@ from time import time as tm
9
9
 
10
10
  from ..base_decentra_object import BaseDecentrAIObject
11
11
  from ..bc import DefaultBlockEngine
12
- from ..const import COMMANDS, ENVIRONMENT, HB, PAYLOAD_DATA, STATUS_TYPE
12
+ from ..const import COMMANDS, ENVIRONMENT, HB, PAYLOAD_DATA, STATUS_TYPE, PLUGIN_SIGNATURES
13
13
  from ..const import comms as comm_ct
14
14
  from ..io_formatter import IOFormatterWrapper
15
15
  from ..logging import Logger
@@ -1396,7 +1396,7 @@ class GenericSession(BaseDecentrAIObject):
1396
1396
  def create_or_attach_to_pipeline(self, *,
1397
1397
  node,
1398
1398
  name,
1399
- data_source,
1399
+ data_source="Void",
1400
1400
  config={},
1401
1401
  plugins=[],
1402
1402
  on_data=None,
@@ -1410,15 +1410,21 @@ class GenericSession(BaseDecentrAIObject):
1410
1410
  ----------
1411
1411
  node : str
1412
1412
  Address or Name of the Naeural Edge Protocol edge node that will handle this pipeline.
1413
+
1413
1414
  name : str
1414
1415
  Name of the pipeline. This is good to be kept unique, as it allows multiple parties to overwrite each others configurations.
1416
+
1415
1417
  data_source : str
1416
1418
  This is the name of the DCT plugin, which resembles the desired functionality of the acquisition.
1419
+ Defaults to "Void" - no actual data acquisition.
1420
+
1417
1421
  config : dict, optional
1418
1422
  This is the dictionary that contains the configuration of the acquisition source, by default {}
1423
+
1419
1424
  plugins : list
1420
1425
  List of dictionaries which contain the configurations of each plugin instance that is desired to run on the box.
1421
1426
  Defaults to []. Should be left [], and instances should be created with the api.
1427
+
1422
1428
  on_data : Callable[[Pipeline, str, str, dict], None], optional
1423
1429
  Callback that handles messages received from any plugin instance.
1424
1430
  As arguments, it has a reference to this Pipeline object, the signature and the instance of the plugin
@@ -1426,15 +1432,18 @@ class GenericSession(BaseDecentrAIObject):
1426
1432
  This callback acts as a default payload processor and will be called even if for a given instance
1427
1433
  the user has defined a specific callback.
1428
1434
  Defaults to None.
1435
+
1429
1436
  on_notification : Callable[[Pipeline, dict], None], optional
1430
1437
  Callback that handles notifications received from any plugin instance.
1431
1438
  As arguments, it has a reference to this Pipeline object, along with the payload itself.
1432
1439
  This callback acts as a default payload processor and will be called even if for a given instance
1433
1440
  the user has defined a specific callback.
1434
1441
  Defaults to None.
1442
+
1435
1443
  max_wait_time : int, optional
1436
1444
  The maximum time to busy-wait, allowing the Session object to listen to node heartbeats
1437
1445
  and to check if the desired node is online in the network, by default 0.
1446
+
1438
1447
  **kwargs :
1439
1448
  The user can provide the configuration of the acquisition source directly as kwargs.
1440
1449
 
@@ -1651,15 +1660,39 @@ class GenericSession(BaseDecentrAIObject):
1651
1660
  *,
1652
1661
  node,
1653
1662
  name,
1654
- signature="CUSTOM_CODE_FASTAPI_01",
1663
+ signature=PLUGIN_SIGNATURES.CUSTOM_WEB_APP_01,
1655
1664
  endpoints=None,
1656
1665
  use_ngrok=True,
1657
1666
  **kwargs
1658
1667
  ):
1668
+ """
1669
+ Create a new web app on a node.
1670
+
1671
+ Parameters
1672
+ ----------
1673
+
1674
+ node : str
1675
+ Address or Name of the Naeural Edge Protocol edge node that will handle this web app.
1676
+
1677
+ name : str
1678
+ Name of the web app.
1679
+
1680
+ signature : str, optional
1681
+ The signature of the plugin that will be used. Defaults to PLUGIN_SIGNATURES.CUSTOM_WEB_APP_01.
1682
+
1683
+ endpoints : list[dict], optional
1684
+ A list of dictionaries defining the endpoint configuration. Defaults to None.
1685
+
1686
+ use_ngrok : bool, optional
1687
+ If True, will use ngrok to expose the web app. Defaults to True.
1688
+
1689
+
1690
+ """
1659
1691
 
1660
1692
  pipeline: Pipeline = self.create_pipeline(
1661
1693
  node=node,
1662
1694
  name=name,
1695
+ # default TYPE is "Void"
1663
1696
  )
1664
1697
 
1665
1698
  instance = pipeline.create_plugin_instance(
@@ -1677,6 +1710,43 @@ class GenericSession(BaseDecentrAIObject):
1677
1710
  # end if we have endpoints defined in the call
1678
1711
 
1679
1712
  return pipeline, instance
1713
+
1714
+
1715
+ def create_telegram_simple_bot(
1716
+ self,
1717
+ *,
1718
+ node,
1719
+ name,
1720
+ signature=PLUGIN_SIGNATURES.CUSTOM_WEB_APP_01,
1721
+ message_handler=None,
1722
+ telegram_bot_token=None,
1723
+ telegram_bot_token_env_key=ENVIRONMENT.TELEGRAM_BOT_TOKEN_ENV_KEY,
1724
+ **kwargs
1725
+ ):
1726
+
1727
+ if telegram_bot_token is None:
1728
+ telegram_bot_token = os.getenv(telegram_bot_token_env_key)
1729
+ if telegram_bot_token is None:
1730
+ message = f"Warning! No Telegram bot token provided as via env {ENVIRONMENT.TELEGRAM_BOT_TOKEN_ENV_KEY} or explicitly as `telegram_bot_token` param."
1731
+ raise ValueError(message)
1732
+
1733
+ b64code = self._get_base64_code(message_handler)
1734
+
1735
+ pipeline: Pipeline = self.create_pipeline(
1736
+ node=node,
1737
+ name=name,
1738
+ # default TYPE is "Void"
1739
+ )
1740
+
1741
+ instance = pipeline.create_plugin_instance(
1742
+ signature=signature,
1743
+ instance_id=self.log.get_unique_id(),
1744
+ telegram_bot_token=telegram_bot_token,
1745
+ message_handler=b64code,
1746
+ **kwargs
1747
+ )
1748
+ return pipeline, instance
1749
+
1680
1750
 
1681
1751
  def broadcast_instance_command_and_wait_for_response_payload(
1682
1752
  self,
@@ -7,3 +7,4 @@ from .payload import STATUS_TYPE, PAYLOAD_DATA, COMMANDS, NOTIFICATION_CODES
7
7
  from .base import CONFIG_STREAM, BIZ_PLUGIN_DATA, PLUGIN_INFO
8
8
  from . import heartbeat as HB
9
9
  from .environment import ENVIRONMENT
10
+ from .apps import PLUGIN_SIGNATURES
@@ -0,0 +1,11 @@
1
+ class PLUGIN_SIGNATURES:
2
+ """
3
+ This class is used to store the plugin signatures for the different plugins.
4
+ It is complementary to the PLUGIN_TYPES class.
5
+ """
6
+ NET_MON_01 = 'NET_MON_01'
7
+ VIEW_SCENE_01 = 'VIEW_SCENE_01'
8
+ CUSTOM_WEB_APP_01 = 'CUSTOM_CODE_FASTAPI_01'
9
+ CHAIN_DIST_CUSTOM_JOB_01 = 'PROCESS_REAL_TIME_COLLECTED_DATA_CUSTOM_EXEC_CHAIN_DIST'
10
+ BASIC_TELEGRAM_BOT_01 = 'BASIC_TELEGRAM_BOT_01'
11
+ # INSERT_NEW_PLUGIN_HERE
@@ -28,3 +28,5 @@ class ENVIRONMENT:
28
28
 
29
29
  EE_SECURED = 'EE_SECURED'
30
30
  AIXP_SECURED = 'AIXP_SECURED'
31
+
32
+ TELEGRAM_BOT_TOKEN_ENV_KEY = 'TELEGRAM_BOT_TOKEN'
@@ -0,0 +1,16 @@
1
+ from .net_mon_01_plugin import NetMon01
2
+ from .view_scene_01_plugin import ViewScene01
3
+ from .custom_web_app_01_plugin import CustomWebApp01
4
+ from .chain_dist_custom_job_01_plugin import ChainDistCustomJob01
5
+ from .basic_telegram_bot_01_plugin import BasicTelegramBot01
6
+
7
+
8
+ class PLUGIN_TYPES:
9
+ """
10
+ The plugin types that are available in the default instance
11
+ """
12
+ NET_MON_01 = NetMon01
13
+ VIEW_SCENE_01 = ViewScene01
14
+ CUSTOM_WEB_APP_01 = CustomWebApp01
15
+ CHAIN_DIST_CUSTOM_JOB_01 = ChainDistCustomJob01
16
+ BASIC_TELEGRAM_BOT_01 = BasicTelegramBot01
@@ -0,0 +1,5 @@
1
+ from ...base import Instance
2
+ from ...const import PLUGIN_SIGNATURES
3
+
4
+ class BasicTelegramBot01(Instance):
5
+ signature = PLUGIN_SIGNATURES.BASIC_TELEGRAM_BOT_01
@@ -1,8 +1,9 @@
1
1
  from ...base import Instance
2
+ from ...const import PLUGIN_SIGNATURES
2
3
 
3
4
 
4
5
  class ChainDistCustomJob01(Instance):
5
- signature = "PROCESS_REAL_TIME_COLLECTED_DATA_CUSTOM_EXEC_CHAIN_DIST"
6
+ signature = PLUGIN_SIGNATURES.CHAIN_DIST_CUSTOM_JOB_01
6
7
 
7
8
  def add_custom_code_callbacks(
8
9
  self,
@@ -1,8 +1,8 @@
1
1
  from ...base import Instance, Pipeline
2
-
2
+ from ...const import PLUGIN_SIGNATURES
3
3
 
4
4
  class CustomWebApp01(Instance):
5
- signature = "CUSTOM_CODE_FASTAPI_01"
5
+ signature = PLUGIN_SIGNATURES.CUSTOM_WEB_APP_01
6
6
 
7
7
  def get_proposed_endpoints(self):
8
8
  from copy import deepcopy
@@ -1,8 +1,8 @@
1
1
  from ...base import Instance
2
-
2
+ from ...const import PLUGIN_SIGNATURES
3
3
 
4
4
  class NetMon01(Instance):
5
- signature = "NET_MON_01"
5
+ signature = PLUGIN_SIGNATURES.NET_MON_01
6
6
 
7
7
  def get_node_history(self, node_id=None, node_addr=None, time_window_hours=1, steps=20):
8
8
  """
@@ -1,8 +1,8 @@
1
1
  from ...base import Instance
2
-
2
+ from ...const import PLUGIN_SIGNATURES
3
3
 
4
4
  class ViewScene01(Instance):
5
- signature = "VIEW_SCENE_01"
5
+ signature = PLUGIN_SIGNATURES.VIEW_SCENE_01
6
6
 
7
7
  def get_last_witness(self, response_params_key="COMMAND_PARAMS"):
8
8
  """
@@ -180,11 +180,12 @@ class BaseLogger(object):
180
180
  if lib_ver == "":
181
181
  lib_ver = __VER__
182
182
  ver = "v{}".format(lib_ver) if lib_ver != "" else ""
183
- self.verbose_log(
184
- "SDK [{} {}] initialized on machine [{}][{}].".format(
185
- self.__lib__, ver, self.MACHINE_NAME, self.get_processor_platform(),
183
+ self.P(
184
+ "NSDK {} initialized on [{}][{}].".format(
185
+ ver, self.MACHINE_NAME, self.get_processor_platform(),
186
186
  ),
187
- color='green'
187
+ color='green',
188
+ boxed=True,
188
189
  )
189
190
  self.verbose_log(" Timezone: {}.".format(self.timezone),color='green')
190
191
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "naeural_client"
7
- version = "2.0.3"
7
+ version = "2.1.0"
8
8
  authors = [
9
9
  { name="Stefan Saraev", email="saraevstefan@gmail.com" },
10
10
  { name="Andrei Ionut Damian", email="andrei.damian@me.com" },
@@ -0,0 +1,61 @@
1
+ """
2
+ This is a simple example of how to use the naeural_client SDK.
3
+
4
+ In this example, we connect to the network, listen for heartbeats from
5
+ Naeural Edge Protocol edge nodes and print the CPU of each node.
6
+ """
7
+ import json
8
+
9
+ from naeural_client import Session, Payload
10
+
11
+
12
+ class MessageHandler:
13
+ def shorten_address(self, address):
14
+ """
15
+ This method is used to shorten the address of the edge node.
16
+ """
17
+ return address[:8] + "..." + address[-6:]
18
+
19
+ def on_heartbeat(self, session: Session, node_addr: str, heartbeat: dict):
20
+ """
21
+ This method is called when a heartbeat is received from an edge node.
22
+
23
+ Parameters
24
+ ----------
25
+ session : Session
26
+ The session object that received the heartbeat.
27
+
28
+ node_addr : str
29
+ The address of the edge node that sent the heartbeat.
30
+
31
+ heartbeat : dict
32
+ The heartbeat received from the edge node.
33
+ """
34
+ session.P("{} ({}) has a {}".format(
35
+ heartbeat['EE_ID'],
36
+ self.shorten_address(node_addr),
37
+ heartbeat["CPU"])
38
+ )
39
+ return
40
+
41
+
42
+
43
+ if __name__ == '__main__':
44
+ # create a naive message handler
45
+ filterer = MessageHandler()
46
+
47
+ # create a session
48
+ # the network credentials are read from the .env file automatically
49
+ session = Session(
50
+ on_heartbeat=filterer.on_heartbeat,
51
+ )
52
+
53
+
54
+ # Observation:
55
+ # next code is not mandatory - it is used to keep the session open and cleanup the resources
56
+ # in production, you would not need this code as the script can close after the pipeline will be sent
57
+ session.run(
58
+ wait=30, # wait for the user to stop the execution or a given time
59
+ close_pipelines=True # when the user stops the execution, the remote edge-node pipelines will be closed
60
+ )
61
+ session.P("Main thread exiting...")
@@ -1,8 +1,10 @@
1
1
  """
2
2
  This is a simple example of how to use the naeural_client SDK.
3
3
 
4
- In this example, we connect to the network, listen for heartbeats from
5
- Naeural Edge Protocol edge nodes and print the CPU of each node.
4
+ In this example:
5
+ - we connect to the network
6
+ - listen for heartbeats from Naeural Edge Protocol edge nodes and print the CPU of each node.
7
+ - listen for payloads from Naeural Edge Protocol edge nodes and print the data of each payload.
6
8
  """
7
9
  import json
8
10
 
@@ -13,6 +15,10 @@ class MessageHandler:
13
15
  def __init__(self, signature_filter: str = None):
14
16
  """
15
17
  This class is used to handle the messages received from the edge nodes.
18
+
19
+ In this class we are defining two callback methods:
20
+ - on_heartbeat: this method is called when a heartbeat is received from an edge node.
21
+ - on_data: this method is called when a payload is received from an edge node.
16
22
  """
17
23
  self.signature_filter = signature_filter.upper() if isinstance(signature_filter, str) else None
18
24
  self.last_data = None # some variable to store the last data received for debugging purposes
@@ -39,7 +45,7 @@ class MessageHandler:
39
45
  heartbeat : dict
40
46
  The heartbeat received from the edge node.
41
47
  """
42
- session.P("{} ({}) has a {}".format(
48
+ session.P("{} ({}) has {}".format(
43
49
  heartbeat['EE_ID'],
44
50
  self.shorten_address(node_addr),
45
51
  heartbeat["CPU"])
@@ -83,14 +89,14 @@ class MessageHandler:
83
89
 
84
90
  if self.signature_filter is not None and plugin_signature.upper() != self.signature_filter:
85
91
  # we are not interested in this data but we still want to log it
86
- message = "Received data from <{}::{}::{}::{}>".format(
92
+ message = "Recv from <{}::{}::{}::{}>".format(
87
93
  addr, pipeline_name, plugin_signature, plugin_instance
88
94
  )
89
95
  color = 'dark'
90
96
  else:
91
97
  # we are interested in this data
92
- message = "Received target data from <{}::{}::{}::{}>\n".format(
93
- node_addr, pipeline_name, plugin_signature, plugin_instance
98
+ message = "Recv data from <{}::{}::{}::{}>\n".format(
99
+ addr, pipeline_name, plugin_signature, plugin_instance
94
100
  )
95
101
  # the actual data is stored in the data.data attribute of the Payload UserDict object
96
102
  # now we just copy some data as a naive example
@@ -150,7 +150,6 @@ if __name__ == "__main__":
150
150
  p = s.create_or_attach_to_pipeline(
151
151
  node=node,
152
152
  name="run_distributed",
153
- data_source="Void"
154
153
  )
155
154
 
156
155
  p.create_chain_dist_custom_plugin_instance(
@@ -1,5 +1,4 @@
1
- from naeural_client import CustomPluginTemplate, Session
2
- from naeural_client.default.instance import CustomWebApp01
1
+ from naeural_client import CustomPluginTemplate, Session, PLUGIN_TYPES
3
2
 
4
3
  # this tutorial can be run only on the local edge node
5
4
  # because it uses ngrok to expose the fastapi server
@@ -48,7 +47,7 @@ if __name__ == "__main__":
48
47
  node = "INSERT_YOUR_NODE_ADDRESS_HERE"
49
48
  session.wait_for_node(node)
50
49
 
51
- instance: CustomWebApp01
50
+ instance: PLUGIN_TYPES.CUSTOM_WEB_APP_01
52
51
  pipeline, instance = session.create_web_app(
53
52
  node=node,
54
53
  name="naeural_predict_app",
@@ -1,5 +1,4 @@
1
- from naeural_client import CustomPluginTemplate, Session
2
- from naeural_client.default.instance import CustomWebApp01
1
+ from naeural_client import CustomPluginTemplate, Session, PLUGIN_TYPES
3
2
 
4
3
  # this tutorial can be run only on the local edge node
5
4
  # because it uses ngrok to expose the fastapi server
@@ -22,11 +21,11 @@ if __name__ == "__main__":
22
21
  node = "0xai_At8N0Qgz78sBLgPtMgifmCabJGkgEzgkEP-1laDggXVM"
23
22
  session.wait_for_node(node)
24
23
 
25
- instance: CustomWebApp01
24
+ instance: PLUGIN_TYPES.CUSTOM_WEB_APP_01
26
25
  pipeline, instance = session.create_web_app(
27
26
  node=node,
28
27
  name="naeural_code_sandbox_copycat_app",
29
- signature=CustomWebApp01,
28
+ signature=PLUGIN_TYPES.CUSTOM_WEB_APP_01, # not mandatory as it is the default value
30
29
 
31
30
  ngrok_edge_label="edghts_2jSQ4nm5TuzGgHh8I0wlfDz3Vr0", # https://naeural-001.ngrok.app
32
31
  use_ngrok=True,
@@ -0,0 +1,48 @@
1
+ import os
2
+
3
+ from naeural_client import Session, CustomPluginTemplate, PLUGIN_TYPES
4
+
5
+
6
+ def reply(plugin: CustomPluginTemplate, message: str, user: str):
7
+ """
8
+ This function is used to reply to a message.
9
+ """
10
+ # for each user message we increase a counter
11
+ plugin.int_cache[user] += 1 # int_cache is a default dict that allows persistence in the plugin
12
+ plugin.P(f"Replying to the {plugin.int_cache[user]} msg of '{user}' on message '{message}'")
13
+ result = f"The answer to your {plugin.int_cache[user]} question is in the question itself: {message}"
14
+ return result
15
+
16
+ if __name__ == "__main__":
17
+ TELEGRAM_BOT_TOKEN_ENV_KEY = "TELEGRAM_BOT_TOKEN"
18
+ MY_NODE = None # we can specify a node here, if we want to connect to a specific
19
+
20
+ session = Session() # assume .env is available and will be used for the connection and tokens
21
+
22
+ if MY_NODE:
23
+ node = MY_NODE
24
+ else:
25
+ session.wait_for_any_node() # we wait for any node to present itself as active
26
+ node = session.get_active_nodes()[0] # we get the first active node
27
+
28
+
29
+ # now we create a telegram bot pipeline & plugin instance
30
+ # we can chose to use the token directly or use the environment key
31
+ instance: PLUGIN_TYPES.BASIC_TELEGRAM_BOT_01
32
+ pipeline, instance = session.create_telegram_simple_bot(
33
+ node=node,
34
+ name="telegram_bot_echo",
35
+ telegram_bot_token_env_key=TELEGRAM_BOT_TOKEN_ENV_KEY,
36
+ reply_function=reply,
37
+ )
38
+
39
+ pipeline.deploy() # we deploy the pipeline
40
+
41
+ # Observation:
42
+ # next code is not mandatory - it is used to keep the session open and cleanup the resources
43
+ # in production, you would not need this code as the script can close after the pipeline will be sent
44
+ session.run(
45
+ wait=60, # we run the session for 60 seconds
46
+ close_pipelines=True, # we close the pipelines after the session
47
+ close_session=True, # we close the session after the session
48
+ )
@@ -1,4 +0,0 @@
1
- from .net_mon_01_plugin import NetMon01
2
- from .view_scene_01_plugin import ViewScene01
3
- from .custom_web_app_01_plugin import CustomWebApp01
4
- from .chain_dist_custom_job_01_plugin import ChainDistCustomJob01
File without changes
File without changes
File without changes