neuronum 1.3.0__py3-none-any.whl → 1.3.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.

Potentially problematic release.


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

neuronum/neuronum.py CHANGED
@@ -24,6 +24,16 @@ class Cell:
24
24
 
25
25
  def __repr__(self) -> str:
26
26
  return f"Cell(host={self.host}, password={self.password}, network={self.network}, synapse={self.synapse})"
27
+
28
+
29
+ def authenticate(self, stx: Optional[str] = None):
30
+ credentials = f"{self.host}\n{self.password}\n{self.synapse}\n{stx}\n"
31
+ self.sock.sendall(credentials.encode('utf-8'))
32
+
33
+ response = self.sock.recv(1024).decode('utf-8')
34
+ print(response)
35
+ return "Authentication successful" in response
36
+
27
37
 
28
38
  def activate(self, txID: str, data: dict):
29
39
  url = f"https://{self.network}/activateTX/{txID}"
@@ -161,29 +171,31 @@ class Cell:
161
171
 
162
172
 
163
173
  def stream(self, label: str, data: dict, stx: Optional[str] = None):
174
+ """Stream data after authenticating once."""
164
175
  context = ssl.create_default_context()
165
176
  context.check_hostname = True
166
177
  context.verify_mode = ssl.CERT_REQUIRED
178
+
167
179
  raw_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
168
180
  self.sock = context.wrap_socket(raw_sock, server_hostname=self.network)
169
181
 
170
182
  print("SSL socket set")
171
183
 
172
184
  try:
173
-
174
- stream = {
175
- "label": label,
176
- "data": data,
177
- }
178
-
179
185
  print(f"Connecting to {self.network}")
180
186
  self.sock.connect((self.network, 55555))
181
187
  print("SSL socket connected")
182
188
 
183
- if not self.authenticate(self.sock, stx):
189
+ if not self.authenticate(stx):
184
190
  print("Authentication failed. Cannot stream.")
185
191
  return
186
192
 
193
+ # Stream data
194
+ stream = {
195
+ "label": label,
196
+ "data": data,
197
+ }
198
+
187
199
  self.sock.sendall(json.dumps(stream).encode('utf-8'))
188
200
  print(f"Sent: {stream}")
189
201
 
@@ -197,16 +209,6 @@ class Cell:
197
209
  self.sock.close()
198
210
  print("SSL connection closed.")
199
211
 
200
-
201
- def authenticate(self, sock, stx: Optional[str] = None):
202
- credentials = f"{self.host}\n{self.password}\n{self.synapse}\n{stx}\n"
203
- sock.sendall(credentials.encode('utf-8'))
204
-
205
- response = sock.recv(1024).decode('utf-8')
206
- print(response)
207
- return "Authentication successful" in response
208
-
209
-
210
212
  def sync(self, stx: Optional[str] = None) -> Generator[str, None, None]:
211
213
  auth = {
212
214
  "host": self.host,
@@ -218,7 +220,7 @@ class Cell:
218
220
  while True:
219
221
  try:
220
222
  ws = create_connection(f"wss://{self.network}/sync/{stx}")
221
- ws.settimeout(1)
223
+ ws.settimeout(10)
222
224
  ws.send(json.dumps(auth))
223
225
  print("Connected to WebSocket.")
224
226
 
@@ -228,7 +230,7 @@ class Cell:
228
230
  operation = json.loads(raw_operation)
229
231
  yield operation
230
232
  except socket.timeout:
231
- print("Timeout occurred, no data received.")
233
+ print("Waiting for stream...")
232
234
  except KeyboardInterrupt:
233
235
  print("Closing connection...")
234
236
  ws.close()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neuronum
3
- Version: 1.3.0
3
+ Version: 1.3.2
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
@@ -133,7 +133,7 @@ cell.clear(CTX)
133
133
  ```
134
134
 
135
135
  ### Streams (STX)
136
- Stream data:
136
+ Stream data to your private Stream (STX):
137
137
  ```bash
138
138
  label = "your_label"
139
139
  data = {
@@ -144,7 +144,19 @@ data = {
144
144
  cell.stream(label, data)
145
145
  ```
146
146
 
147
- Sync stream:
147
+ Stream data to a public Stream (STX):
148
+ ```bash
149
+ STX = "id::stx"
150
+ label = "your_label"
151
+ data = {
152
+ "key1": "value1",
153
+ "key2": "value2",
154
+ "key3": "value3",
155
+ }
156
+ cell.stream(label, data, STX)
157
+ ```
158
+
159
+ Sync data from your private Stream (STX):
148
160
  ```bash
149
161
  stream = cell.sync()
150
162
  for operation in stream:
@@ -155,3 +167,15 @@ for operation in stream:
155
167
  operator = operation.get("operator")
156
168
  ```
157
169
 
170
+ Sync data from a public Stream (STX):
171
+ ```bash
172
+ STX = "id::stx"
173
+ stream = cell.sync(STX)
174
+ for operation in stream:
175
+ label = operation.get("label")
176
+ value = operation.get("data").get("key1")
177
+ ts = operation.get("time")
178
+ stxID = operation.get("stxID")
179
+ operator = operation.get("operator")
180
+ ```
181
+
@@ -0,0 +1,7 @@
1
+ neuronum/__init__.py,sha256=Drsm263_w3_VWgl1YsKLUr8WwVodqV3TSjqpxLjyq_M,46
2
+ neuronum/neuronum.py,sha256=FqlYTQSlMZpZMn3Dc4_XyzD60cu1Tdd9ExQzjGDUYPY,7568
3
+ neuronum-1.3.2.dist-info/LICENSE,sha256=UiZjNHiCyRP6WoZfbYQh9cv4JW96wIofKXmzBJrYSUk,1125
4
+ neuronum-1.3.2.dist-info/METADATA,sha256=7bGeBqN6spxPcJgYNJ6KmLDjp4igvP-Vk8TUxMekFEE,4346
5
+ neuronum-1.3.2.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
6
+ neuronum-1.3.2.dist-info/top_level.txt,sha256=73zXVVO9UTTiwEcSaXytsJ8n0q47OCwAqPlIh-hzWJU,9
7
+ neuronum-1.3.2.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- neuronum/__init__.py,sha256=Drsm263_w3_VWgl1YsKLUr8WwVodqV3TSjqpxLjyq_M,46
2
- neuronum/neuronum.py,sha256=UZw5oocfxTJslee0YB74_cWEre3JsyKLoCkh0Lpk3rs,7531
3
- neuronum-1.3.0.dist-info/LICENSE,sha256=UiZjNHiCyRP6WoZfbYQh9cv4JW96wIofKXmzBJrYSUk,1125
4
- neuronum-1.3.0.dist-info/METADATA,sha256=uYFEcqrxGmLUrjYelQeosqDso1sn7fP0zba6VXiFu84,3765
5
- neuronum-1.3.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
6
- neuronum-1.3.0.dist-info/top_level.txt,sha256=73zXVVO9UTTiwEcSaXytsJ8n0q47OCwAqPlIh-hzWJU,9
7
- neuronum-1.3.0.dist-info/RECORD,,