naeural-client 2.5.6__py3-none-any.whl → 2.5.8__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.5.6"
1
+ __VER__ = "2.5.8"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
@@ -24,7 +24,9 @@ from .payload import Payload
24
24
  from .pipeline import Pipeline
25
25
  from .webapp_pipeline import WebappPipeline
26
26
  from .transaction import Transaction
27
- from ..utils.config import load_user_defined_config, get_user_config_file, get_user_folder
27
+ from ..utils.config import (
28
+ load_user_defined_config, get_user_config_file, get_user_folder, seconds_to_short_format
29
+ )
28
30
 
29
31
  # from ..default.instance import PLUGIN_TYPES # circular import
30
32
 
@@ -571,7 +573,7 @@ class GenericSession(BaseDecentrAIObject):
571
573
  sender_addr = dict_msg.get(PAYLOAD_DATA.EE_SENDER, None)
572
574
  path = dict_msg.get(PAYLOAD_DATA.EE_PAYLOAD_PATH, [None, None, None, None])
573
575
  ee_id = dict_msg.get(PAYLOAD_DATA.EE_ID, None)
574
- current_network = dict_msg.get(PAYLOAD_DATA.NETMON_CURRENT_NETWORK, {})
576
+ current_network = dict_msg.get(PAYLOAD_DATA.NETMON_CURRENT_NETWORK, {})
575
577
  if current_network:
