neuronum 1.2.1__tar.gz → 1.2.3__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.2.1
3
+ Version: 1.2.3
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,21 +26,21 @@ Interact with the `Neuronum Network` to build, connect & automate economic data
26
26
  ## Business 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 economic data to synchronize devices & databases in real time (beta)
29
+ - **Streams (STX)**: Stream economic data to synchronize devices and databases in real time
30
30
 
31
31
  ## Community Cell Features
32
32
  - **Circuits (CTX)**: A simple Key-Value-Label database (perfect for testing and side projects)
33
+ - **Streams (STX)**: Stream economic data to synchronize devices and databases in real time
33
34
 
34
35
  ## Getting Started
35
36
  Create your Neuronum Business/Community Cell: [Create Cell](https://neuronum.net/createcell)
36
37
 
37
-
38
38
  Install the Neuronum library using pip:
39
39
  ```bash
40
40
  pip install neuronum
41
41
  ```
42
42
 
43
- Set & test Cell connection:
43
+ Set and test Cell connection:
44
44
  ```bash
45
45
  import neuronum
46
46
 
@@ -50,23 +50,22 @@ password="your_password",
50
50
  network="neuronum.net",
51
51
  synapse="your_synapse"
52
52
  )
53
-
54
53
  cell.test_connection()
55
54
  ```
56
55
 
56
+ ### Transmitters (TX)
57
57
  Activate Transmitter (TX):
58
58
  ```bash
59
59
  TX = "id::tx"
60
-
61
60
  data = {
62
61
  "key1": "value1",
63
62
  "key2": "value2",
64
63
  "key3": "value3",
65
64
  }
66
-
67
65
  cell.activate(TX, data)
68
66
  ```
69
67
 
68
+ ### Circuits (CTX)
70
69
  Store data on your private Circuit (CTX):
71
70
  ```bash
72
71
  label = "your_label"
@@ -81,7 +80,6 @@ cell.store(label, data)
81
80
  Store data on a public Circuit (CTX):
82
81
  ```bash
83
82
  CTX = "id::ctx"
84
-
85
83
  label = "your_label"
86
84
  data = {
87
85
  "key1": "value1",
@@ -94,7 +92,6 @@ cell.store(label, data, CTX)
94
92
  Load data from your private Circuit (CTX):
95
93
  ```bash
96
94
  label = "your_label"
97
-
98
95
  data = cell.load(label)
99
96
  key1 = data["key1"]
100
97
  key2 = data["key2"]
@@ -104,9 +101,7 @@ key3 = data["key3"]
104
101
  Load data from a public Circuit (CTX):
105
102
  ```bash
106
103
  CTX = "id::ctx"
107
-
108
104
  label = "your_label"
109
-
110
105
  data = cell.load(label, CTX)
111
106
  key1 = data["key1"]
112
107
  key2 = data["key2"]
@@ -122,20 +117,24 @@ data = cell.delete(label)
122
117
  Delete data from a public Circuit (CTX):
123
118
  ```bash
124
119
  CTX = "id::ctx"
125
-
126
120
  label = "your_label"
127
121
  data = cell.delete(label, CTX)
128
122
  ```
129
123
 
124
+ ### Streams (STX)
130
125
  Stream data:
131
126
  ```bash
132
- data = "your_data"
133
- cell.stream(data)
127
+ label = "your_label"
128
+ data = {
129
+ "key1": "value1",
130
+ "key2": "value2",
131
+ "key3": "value3",
132
+ }
133
+ cell.stream(label, data)
134
134
  ```
135
135
 
136
- Sync data:
136
+ Sync stream:
137
137
  ```bash
138
- STX = "stx::id"
139
- data = cell.sync(STX)
138
+ stream = cell.sync()
140
139
  ```
141
140
 
@@ -9,21 +9,21 @@ Interact with the `Neuronum Network` to build, connect & automate economic data
9
9
  ## Business 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 economic data to synchronize devices & databases in real time (beta)
12
+ - **Streams (STX)**: Stream economic data to synchronize devices and databases in real time
13
13
 
14
14
  ## Community Cell Features
15
15
  - **Circuits (CTX)**: A simple Key-Value-Label database (perfect for testing and side projects)
16
+ - **Streams (STX)**: Stream economic data to synchronize devices and databases in real time
16
17
 
17
18
  ## Getting Started
18
19
  Create your Neuronum Business/Community Cell: [Create Cell](https://neuronum.net/createcell)
19
20
 
20
-
21
21
  Install the Neuronum library using pip:
22
22
  ```bash
23
23
  pip install neuronum
24
24
  ```
25
25
 
26
- Set & test Cell connection:
26
+ Set and test Cell connection:
27
27
  ```bash
28
28
  import neuronum
29
29
 
@@ -33,23 +33,22 @@ password="your_password",
33
33
  network="neuronum.net",
34
34
  synapse="your_synapse"
35
35
  )
36
-
37
36
  cell.test_connection()
38
37
  ```
39
38
 
39
+ ### Transmitters (TX)
40
40
  Activate Transmitter (TX):
41
41
  ```bash
42
42
  TX = "id::tx"
43
-
44
43
  data = {
45
44
  "key1": "value1",
46
45
  "key2": "value2",
47
46
  "key3": "value3",
48
47
  }
49
-
50
48
  cell.activate(TX, data)
51
49
  ```
52
50
 
51
+ ### Circuits (CTX)
53
52
  Store data on your private Circuit (CTX):
54
53
  ```bash
55
54
  label = "your_label"
@@ -64,7 +63,6 @@ cell.store(label, data)
64
63
  Store data on a public Circuit (CTX):
65
64
  ```bash
66
65
  CTX = "id::ctx"
67
-
68
66
  label = "your_label"
69
67
  data = {
70
68
  "key1": "value1",
@@ -77,7 +75,6 @@ cell.store(label, data, CTX)
77
75
  Load data from your private Circuit (CTX):
78
76
  ```bash
79
77
  label = "your_label"
80
-
81
78
  data = cell.load(label)
82
79
  key1 = data["key1"]
83
80
  key2 = data["key2"]
@@ -87,9 +84,7 @@ key3 = data["key3"]
87
84
  Load data from a public Circuit (CTX):
88
85
  ```bash
89
86
  CTX = "id::ctx"
90
-
91
87
  label = "your_label"
92
-
93
88
  data = cell.load(label, CTX)
94
89
  key1 = data["key1"]
95
90
  key2 = data["key2"]
@@ -105,20 +100,24 @@ data = cell.delete(label)
105
100
  Delete data from a public Circuit (CTX):
106
101
  ```bash
107
102
  CTX = "id::ctx"
108
-
109
103
  label = "your_label"
110
104
  data = cell.delete(label, CTX)
111
105
  ```
112
106
 
107
+ ### Streams (STX)
113
108
  Stream data:
114
109
  ```bash
115
- data = "your_data"
116
- cell.stream(data)
110
+ label = "your_label"
111
+ data = {
112
+ "key1": "value1",
113
+ "key2": "value2",
114
+ "key3": "value3",
115
+ }
116
+ cell.stream(label, data)
117
117
  ```
118
118
 
119
- Sync data:
119
+ Sync stream:
120
120
  ```bash
121
- STX = "stx::id"
122
- data = cell.sync(STX)
121
+ stream = cell.sync()
123
122
  ```
124
123
 
@@ -4,6 +4,7 @@ from typing import Optional
4
4
  import ssl
5
5
  from websocket import create_connection
6
6
  from typing import List
7
+ import json
7
8
 
8
9
 
9
10
  class Cell:
@@ -24,8 +25,8 @@ class Cell:
24
25
  def __repr__(self) -> str:
25
26
  return f"Cell(host={self.host}, password={self.password}, network={self.network}, synapse={self.synapse})"
26
27
 
27
- def activate(self, txID: str, data: dict, base_url: str = "https://{network}/activateTX"):
28
- full_url = base_url.format(network=self.network) + f"/{txID}"
28
+ def activate(self, txID: str, data: dict):
29
+ url = f"https://{self.network}/activateTX/{txID}"
29
30
 
30
31
  TX = {
31
32
  "data": data,
@@ -34,13 +35,13 @@ class Cell:
34
35
 
35
36
  try:
36
37
  response = requests.post(
37
- full_url,
38
+ url,
38
39
  json=TX,
39
40
  )
40
41
 
41
42
  response.raise_for_status()
42
43
 
43
- print(f"Response from FastAPI backend: {response.json()}")
44
+ print(f"Response from Neuronum: {response.json()}")
44
45
 
45
46
  except requests.exceptions.RequestException as e:
46
47
  print(f"Error sending request: {e}")
@@ -49,17 +50,15 @@ class Cell:
49
50
 
50
51
 
51
52
 
52
- def test_connection(self, base_url: str = "https://{network}/testConnection"):
53
- full_url = base_url.format(network=self.network)
54
-
55
- print(f"Full URL: {full_url}")
53
+ def test_connection(self):
54
+ url = f"https://{self.network}/testConnection"
56
55
 
57
56
  test = {
58
57
  "cell": self.to_dict()
59
58
  }
60
59
 
61
60
  try:
62
- response = requests.post(full_url, json=test)
61
+ response = requests.post(url, json=test)
63
62
  response.raise_for_status()
64
63
  print(response.json())
65
64
  except requests.exceptions.RequestException as e:
@@ -83,7 +82,7 @@ class Cell:
83
82
  try:
84
83
  response = requests.post(full_url, json=store)
85
84
  response.raise_for_status()
86
- print(f"Response from FastAPI backend: {response.json()}")
85
+ print(f"Response from Neuronum: {response.json()}")
87
86
  except requests.exceptions.RequestException as e:
88
87
  print(f"Error sending request: {e}")
89
88
  except Exception as e:
@@ -161,7 +160,7 @@ class Cell:
161
160
 
162
161
 
163
162
 
164
- def stream(self, data):
163
+ def stream(self, label: str, data: dict, stx: Optional[str] = None):
165
164
  context = ssl.create_default_context()
166
165
  context.check_hostname = True
167
166
  context.verify_mode = ssl.CERT_REQUIRED
@@ -171,16 +170,22 @@ class Cell:
171
170
  print("SSL socket set")
172
171
 
173
172
  try:
174
- print(f"Connecting to {self.network} on port 55555...")
173
+
174
+ stream = {
175
+ "label": label,
176
+ "data": data,
177
+ }
178
+
179
+ print(f"Connecting to {self.network}")
175
180
  self.sock.connect((self.network, 55555))
176
181
  print("SSL socket connected")
177
182
 
178
- if not self.authenticate(self.sock):
183
+ if not self.authenticate(self.sock, stx):
179
184
  print("Authentication failed. Cannot stream.")
180
185
  return
181
186
 
182
- self.sock.sendall(data.encode('utf-8'))
183
- print(f"Sent: {data}")
187
+ self.sock.sendall(json.dumps(stream).encode('utf-8'))
188
+ print(f"Sent: {stream}")
184
189
 
185
190
  except ssl.SSLError as e:
186
191
  print(f"SSL error occurred: {e}")
@@ -193,38 +198,49 @@ class Cell:
193
198
  print("SSL connection closed.")
194
199
 
195
200
 
196
- def authenticate(self, sock):
197
- credentials = f"{self.host}\n{self.password}\n{self.synapse}\n"
198
- sock.sendall(credentials.encode('utf-8'))
199
-
200
- response = sock.recv(1024).decode('utf-8')
201
- print(response)
202
- return "Authentication successful" in response
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
203
208
 
204
209
 
205
- def sync(self, STX: str) -> List[str]:
206
- data = []
207
- try:
208
- ws = create_connection(f"wss://{self.network}/ws/{STX}")
209
- print(f"Connected to Stream {STX}")
210
- except Exception as e:
211
- print(f"Failed to connect: {e}")
212
- return data
210
+ def sync(self, stx: Optional[str] = None) -> List[str]:
211
+ stream = []
212
+ auth = {
213
+ "host": self.host,
214
+ "password": self.password,
215
+ "synapse": self.synapse,
216
+ }
217
+ print(f"Auth Payload: {auth}")
213
218
 
214
- try:
215
- while True:
216
- message = ws.recv()
217
- print(f"Received Data: {message}")
218
- data.append(message)
219
- except KeyboardInterrupt:
220
- print("Closing connection...")
221
- except Exception as e:
222
- print(f"Error during data collection: {e}")
223
- finally:
224
- ws.close()
225
- print("Connection closed.")
219
+ while True:
220
+ try:
221
+ ws = create_connection(f"wss://{self.network}/sync/{stx}")
222
+ ws.settimeout(1) # Set timeout for receiving data
223
+ ws.send(json.dumps(auth))
224
+ print("Connected to WebSocket.")
225
+
226
+ while True:
227
+ try:
228
+ message = ws.recv()
229
+ print(f"Received Data: {message}")
230
+ stream.append(message)
231
+ except socket.timeout:
232
+ # Timeout occurred, but keep the connection open
233
+ print("Timeout occurred, no data received.")
234
+ except KeyboardInterrupt:
235
+ print("Closing connection...")
236
+ ws.close()
237
+ return stream
238
+ except Exception as e:
239
+ print(f"Connection failed: {e}")
240
+ finally:
241
+ if ws:
242
+ ws.close()
243
+ print("Connection closed, retrying...")
226
244
 
227
- return data
228
-
229
245
 
230
246
  __all__ = ['Cell']
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neuronum
3
- Version: 1.2.1
3
+ Version: 1.2.3
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,21 +26,21 @@ Interact with the `Neuronum Network` to build, connect & automate economic data
26
26
  ## Business 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 economic data to synchronize devices & databases in real time (beta)
29
+ - **Streams (STX)**: Stream economic data to synchronize devices and databases in real time
30
30
 
31
31
  ## Community Cell Features
32
32
  - **Circuits (CTX)**: A simple Key-Value-Label database (perfect for testing and side projects)
33
+ - **Streams (STX)**: Stream economic data to synchronize devices and databases in real time
33
34
 
34
35
  ## Getting Started
35
36
  Create your Neuronum Business/Community Cell: [Create Cell](https://neuronum.net/createcell)
36
37
 
37
-
38
38
  Install the Neuronum library using pip:
39
39
  ```bash
40
40
  pip install neuronum
41
41
  ```
42
42
 
43
- Set & test Cell connection:
43
+ Set and test Cell connection:
44
44
  ```bash
45
45
  import neuronum
46
46
 
@@ -50,23 +50,22 @@ password="your_password",
50
50
  network="neuronum.net",
51
51
  synapse="your_synapse"
52
52
  )
53
-
54
53
  cell.test_connection()
55
54
  ```
56
55
 
56
+ ### Transmitters (TX)
57
57
  Activate Transmitter (TX):
58
58
  ```bash
59
59
  TX = "id::tx"
60
-
61
60
  data = {
62
61
  "key1": "value1",
63
62
  "key2": "value2",
64
63
  "key3": "value3",
65
64
  }
66
-
67
65
  cell.activate(TX, data)
68
66
  ```
69
67
 
68
+ ### Circuits (CTX)
70
69
  Store data on your private Circuit (CTX):
71
70
  ```bash
72
71
  label = "your_label"
@@ -81,7 +80,6 @@ cell.store(label, data)
81
80
  Store data on a public Circuit (CTX):
82
81
  ```bash
83
82
  CTX = "id::ctx"
84
-
85
83
  label = "your_label"
86
84
  data = {
87
85
  "key1": "value1",
@@ -94,7 +92,6 @@ cell.store(label, data, CTX)
94
92
  Load data from your private Circuit (CTX):
95
93
  ```bash
96
94
  label = "your_label"
97
-
98
95
  data = cell.load(label)
99
96
  key1 = data["key1"]
100
97
  key2 = data["key2"]
@@ -104,9 +101,7 @@ key3 = data["key3"]
104
101
  Load data from a public Circuit (CTX):
105
102
  ```bash
106
103
  CTX = "id::ctx"
107
-
108
104
  label = "your_label"
109
-
110
105
  data = cell.load(label, CTX)
111
106
  key1 = data["key1"]
112
107
  key2 = data["key2"]
@@ -122,20 +117,24 @@ data = cell.delete(label)
122
117
  Delete data from a public Circuit (CTX):
123
118
  ```bash
124
119
  CTX = "id::ctx"
125
-
126
120
  label = "your_label"
127
121
  data = cell.delete(label, CTX)
128
122
  ```
129
123
 
124
+ ### Streams (STX)
130
125
  Stream data:
131
126
  ```bash
132
- data = "your_data"
133
- cell.stream(data)
127
+ label = "your_label"
128
+ data = {
129
+ "key1": "value1",
130
+ "key2": "value2",
131
+ "key3": "value3",
132
+ }
133
+ cell.stream(label, data)
134
134
  ```
135
135
 
136
- Sync data:
136
+ Sync stream:
137
137
  ```bash
138
- STX = "stx::id"
139
- data = cell.sync(STX)
138
+ stream = cell.sync()
140
139
  ```
141
140
 
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='neuronum',
5
- version='1.2.1',
5
+ version='1.2.3',
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