neuronum 1.2.1__py3-none-any.whl → 1.2.3__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 +60 -44
- {neuronum-1.2.1.dist-info → neuronum-1.2.3.dist-info}/METADATA +16 -17
- neuronum-1.2.3.dist-info/RECORD +7 -0
- neuronum-1.2.1.dist-info/RECORD +0 -7
- {neuronum-1.2.1.dist-info → neuronum-1.2.3.dist-info}/LICENSE +0 -0
- {neuronum-1.2.1.dist-info → neuronum-1.2.3.dist-info}/WHEEL +0 -0
- {neuronum-1.2.1.dist-info → neuronum-1.2.3.dist-info}/top_level.txt +0 -0
neuronum/neuronum.py
CHANGED
|
@@ -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
|
|
28
|
-
|
|
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
|
-
|
|
38
|
+
url,
|
|
38
39
|
json=TX,
|
|
39
40
|
)
|
|
40
41
|
|
|
41
42
|
response.raise_for_status()
|
|
42
43
|
|
|
43
|
-
print(f"Response from
|
|
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
|
|
53
|
-
|
|
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(
|
|
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
|
|
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
|
-
|
|
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(
|
|
183
|
-
print(f"Sent: {
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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.
|
|
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
|
|
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
|
|
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
|
-
|
|
133
|
-
|
|
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
|
|
136
|
+
Sync stream:
|
|
137
137
|
```bash
|
|
138
|
-
|
|
139
|
-
data = cell.sync(STX)
|
|
138
|
+
stream = cell.sync()
|
|
140
139
|
```
|
|
141
140
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
neuronum/__init__.py,sha256=Drsm263_w3_VWgl1YsKLUr8WwVodqV3TSjqpxLjyq_M,46
|
|
2
|
+
neuronum/neuronum.py,sha256=SexnB-knTtsJIa1zjLoW11W3yVbjeM2ytz79TbTMX_k,7637
|
|
3
|
+
neuronum-1.2.3.dist-info/LICENSE,sha256=UiZjNHiCyRP6WoZfbYQh9cv4JW96wIofKXmzBJrYSUk,1125
|
|
4
|
+
neuronum-1.2.3.dist-info/METADATA,sha256=AnPbAHXlSKzNRSEgTiSdGQgo0dQYpfBPmfkDzfKDwBE,3423
|
|
5
|
+
neuronum-1.2.3.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
6
|
+
neuronum-1.2.3.dist-info/top_level.txt,sha256=73zXVVO9UTTiwEcSaXytsJ8n0q47OCwAqPlIh-hzWJU,9
|
|
7
|
+
neuronum-1.2.3.dist-info/RECORD,,
|
neuronum-1.2.1.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
neuronum/__init__.py,sha256=Drsm263_w3_VWgl1YsKLUr8WwVodqV3TSjqpxLjyq_M,46
|
|
2
|
-
neuronum/neuronum.py,sha256=nn_vEskQyALPRXZTuWPn89kXqkut9vMPGC9t-WNaYzM,6999
|
|
3
|
-
neuronum-1.2.1.dist-info/LICENSE,sha256=UiZjNHiCyRP6WoZfbYQh9cv4JW96wIofKXmzBJrYSUk,1125
|
|
4
|
-
neuronum-1.2.1.dist-info/METADATA,sha256=dmrkgRF0rbHh4q1tVI12uQBj4jg-5Lw4w3tvI9indy4,3214
|
|
5
|
-
neuronum-1.2.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
6
|
-
neuronum-1.2.1.dist-info/top_level.txt,sha256=73zXVVO9UTTiwEcSaXytsJ8n0q47OCwAqPlIh-hzWJU,9
|
|
7
|
-
neuronum-1.2.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|