neuronum 1.3.3__tar.gz → 1.4.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.

Potentially problematic release.


This version of neuronum might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neuronum
3
- Version: 1.3.3
3
+ Version: 1.4.0
4
4
  Summary: Interact with the Neuronum Network to build, connect & automate economic data streams
5
5
  Home-page: https://neuronum.net
6
6
  Author: Neuronum Cybernetics
@@ -26,7 +26,8 @@ Interact with the `Neuronum Network` to build, connect & automate economic data
26
26
  ## Cell Features
27
27
  - **Transmitters (TX)**: Automate economic data transfer + Circuits Integration
28
28
  - **Circuits (CTX)**: A simple Key-Value-Label database to store economic data
29
- - **Streams (STX)**: stream, synchronize and control data in real time
29
+ - **Streams (STX)**: Stream, synchronize and control data in real time
30
+ - **Nodes**: Register Nodes actively running the Neuronum library
30
31
 
31
32
  ## Getting Started
32
33
  Create your Neuronum Cell: [Create Cell](https://neuronum.net/createcell)
@@ -175,3 +176,11 @@ for operation in stream:
175
176
  operator = operation.get("operator")
176
177
  ```
177
178
 
179
+ ### Nodes
180
+ Register a Neuronum Node with its associated Stream:
181
+ ```bash
182
+ node = "name_your_node"
183
+ STX = "id::stx"
184
+ cell.register(node, STX)
185
+ ```
186
+
@@ -9,7 +9,8 @@ Interact with the `Neuronum Network` to build, connect & automate economic data
9
9
  ## Cell Features
10
10
  - **Transmitters (TX)**: Automate economic data transfer + Circuits Integration
11
11
  - **Circuits (CTX)**: A simple Key-Value-Label database to store economic data
12
- - **Streams (STX)**: stream, synchronize and control data in real time
12
+ - **Streams (STX)**: Stream, synchronize and control data in real time
13
+ - **Nodes**: Register Nodes actively running the Neuronum library
13
14
 
14
15
  ## Getting Started
15
16
  Create your Neuronum Cell: [Create Cell](https://neuronum.net/createcell)
@@ -158,3 +159,11 @@ for operation in stream:
158
159
  operator = operation.get("operator")
159
160
  ```
160
161
 
162
+ ### Nodes
163
+ Register a Neuronum Node with its associated Stream:
164
+ ```bash
165
+ node = "name_your_node"
166
+ STX = "id::stx"
167
+ cell.register(node, STX)
168
+ ```
169
+
@@ -3,7 +3,6 @@ import socket
3
3
  from typing import Optional, Generator
4
4
  import ssl
5
5
  from websocket import create_connection
6
- from typing import List
7
6
  import json
8
7
 
9
8
 
@@ -60,6 +59,32 @@ class Cell:
60
59
 
61
60
 
62
61
 
62
+ def register(self, node: str, stx: str):
63
+ url = f"https://{self.network}/register/node"
64
+
65
+ node = {
66
+ "description": node,
67
+ "stream": stx,
68
+ "cell": self.to_dict()
69
+ }
70
+
71
+ try:
72
+ response = requests.post(
73
+ url,
74
+ json=node,
75
+ )
76
+
77
+ response.raise_for_status()
78
+
79
+ print(f"Response from Neuronum: {response.json()}")
80
+
81
+ except requests.exceptions.RequestException as e:
82
+ print(f"Error sending request: {e}")
83
+ except Exception as e:
84
+ print(f"Unexpected error: {e}")
85
+
86
+
87
+
63
88
  def test_connection(self):
64
89
  url = f"https://{self.network}/testConnection"
65
90
 
@@ -169,9 +194,7 @@ class Cell:
169
194
  print(f"Unexpected error: {e}")
170
195
 
171
196
 
172
-
173
197
  def stream(self, label: str, data: dict, stx: Optional[str] = None):
174
- """Stream data after authenticating once."""
175
198
  context = ssl.create_default_context()
176
199
  context.check_hostname = True
177
200
  context.verify_mode = ssl.CERT_REQUIRED
@@ -179,18 +202,14 @@ class Cell:
179
202
  raw_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
180
203
  self.sock = context.wrap_socket(raw_sock, server_hostname=self.network)
181
204
 
182
- print("SSL socket set")
183
-
184
205
  try:
185
206
  print(f"Connecting to {self.network}")
186
207
  self.sock.connect((self.network, 55555))
187
- print("SSL socket connected")
188
208
 
189
209
  if not self.authenticate(stx):
190
210
  print("Authentication failed. Cannot stream.")
191
211
  return
192
212
 
193
- # Stream data
194
213
  stream = {
195
214
  "label": label,
196
215
  "data": data,
@@ -207,7 +226,7 @@ class Cell:
207
226
 
208
227
  finally:
209
228
  self.sock.close()
210
- print("SSL connection closed.")
229
+
211
230
 
212
231
  def sync(self, stx: Optional[str] = None) -> Generator[str, None, None]:
213
232
  auth = {
@@ -215,32 +234,49 @@ class Cell:
215
234
  "password": self.password,
216
235
  "synapse": self.synapse,
217
236
  }
218
- print(f"Auth Payload: {auth}")
237
+ ws = None
219
238
 
220
- while True:
221
- try:
222
- ws = create_connection(f"wss://{self.network}/sync/{stx}")
223
- ws.settimeout(10)
224
- ws.send(json.dumps(auth))
225
- print("Connected to WebSocket.")
239
+ try:
240
+ while True:
241
+ try:
242
+ ws = create_connection(f"wss://{self.network}/sync/{stx}")
243
+ ws.settimeout(1)
244
+ ws.send(json.dumps(auth))
245
+ print("Stream connection set...")
226
246
 
227
- while True:
228
247
  try:
229
248
  raw_operation = ws.recv()
230
249
  operation = json.loads(raw_operation)
250
+ print("Listening to Stream...")
231
251
  yield operation
252
+
253
+ ws.settimeout(None)
254
+
255
+ while True:
256
+ raw_operation = ws.recv()
257
+ operation = json.loads(raw_operation)
258
+ yield operation
232
259
  except socket.timeout:
233
- print("Waiting for stream...")
234
- except KeyboardInterrupt:
235
- print("Closing connection...")
260
+ print("No initial data received. Retrying connection...")
236
261
  ws.close()
237
- return
238
- except Exception as e:
239
- print(f"Connection failed: {e}")
240
- finally:
241
- if ws:
242
- ws.close()
243
- print("Connection closed, retrying...")
244
262
 
245
-
263
+ except KeyboardInterrupt:
264
+ print("Stream-Synchronization ended!")
265
+ if ws:
266
+ ws.close()
267
+ print("Connection closed. Exiting.")
268
+ return
269
+ except Exception as e:
270
+ print(f"{e}")
271
+ finally:
272
+ if ws:
273
+ ws.close()
274
+ print("Connection closed.")
275
+ except KeyboardInterrupt:
276
+ print("Stream-Synchronization ended!")
277
+ if ws:
278
+ ws.close()
279
+ print("Connection closed. Goodbye!")
280
+
281
+
246
282
  __all__ = ['Cell']
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neuronum
3
- Version: 1.3.3
3
+ Version: 1.4.0
4
4
  Summary: Interact with the Neuronum Network to build, connect & automate economic data streams
5
5
  Home-page: https://neuronum.net
6
6
  Author: Neuronum Cybernetics
@@ -26,7 +26,8 @@ Interact with the `Neuronum Network` to build, connect & automate economic data
26
26
  ## Cell Features
27
27
  - **Transmitters (TX)**: Automate economic data transfer + Circuits Integration
28
28
  - **Circuits (CTX)**: A simple Key-Value-Label database to store economic data
29
- - **Streams (STX)**: stream, synchronize and control data in real time
29
+ - **Streams (STX)**: Stream, synchronize and control data in real time
30
+ - **Nodes**: Register Nodes actively running the Neuronum library
30
31
 
31
32
  ## Getting Started
32
33
  Create your Neuronum Cell: [Create Cell](https://neuronum.net/createcell)
@@ -175,3 +176,11 @@ for operation in stream:
175
176
  operator = operation.get("operator")
176
177
  ```
177
178
 
179
+ ### Nodes
180
+ Register a Neuronum Node with its associated Stream:
181
+ ```bash
182
+ node = "name_your_node"
183
+ STX = "id::stx"
184
+ cell.register(node, STX)
185
+ ```
186
+
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='neuronum',
5
- version='1.3.3',
5
+ version='1.4.0',
6
6
  author='Neuronum Cybernetics',
7
7
  author_email='welcome@neuronum.net',
8
8
  description='Interact with the Neuronum Network to build, connect & automate economic data streams',
File without changes
File without changes
File without changes