576
578
  all_addresses = [
577
579
  x[PAYLOAD_DATA.NETMON_ADDRESS] for x in current_network.values()
@@ -1853,6 +1855,10 @@ class GenericSession(BaseDecentrAIObject):
1853
1855
  """
1854
1856
  Create a new web app on a list of nodes.
1855
1857
 
1858
+ IMPORTANT:
1859
+ The web app will be exposed using ngrok from multiple nodes that all will share the
1860
+ same edge label so the ngrok_edge_label is mandatory.
1861
+
1856
1862
  Parameters
1857
1863
  ----------
1858
1864
 
@@ -1877,14 +1883,16 @@ class GenericSession(BaseDecentrAIObject):
1877
1883
  """
1878
1884
 
1879
1885
  ngrok_use_api = True
1880
- use_ngrok=True,
1886
+ use_ngrok = True
1887
+ kwargs.pop('use_ngrok', None)
1888
+ kwargs.pop('ngrok_use_api', None)
1881
1889
 
1882
1890
  # if isinstance(signature, str):
1883
1891
 
1884
1892
  pipelines, instances = [], []
1885
1893
 
1886
1894
  for node in nodes:
1887
- self.P("Creating web app on node {}...".format(node), color='y')
1895
+ self.P("Creating web app on node {}...".format(node), color='b')
1888
1896
  pipeline: WebappPipeline = self.create_pipeline(
1889
1897
  node=nodes[0],
1890
1898
  name=name,
@@ -2226,7 +2234,14 @@ class GenericSession(BaseDecentrAIObject):
2226
2234
  def client_address(self):
2227
2235
  return self.get_client_address()
2228
2236
 
2229
- def get_network_known_nodes(self, timeout=10, online_only=False, supervisors_only=False):
2237
+ def get_network_known_nodes(
2238
+ self,
2239
+ timeout=10,
2240
+ online_only=False,
2241
+ supervisors_only=False,
2242
+ min_supervisors=2,
2243
+ supervisor=None,
2244
+ ):
2230
2245
  """
2231
2246
  This function will return a Pandas dataframe known nodes in the network based on
2232
2247
  all the net-mon messages received so far.
@@ -2234,10 +2249,10 @@ class GenericSession(BaseDecentrAIObject):
2234
2249
  mapping = OrderedDict({
2235
2250
  'Address': PAYLOAD_DATA.NETMON_ADDRESS,
2236
2251
  'Alias' : PAYLOAD_DATA.NETMON_EEID,
2252
+ 'Seen ago' : PAYLOAD_DATA.NETMON_LAST_SEEN,
2237
2253
  'Last state': PAYLOAD_DATA.NETMON_STATUS_KEY,
2238
- 'Ago (s)' : PAYLOAD_DATA.NETMON_LAST_SEEN,
2239
2254
  'Last probe' : PAYLOAD_DATA.NETMON_LAST_REMOTE_TIME,
2240
- 'Node zone' : PAYLOAD_DATA.NETMON_NODE_UTC,
2255
+ 'Zone' : PAYLOAD_DATA.NETMON_NODE_UTC,
2241
2256
  'Supervisor' : PAYLOAD_DATA.NETMON_IS_SUPERVISOR,
2242
2257
  })
2243
2258
  reverse_mapping = {v: k for k, v in mapping.items()}
@@ -2245,8 +2260,12 @@ class GenericSession(BaseDecentrAIObject):
2245
2260
  for k in mapping:
2246
2261
  res[k] = []
2247
2262
  start = tm()
2263
+
2248
2264
  while (tm() - start) < timeout:
2249
- if len(self.__current_network_statuses) > 0:
2265
+ if supervisor is not None:
2266
+ if supervisor in self.__current_network_statuses:
2267
+ break
2268
+ elif len(self.__current_network_statuses) >= min_supervisors:
2250
2269
  break
2251
2270
  sleep(0.1)
2252
2271
  # end while
@@ -2269,10 +2288,15 @@ class GenericSession(BaseDecentrAIObject):
2269
2288
  val = node_info.get(key, None)
2270
2289
  if key == PAYLOAD_DATA.NETMON_LAST_REMOTE_TIME:
2271
2290
  # val hols a string '2024-12-23 23:50:16.462155' and must be converted to a datetime
2272
- val = dt.strptime(val, '%Y-%m-%d %H:%M:%S.%f')
2273
- # strip the microseconds
2274
- val = val.replace(microsecond=0)
2291
+ val = dt.strptime(val, '%Y-%m-%d %H:%M:%S.%f')
2292
+ val = val.replace(microsecond=0) # strip the microseconds
2293
+ elif key == PAYLOAD_DATA.NETMON_LAST_SEEN:
2294
+ # convert val (seconds) to a human readable format
2295
+ val = seconds_to_short_format(val)
2296
+ elif key == PAYLOAD_DATA.NETMON_ADDRESS:
2297
+ val = self.bc_engine._add_prefix(val)
2275
2298
  res[column].append(val)
2276
2299
  # end for
2277
2300
  # end if
2301
+ pd.options.display.float_format = '{:.1f}'.format
2278
2302
  return pd.DataFrame(res), best_super
naeural_client/cli/cli.py CHANGED
@@ -52,9 +52,14 @@ def build_parser():
52
52
  if isinstance(subcmd_info, dict) and "params" in subcmd_info:
53
53
  for param, description in subcmd_info["params"].items():
54
54
  if param.startswith("--"):
55
- subcommand_parser.add_argument(
56
- param, action="store_true", help=description
57
- )
55
+ if description.upper().endswith("FLAG"):
56
+ subcommand_parser.add_argument(
57
+ param, action="store_true", help=description
58
+ )
59
+ else:
60
+ subcommand_parser.add_argument(
61
+ param, help=description, type=str
62
+ )
58
63
  else:
59
64
  subcommand_parser.add_argument(
60
65
  param, help=description
@@ -63,6 +68,9 @@ def build_parser():
63
68
  #end for
64
69
  #end if
65
70
  subcommand_parser.set_defaults(func=subcmd_info["func"])
71
+ #end for
72
+ # Fallback help for `-h <subcommand>` like `nepctl -h config`
73
+ command_parser.set_defaults(func=lambda args: command_parser.print_help())
66
74
  else:
67
75
  # Single-level commands with parameters
68
76
  if "params" in subcommands:
@@ -11,9 +11,10 @@ CLI_COMMANDS = {
11
11
  "nodes": {
12
12
  "func": get_nodes,
13
13
  "params": {
14
- "--all": "Get all known nodes", # DONE
15
- "--online" : "Get only online nodes", # DONE
14
+ "--all": "Get all known nodes flag", # DONE
15
+ "--online" : "Get only online nodes flag", # DONE
16
16
  # "--peered": "Get only peered nodes"
17
+ "--supervisor" : "Use a specific supervisor node"
17
18
  }
18
19
  },
19
20
  "supervisors": {
@@ -10,21 +10,25 @@ def get_nodes(args):
10
10
  3. Wait for the second net mon message via Session and show progress.
11
11
  4. Get the active nodes union via Session and display the nodes marking those peered vs non-peered.
12
12
  """
13
- if args.verbose:
14
- log_with_color("Getting nodes...", color='b')
13
+ supervisor_addr = args.supervisor
14
+ # log_with_color(f"Getting nodes from supervisor <{supervisor_addr}>...", color='b')
15
15
  from naeural_client import Session
16
16
  sess = Session(silent=not args.verbose)
17
17
  if args.all:
18
- df, supervisor = sess.get_network_known_nodes()
19
- log_with_color(f"Network historical map as seen by <{supervisor}>:", color='b')
18
+ df, supervisor = sess.get_network_known_nodes(supervisor=supervisor_addr)
19
+ log_with_color(f"Network full map reported by <{supervisor}>:", color='b')
20
20
  log_with_color(f"{df}")
21
21
  elif args.online:
22
- df, supervisor = sess.get_network_known_nodes(online_only=True)
23
- log_with_color(f"Online nodes as seen by <{supervisor}>:", color='b')
22
+ df, supervisor = sess.get_network_known_nodes(
23
+ online_only=True, supervisor=supervisor_addr
24
+ )
25
+ log_with_color(f"Online nodes reported by <{supervisor}>:", color='b')
24
26
  log_with_color(f"{df}")
25
27
  else:
26
- df, supervisor = sess.get_network_known_nodes(online_only=True)
27
- log_with_color(f"Online nodes as seen by <{supervisor}>:", color='b')
28
+ df, supervisor = sess.get_network_known_nodes(
29
+ online_only=True, supervisor=supervisor_addr
30
+ )
31
+ log_with_color(f"Online nodes reported by <{supervisor}>:", color='b')
28
32
  log_with_color(f"{df}")
29
33
  return
30
34
 
@@ -14,6 +14,34 @@ EE_SECURED=true
14
14
  TARGET_NODE=
15
15
  """
16
16
 
17
+ def seconds_to_short_format(seconds):
18
+ """
19
+ Converts a duration in seconds into a short human-readable format: "Xd HH:MM:SS".
20
+
21
+ Parameters
22
+ ----------
23
+ seconds : int
24
+ The total duration in seconds.
25
+
26
+ Returns
27
+ -------
28
+ str
29
+ Short human-readable duration in "Xd HH:MM:SS" format.
30
+ """
31
+ days = int(seconds / (24 * 3600))
32
+ seconds %= (24 * 3600)
33
+ hours = int(seconds / 3600)
34
+ seconds %= 3600
35
+ minutes = int(seconds / 60)
36
+ seconds %= 60
37
+ seconds = int(seconds)
38
+
39
+ # Format the result
40
+ if days > 0:
41
+ return f"{days}d {hours:02}:{minutes:02}:{seconds:02}"
42
+ else:
43
+ return f"{hours:02}:{minutes:02}:{seconds:02}"
44
+
17
45
  def log_with_color(s, color='n'):
18
46
  """
19
47
  Prints the string `s` to the console in the specified color.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: naeural_client
3
- Version: 2.5.6
3
+ Version: 2.5.8
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/NaeuralEdgeProtocol/naeural_client
6
6
  Project-URL: Bug Tracker, https://github.com/NaeuralEdgeProtocol/naeural_client/issues
@@ -1,10 +1,10 @@
1
1
  naeural_client/__init__.py,sha256=GP8WSrn87sjTPO-QRNL2PG8JK5Mixbiea_HrtbG8RAQ,592
2
- naeural_client/_ver.py,sha256=eM0cjdG-7WKPMa-eHgFEcSnK6DZxqwpsE_ucv5E50nQ,330
2
+ naeural_client/_ver.py,sha256=U6QiJieJV9JDC_Mjz3ycdADSzIDI8FlRxv4soJ34EYk,330
3
3
  naeural_client/base_decentra_object.py,sha256=C4iwZTkhKNBS4VHlJs5DfElRYLo4Q9l1V1DNVSk1fyQ,4412
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=byrjQ6J-VsDj12LZbq0wRgDwQeJuH-soHqZNET_2Wa0,84855
7
+ naeural_client/base/generic_session.py,sha256=3pvPZCIiygD-QWggmWUOZWj52o6la5koEYd2R-OF9YQ,85692
8
8
  naeural_client/base/instance.py,sha256=kcZJmjLBtx8Bjj_ysIOx1JmLA-qSpG7E28j5rq6IYus,20444
9
9
  naeural_client/base/pipeline.py,sha256=b4uNHrEIOlAtw4PGUx20dxwBhDck5__SrVXaHcSi8ZA,58251
10
10
  naeural_client/base/plugin_template.py,sha256=qGaXByd_JZFpjvH9GXNbT7KaitRxIJB6-1IhbKrZjq4,138123
@@ -20,9 +20,9 @@ naeural_client/bc/ec.py,sha256=mWjodWCRgC3omVXOA9jtNdtPVNn2kMKV3Dcjt9oFUCQ,22974
20
20
  naeural_client/certs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  naeural_client/certs/r9092118.ala.eu-central-1.emqxsl.com.crt,sha256=y-6io0tseyx9-a4Pmde1z1gPULtJNSYUpG_YFkYaMKU,1337
22
22
  naeural_client/cli/README.md,sha256=WPdI_EjzAbUW1aPyj1sSR8rLydcJKZtoiaEtklQrjHo,74
23
- naeural_client/cli/cli.py,sha256=1BdWhedmFGgAeiEZvDfzbavSLJ7n2N9qM9qLYvvfFaU,3381
24
- naeural_client/cli/cli_commands.py,sha256=_oPGZ4nq24qNmXHknkYO8Hb2-SSCRgsR5L_Ac-7dxsM,1316
25
- naeural_client/cli/nodes.py,sha256=gmc-9ETnSB3eSX_lPv3XkZ1jM1aUFsQzInwqCqUY_bQ,2155
23
+ naeural_client/cli/cli.py,sha256=GyQhw16LrCbXU0JLH0HlbyYvKqa15K5RIhQ-Pgi7Gy4,3752
24
+ naeural_client/cli/cli_commands.py,sha256=BtByinaxFvThyQdeu8Moz2aMioR5MW5GTiI1bGjbfwQ,1392
25
+ naeural_client/cli/nodes.py,sha256=84gcpzZyPrJdrutOftwTGWwW55FvjkHZ0vf8NfmLAMk,2314
26
26
  naeural_client/code_cheker/__init__.py,sha256=pwkdeZGVL16ZA4Qf2mRahEhoOvKhL7FyuQbMFLr1E5M,33
27
27
  naeural_client/code_cheker/base.py,sha256=lT5DRIFO5rqzsMNCmdMRfkAeevmezozehyfgmhnKpuI,19074
28
28
  naeural_client/code_cheker/checker.py,sha256=QWupeM7ToancVIq1tRUxRNUrI8B5l5eoY0kDU4-O5aE,7365
@@ -79,10 +79,10 @@ naeural_client/logging/tzlocal/win32.py,sha256=zBoj0vFVrGhnCm_f7xmYzGym4-fV-4Ij2
79
79
  naeural_client/logging/tzlocal/windows_tz.py,sha256=Sv9okktjZJfRGGUOOppsvQuX_eXyXUxkSKCAFmWT9Hw,34203
80
80
  naeural_client/utils/__init__.py,sha256=mAnke3-MeRzz3nhQvhuHqLnpaaCSmDxicd7Ck9uwpmI,77
81
81
  naeural_client/utils/comm_utils.py,sha256=4cS9llRr_pK_3rNgDcRMCQwYPO0kcNU7AdWy_LtMyCY,1072
82
- naeural_client/utils/config.py,sha256=Ltagd1qI3EpqwhAVVpTXAWoVlO8ca8hKVk5cmAQBV9k,4563
82
+ naeural_client/utils/config.py,sha256=aUVyi5rZjvnbUwM5mmj0E2IHvURdrlHSgleqZvJBNuU,5202
83
83
  naeural_client/utils/dotenv.py,sha256=_AgSo35n7EnQv5yDyu7C7i0kHragLJoCGydHjvOkrYY,2008
84
- naeural_client-2.5.6.dist-info/METADATA,sha256=jrlqTyqmxWUUDNuk5Bt1FkcXGHt5IzYKoZV9pPnD3AA,14493
85
- naeural_client-2.5.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
86
- naeural_client-2.5.6.dist-info/entry_points.txt,sha256=PNdyotDaQBAslZREx5luVyj0kqpQnwNACwkFNTPIHU4,55
87
- naeural_client-2.5.6.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
88
- naeural_client-2.5.6.dist-info/RECORD,,
84
+ naeural_client-2.5.8.dist-info/METADATA,sha256=-9ZEY7NRPuPvc9-7hqTqlxNk29OqOLfCZG8D2Galhwo,14493
85
+ naeural_client-2.5.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
86
+ naeural_client-2.5.8.dist-info/entry_points.txt,sha256=PNdyotDaQBAslZREx5luVyj0kqpQnwNACwkFNTPIHU4,55
87
+ naeural_client-2.5.8.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
88
+ naeural_client-2.5.8.dist-info/RECORD,,