neuronum 5.8.4__py3-none-any.whl → 5.9.0__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 +45 -15
- {neuronum-5.8.4.dist-info → neuronum-5.9.0.dist-info}/METADATA +93 -5
- neuronum-5.9.0.dist-info/RECORD +10 -0
- neuronum-5.8.4.dist-info/RECORD +0 -10
- {neuronum-5.8.4.dist-info → neuronum-5.9.0.dist-info}/WHEEL +0 -0
- {neuronum-5.8.4.dist-info → neuronum-5.9.0.dist-info}/entry_points.txt +0 -0
- {neuronum-5.8.4.dist-info → neuronum-5.9.0.dist-info}/licenses/LICENSE.md +0 -0
- {neuronum-5.8.4.dist-info → neuronum-5.9.0.dist-info}/top_level.txt +0 -0
neuronum/neuronum.py
CHANGED
|
@@ -82,17 +82,18 @@ class Cell:
|
|
|
82
82
|
|
|
83
83
|
async def sync(self, stx: Optional[str] = None) -> AsyncGenerator[str, None]:
|
|
84
84
|
full_url = f"wss://{self.network}/sync/{stx}"
|
|
85
|
-
|
|
86
85
|
auth_payload = {
|
|
87
86
|
"host": self.host,
|
|
88
87
|
"password": self.password,
|
|
89
88
|
"synapse": self.synapse,
|
|
90
89
|
}
|
|
91
90
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
while True:
|
|
92
|
+
try:
|
|
93
|
+
async with websockets.connect(full_url) as ws:
|
|
94
|
+
await ws.send(json.dumps(auth_payload))
|
|
95
|
+
print("Connected to WebSocket.")
|
|
96
|
+
|
|
96
97
|
while True:
|
|
97
98
|
try:
|
|
98
99
|
raw_operation = await ws.recv()
|
|
@@ -100,17 +101,20 @@ class Cell:
|
|
|
100
101
|
yield operation
|
|
101
102
|
|
|
102
103
|
except asyncio.TimeoutError:
|
|
103
|
-
print("No
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
print("No data received. Continuing...")
|
|
105
|
+
except websockets.exceptions.ConnectionClosedError as e:
|
|
106
|
+
print(f"Connection closed with error: {e}. Reconnecting...")
|
|
107
|
+
break
|
|
108
|
+
except Exception as e:
|
|
109
|
+
print(f"Unexpected error in recv loop: {e}")
|
|
110
|
+
break
|
|
111
|
+
|
|
112
|
+
except websockets.exceptions.WebSocketException as e:
|
|
113
|
+
print(f"WebSocket error occurred: {e}. Retrying in 5 seconds...")
|
|
114
|
+
except Exception as e:
|
|
115
|
+
print(f"General error occurred: {e}. Retrying in 5 seconds...")
|
|
111
116
|
|
|
112
|
-
|
|
113
|
-
print(f"An unexpected error occurred: {e}")
|
|
117
|
+
await asyncio.sleep(3)
|
|
114
118
|
|
|
115
119
|
|
|
116
120
|
async def create_tx(self, descr: str, key_values: dict, stx: str, label: str, partners: list):
|
|
@@ -486,4 +490,30 @@ class Cell:
|
|
|
486
490
|
print(f"Unexpected error: {e}")
|
|
487
491
|
|
|
488
492
|
|
|
493
|
+
async def notify(self, receiver: str, title: str, message: str):
|
|
494
|
+
full_url = f"https://{self.network}/api/notify"
|
|
495
|
+
|
|
496
|
+
notify_payload = {
|
|
497
|
+
"receiver": receiver,
|
|
498
|
+
"notification": {
|
|
499
|
+
"title": title,
|
|
500
|
+
"message": message
|
|
501
|
+
},
|
|
502
|
+
"cell": self.to_dict()
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
async with aiohttp.ClientSession() as session:
|
|
506
|
+
try:
|
|
507
|
+
async with session.post(full_url, json=notify_payload) as response:
|
|
508
|
+
response.raise_for_status()
|
|
509
|
+
data = await response.json()
|
|
510
|
+
print(f"Notification sent successfully: {data}")
|
|
511
|
+
return data
|
|
512
|
+
|
|
513
|
+
except aiohttp.ClientError as e:
|
|
514
|
+
print(f"HTTP error while sending notification: {e}")
|
|
515
|
+
except Exception as e:
|
|
516
|
+
print(f"Unexpected error: {e}")
|
|
517
|
+
|
|
518
|
+
|
|
489
519
|
__all__ = ['Cell']
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: neuronum
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.9.0
|
|
4
4
|
Summary: Official client library to interact with the Neuronum Network
|
|
5
5
|
Home-page: https://neuronum.net
|
|
6
6
|
Author: Neuronum Cybernetics
|
|
@@ -34,7 +34,7 @@ Dynamic: summary
|
|
|
34
34
|
<h1 align="center">
|
|
35
35
|
<img src="https://neuronum.net/static/neuronum.svg" alt="Neuronum" width="80">
|
|
36
36
|
</h1>
|
|
37
|
-
<h4 align="center">Neuronum:
|
|
37
|
+
<h4 align="center">Neuronum: The Real Time Data Engine</h4>
|
|
38
38
|
|
|
39
39
|
<p align="center">
|
|
40
40
|
<a href="https://neuronum.net">
|
|
@@ -64,12 +64,12 @@ In this brief getting started guide, you will:
|
|
|
64
64
|
------------------
|
|
65
65
|
|
|
66
66
|
### **About Neuronum**
|
|
67
|
-
Neuronum
|
|
67
|
+
Neuronum is the real-time data engine designed for developers to build event-driven apps and services in minutes using high-level Python
|
|
68
68
|
|
|
69
69
|
### **Features**
|
|
70
70
|
**Cell & Nodes**
|
|
71
71
|
- Cell: Account to connect and interact with Neuronum. [Learn More](https://github.com/neuronumcybernetics/neuronum/tree/main/features/cell)
|
|
72
|
-
- Nodes: Soft- and Hardware components hosting Neuronum data gateways. [Learn More](https://github.com/neuronumcybernetics/neuronum/tree/main/features/nodes)
|
|
72
|
+
- Nodes (Apps): Soft- and Hardware components hosting Neuronum data gateways. [Learn More](https://github.com/neuronumcybernetics/neuronum/tree/main/features/nodes)
|
|
73
73
|
|
|
74
74
|
**Data Gateways**
|
|
75
75
|
- Transmitters (TX): Securely transmit and receive data packages. [Learn More](https://github.com/neuronumcybernetics/neuronum/tree/main/features/transmitters)
|
|
@@ -104,7 +104,7 @@ neuronum connect-cell # connect Cell
|
|
|
104
104
|
|
|
105
105
|
|
|
106
106
|
### **Build On Neuronum**
|
|
107
|
-
[
|
|
107
|
+
To dive deeper into Neuronum App development, visit & build with [Node Examples](https://github.com/neuronumcybernetics/neuronum/tree/main/features/nodes/examples)
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
Initialize a Node (app template):
|
|
@@ -112,6 +112,94 @@ Initialize a Node (app template):
|
|
|
112
112
|
neuronum init-node --app # initialize a Node with app template
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
+
This command prompts you to enter a Node description (e.g Getting Started Node) and creates a new directory named node_<node_id> containing the following files:
|
|
116
|
+
|
|
117
|
+
.env
|
|
118
|
+
```env
|
|
119
|
+
NODE=your_node_id
|
|
120
|
+
HOST=your_cell_id
|
|
121
|
+
PASSWORD=your_password
|
|
122
|
+
NETWORK=neuronum.net
|
|
123
|
+
SYNAPSE=your_synapse # auth token
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
app.py
|
|
127
|
+
```python
|
|
128
|
+
import asyncio
|
|
129
|
+
import neuronum
|
|
130
|
+
import os
|
|
131
|
+
from dotenv import load_dotenv
|
|
132
|
+
|
|
133
|
+
load_dotenv()
|
|
134
|
+
host = os.getenv("HOST")
|
|
135
|
+
password = os.getenv("PASSWORD")
|
|
136
|
+
network = os.getenv("NETWORK")
|
|
137
|
+
synapse = os.getenv("SYNAPSE")
|
|
138
|
+
|
|
139
|
+
cell = neuronum.Cell(
|
|
140
|
+
host=host,
|
|
141
|
+
password=password,
|
|
142
|
+
network=network,
|
|
143
|
+
synapse=synapse
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
async def main():
|
|
147
|
+
STX = "id::stx"
|
|
148
|
+
async for operation in cell.sync(STX):
|
|
149
|
+
txID = operation.get("txID")
|
|
150
|
+
client = operation.get("operator")
|
|
151
|
+
|
|
152
|
+
if txID == "id::tx":
|
|
153
|
+
data = {
|
|
154
|
+
"json": f"Hello {client}",
|
|
155
|
+
"html": f"""
|
|
156
|
+
<!DOCTYPE html>
|
|
157
|
+
<html>
|
|
158
|
+
<head>
|
|
159
|
+
<meta charset="UTF-8">
|
|
160
|
+
<title>Greeting Node</title>
|
|
161
|
+
</head>
|
|
162
|
+
<body>
|
|
163
|
+
<div class="card">
|
|
164
|
+
<h1>Hello, {client}</h1>
|
|
165
|
+
</div>
|
|
166
|
+
</body>
|
|
167
|
+
</html>
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
await cell.tx_response(txID, client, data)
|
|
172
|
+
|
|
173
|
+
asyncio.run(main())
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
NODE.md
|
|
177
|
+
```
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"gateways": [
|
|
181
|
+
{
|
|
182
|
+
"type": "stream",
|
|
183
|
+
"id": "id::stx",
|
|
184
|
+
"link": "https://neuronum.net/stream/id::stx",
|
|
185
|
+
"info": "stream info"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"type": "transmitter",
|
|
189
|
+
"id": "id::tx",
|
|
190
|
+
"link": "https://neuronum.net/tx/id::tx",
|
|
191
|
+
"info": "transmitter info"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"type": "circuit",
|
|
195
|
+
"id": "id::ctx",
|
|
196
|
+
"link": "https://neuronum.net/circuit/id::ctx",
|
|
197
|
+
"info": "circuit info"
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
115
203
|
Change into Node folder
|
|
116
204
|
```sh
|
|
117
205
|
cd node_node_id # change directory
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
cli/main.py,sha256=Yec9ovjqM6iI6IyUU8nhgrpcd7rIMocSoZI8QWY1KC4,35684
|
|
3
|
+
neuronum/__init__.py,sha256=Drsm263_w3_VWgl1YsKLUr8WwVodqV3TSjqpxLjyq_M,46
|
|
4
|
+
neuronum/neuronum.py,sha256=coAcZQFovKZeGVg8qQpfBkp2NdK4MpiIMdg22Vmi7nc,18490
|
|
5
|
+
neuronum-5.9.0.dist-info/licenses/LICENSE.md,sha256=zGst0rjgnp6oFuRVwFwB1Ql4sDXt_nw9xbUR49Gf99A,2008
|
|
6
|
+
neuronum-5.9.0.dist-info/METADATA,sha256=BlBH6oDflT_V2QmOm1JZjYOaONu4QDWto7QJBTGVL2g,7437
|
|
7
|
+
neuronum-5.9.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
neuronum-5.9.0.dist-info/entry_points.txt,sha256=XKYBcRNxGeJpZZkDPsa8HA_RaJ7Km_R_JaUq5T9Nk2U,42
|
|
9
|
+
neuronum-5.9.0.dist-info/top_level.txt,sha256=ru8Fr84cHm6oHr_DcJ8-uaq3RTiuCRFIr6AC8V0zPu4,13
|
|
10
|
+
neuronum-5.9.0.dist-info/RECORD,,
|
neuronum-5.8.4.dist-info/RECORD
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
cli/main.py,sha256=Yec9ovjqM6iI6IyUU8nhgrpcd7rIMocSoZI8QWY1KC4,35684
|
|
3
|
-
neuronum/__init__.py,sha256=Drsm263_w3_VWgl1YsKLUr8WwVodqV3TSjqpxLjyq_M,46
|
|
4
|
-
neuronum/neuronum.py,sha256=L8Oz1qcTyOiYMTGfiSKgN5Nu9jcl25jFeJOh0XItPjw,17201
|
|
5
|
-
neuronum-5.8.4.dist-info/licenses/LICENSE.md,sha256=zGst0rjgnp6oFuRVwFwB1Ql4sDXt_nw9xbUR49Gf99A,2008
|
|
6
|
-
neuronum-5.8.4.dist-info/METADATA,sha256=T9p6cUzgU3c2P9uvagnunGkRVrvC7DKAZZV26JdSQlQ,5367
|
|
7
|
-
neuronum-5.8.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
-
neuronum-5.8.4.dist-info/entry_points.txt,sha256=XKYBcRNxGeJpZZkDPsa8HA_RaJ7Km_R_JaUq5T9Nk2U,42
|
|
9
|
-
neuronum-5.8.4.dist-info/top_level.txt,sha256=ru8Fr84cHm6oHr_DcJ8-uaq3RTiuCRFIr6AC8V0zPu4,13
|
|
10
|
-
neuronum-5.8.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|