neuronum 1.2.0__py3-none-any.whl → 1.2.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 +48 -27
- {neuronum-1.2.0.dist-info → neuronum-1.2.2.dist-info}/METADATA +19 -19
- neuronum-1.2.2.dist-info/RECORD +7 -0
- neuronum-1.2.0.dist-info/RECORD +0 -8
- neuronum-1.2.0.dist-info/entry_points.txt +0 -2
- {neuronum-1.2.0.dist-info → neuronum-1.2.2.dist-info}/LICENSE +0 -0
- {neuronum-1.2.0.dist-info → neuronum-1.2.2.dist-info}/WHEEL +0 -0
- {neuronum-1.2.0.dist-info → neuronum-1.2.2.dist-info}/top_level.txt +0 -0
neuronum/neuronum.py
CHANGED
|
@@ -3,6 +3,8 @@ import socket
|
|
|
3
3
|
from typing import Optional
|
|
4
4
|
import ssl
|
|
5
5
|
from websocket import create_connection
|
|
6
|
+
from typing import List
|
|
7
|
+
import json
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
class Cell:
|
|
@@ -23,8 +25,8 @@ class Cell:
|
|
|
23
25
|
def __repr__(self) -> str:
|
|
24
26
|
return f"Cell(host={self.host}, password={self.password}, network={self.network}, synapse={self.synapse})"
|
|
25
27
|
|
|
26
|
-
def activate(self, txID: str, data: dict
|
|
27
|
-
|
|
28
|
+
def activate(self, txID: str, data: dict):
|
|
29
|
+
url = f"https://{self.network}/activateTX/{txID}"
|
|
28
30
|
|
|
29
31
|
TX = {
|
|
30
32
|
"data": data,
|
|
@@ -33,13 +35,13 @@ class Cell:
|
|
|
33
35
|
|
|
34
36
|
try:
|
|
35
37
|
response = requests.post(
|
|
36
|
-
|
|
38
|
+
url,
|
|
37
39
|
json=TX,
|
|
38
40
|
)
|
|
39
41
|
|
|
40
42
|
response.raise_for_status()
|
|
41
43
|
|
|
42
|
-
print(f"Response from
|
|
44
|
+
print(f"Response from Neuronum: {response.json()}")
|
|
43
45
|
|
|
44
46
|
except requests.exceptions.RequestException as e:
|
|
45
47
|
print(f"Error sending request: {e}")
|
|
@@ -48,17 +50,15 @@ class Cell:
|
|
|
48
50
|
|
|
49
51
|
|
|
50
52
|
|
|
51
|
-
def test_connection(self
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
print(f"Full URL: {full_url}")
|
|
53
|
+
def test_connection(self):
|
|
54
|
+
url = f"https://{self.network}/testConnection"
|
|
55
55
|
|
|
56
56
|
test = {
|
|
57
57
|
"cell": self.to_dict()
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
try:
|
|
61
|
-
response = requests.post(
|
|
61
|
+
response = requests.post(url, json=test)
|
|
62
62
|
response.raise_for_status()
|
|
63
63
|
print(response.json())
|
|
64
64
|
except requests.exceptions.RequestException as e:
|
|
@@ -82,7 +82,7 @@ class Cell:
|
|
|
82
82
|
try:
|
|
83
83
|
response = requests.post(full_url, json=store)
|
|
84
84
|
response.raise_for_status()
|
|
85
|
-
print(f"Response from
|
|
85
|
+
print(f"Response from Neuronum: {response.json()}")
|
|
86
86
|
except requests.exceptions.RequestException as e:
|
|
87
87
|
print(f"Error sending request: {e}")
|
|
88
88
|
except Exception as e:
|
|
@@ -160,7 +160,7 @@ class Cell:
|
|
|
160
160
|
|
|
161
161
|
|
|
162
162
|
|
|
163
|
-
def stream(self, data):
|
|
163
|
+
def stream(self, label: str, data: dict, stx: Optional[str] = None):
|
|
164
164
|
context = ssl.create_default_context()
|
|
165
165
|
context.check_hostname = True
|
|
166
166
|
context.verify_mode = ssl.CERT_REQUIRED
|
|
@@ -170,16 +170,22 @@ class Cell:
|
|
|
170
170
|
print("SSL socket set")
|
|
171
171
|
|
|
172
172
|
try:
|
|
173
|
-
|
|
173
|
+
|
|
174
|
+
stream = {
|
|
175
|
+
"label": label,
|
|
176
|
+
"data": data,
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
print(f"Connecting to {self.network}")
|
|
174
180
|
self.sock.connect((self.network, 55555))
|
|
175
181
|
print("SSL socket connected")
|
|
176
182
|
|
|
177
|
-
if not self.authenticate(self.sock):
|
|
183
|
+
if not self.authenticate(self.sock, stx):
|
|
178
184
|
print("Authentication failed. Cannot stream.")
|
|
179
185
|
return
|
|
180
186
|
|
|
181
|
-
self.sock.sendall(
|
|
182
|
-
print(f"Sent: {
|
|
187
|
+
self.sock.sendall(json.dumps(stream).encode('utf-8'))
|
|
188
|
+
print(f"Sent: {stream}")
|
|
183
189
|
|
|
184
190
|
except ssl.SSLError as e:
|
|
185
191
|
print(f"SSL error occurred: {e}")
|
|
@@ -192,31 +198,46 @@ class Cell:
|
|
|
192
198
|
print("SSL connection closed.")
|
|
193
199
|
|
|
194
200
|
|
|
195
|
-
def authenticate(self, sock):
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
|
202
208
|
|
|
203
209
|
|
|
204
|
-
def sync(self,
|
|
210
|
+
def sync(self, stx: Optional[str] = None) -> List[str]:
|
|
211
|
+
stream = []
|
|
205
212
|
try:
|
|
206
|
-
|
|
207
|
-
|
|
213
|
+
auth = {
|
|
214
|
+
"host": self.host,
|
|
215
|
+
"password": self.password,
|
|
216
|
+
"synapse": self.synapse,
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
ws = create_connection(f"wss://{self.network}/sync/{stx}")
|
|
220
|
+
ws.settimeout(1)
|
|
221
|
+
print(f"Auth Payload: {auth}")
|
|
222
|
+
ws.send(json.dumps(auth))
|
|
223
|
+
|
|
208
224
|
except Exception as e:
|
|
209
225
|
print(f"Failed to connect: {e}")
|
|
210
|
-
return
|
|
226
|
+
return stream
|
|
211
227
|
|
|
212
228
|
try:
|
|
213
229
|
while True:
|
|
214
230
|
message = ws.recv()
|
|
215
231
|
print(f"Received Data: {message}")
|
|
232
|
+
stream.append(message)
|
|
216
233
|
except KeyboardInterrupt:
|
|
217
234
|
print("Closing connection...")
|
|
235
|
+
except Exception as e:
|
|
236
|
+
print(f"Error during data collection: {e}")
|
|
218
237
|
finally:
|
|
219
238
|
ws.close()
|
|
220
|
-
|
|
239
|
+
print("Connection closed.")
|
|
240
|
+
|
|
241
|
+
return stream
|
|
221
242
|
|
|
222
243
|
__all__ = ['Cell']
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: neuronum
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.2
|
|
4
4
|
Summary: Interact with the Neuronum Network to build, connect & automate economic data streams
|
|
5
|
-
Home-page: https://
|
|
5
|
+
Home-page: https://neuronum.net
|
|
6
6
|
Author: Neuronum Cybernetics
|
|
7
7
|
Author-email: welcome@neuronum.net
|
|
8
|
+
Project-URL: GitHub, https://github.com/neuronumcybernetics/neuronum
|
|
8
9
|
Classifier: Programming Language :: Python :: 3
|
|
9
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
11
|
Classifier: Operating System :: OS Independent
|
|
@@ -25,21 +26,21 @@ Interact with the `Neuronum Network` to build, connect & automate economic data
|
|
|
25
26
|
## Business Cell Features
|
|
26
27
|
- **Transmitters (TX)**: Automate economic data transfer + Circuits Integration
|
|
27
28
|
- **Circuits (CTX)**: A simple Key-Value-Label database to store economic data
|
|
28
|
-
- **Streams (STX)**: Stream economic data to synchronize devices
|
|
29
|
+
- **Streams (STX)**: Stream economic data to synchronize devices and databases in real time
|
|
29
30
|
|
|
30
31
|
## Community Cell Features
|
|
31
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
|
|
32
34
|
|
|
33
35
|
## Getting Started
|
|
34
36
|
Create your Neuronum Business/Community Cell: [Create Cell](https://neuronum.net/createcell)
|
|
35
37
|
|
|
36
|
-
|
|
37
38
|
Install the Neuronum library using pip:
|
|
38
39
|
```bash
|
|
39
40
|
pip install neuronum
|
|
40
41
|
```
|
|
41
42
|
|
|
42
|
-
Set
|
|
43
|
+
Set and test Cell connection:
|
|
43
44
|
```bash
|
|
44
45
|
import neuronum
|
|
45
46
|
|
|
@@ -49,24 +50,22 @@ password="your_password",
|
|
|
49
50
|
network="neuronum.net",
|
|
50
51
|
synapse="your_synapse"
|
|
51
52
|
)
|
|
52
|
-
|
|
53
53
|
cell.test_connection()
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
### Transmitters (TX)
|
|
56
57
|
Activate Transmitter (TX):
|
|
57
58
|
```bash
|
|
58
59
|
TX = "id::tx"
|
|
59
|
-
|
|
60
60
|
data = {
|
|
61
61
|
"key1": "value1",
|
|
62
62
|
"key2": "value2",
|
|
63
63
|
"key3": "value3",
|
|
64
|
-
"key4": "value4"
|
|
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,19 +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
|
-
cell.sync(STX)
|
|
138
|
+
stream = cell.sync()
|
|
140
139
|
```
|
|
140
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
neuronum/__init__.py,sha256=Drsm263_w3_VWgl1YsKLUr8WwVodqV3TSjqpxLjyq_M,46
|
|
2
|
+
neuronum/neuronum.py,sha256=Y0BMTTfBM3E9scEM57aDNj6wkwRH6yA0XwLj0nohodQ,7290
|
|
3
|
+
neuronum-1.2.2.dist-info/LICENSE,sha256=UiZjNHiCyRP6WoZfbYQh9cv4JW96wIofKXmzBJrYSUk,1125
|
|
4
|
+
neuronum-1.2.2.dist-info/METADATA,sha256=nHWQUddV45PHdXejJxwxgca6fhrWk_9OcVrKOnTRSss,3423
|
|
5
|
+
neuronum-1.2.2.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
6
|
+
neuronum-1.2.2.dist-info/top_level.txt,sha256=73zXVVO9UTTiwEcSaXytsJ8n0q47OCwAqPlIh-hzWJU,9
|
|
7
|
+
neuronum-1.2.2.dist-info/RECORD,,
|
neuronum-1.2.0.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
neuronum/__init__.py,sha256=Drsm263_w3_VWgl1YsKLUr8WwVodqV3TSjqpxLjyq_M,46
|
|
2
|
-
neuronum/neuronum.py,sha256=06qogFQ_a3dOqa6dgvLadltcYj8mtnxAqBxsYafB2uU,6746
|
|
3
|
-
neuronum-1.2.0.dist-info/LICENSE,sha256=UiZjNHiCyRP6WoZfbYQh9cv4JW96wIofKXmzBJrYSUk,1125
|
|
4
|
-
neuronum-1.2.0.dist-info/METADATA,sha256=zEqH8GXUGxlrw5TtQQ4XwLp00TitmlkxscMA0JYd0Nw,3184
|
|
5
|
-
neuronum-1.2.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
6
|
-
neuronum-1.2.0.dist-info/entry_points.txt,sha256=HAUSjcFCB-PSkwnZQy9qEaelZmzS6EmTMjrhPynPKg8,47
|
|
7
|
-
neuronum-1.2.0.dist-info/top_level.txt,sha256=73zXVVO9UTTiwEcSaXytsJ8n0q47OCwAqPlIh-hzWJU,9
|
|
8
|
-
neuronum-1.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|