artificialbrains-sdk 0.1.0__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.
- artificialbrains_sdk-0.1.0/PKG-INFO +370 -0
- artificialbrains_sdk-0.1.0/README.md +356 -0
- artificialbrains_sdk-0.1.0/ab_sdk/__init__.py +63 -0
- artificialbrains_sdk-0.1.0/ab_sdk/client.py +270 -0
- artificialbrains_sdk-0.1.0/ab_sdk/contract_scaffold.py +315 -0
- artificialbrains_sdk-0.1.0/ab_sdk/endpoints.py +48 -0
- artificialbrains_sdk-0.1.0/ab_sdk/input_streamer.py +174 -0
- artificialbrains_sdk-0.1.0/ab_sdk/plugins/__init__.py +69 -0
- artificialbrains_sdk-0.1.0/ab_sdk/plugins/decoder.py +331 -0
- artificialbrains_sdk-0.1.0/ab_sdk/plugins/deviation.py +59 -0
- artificialbrains_sdk-0.1.0/ab_sdk/plugins/reward.py +55 -0
- artificialbrains_sdk-0.1.0/ab_sdk/robot_loop.py +184 -0
- artificialbrains_sdk-0.1.0/ab_sdk/run_session.py +305 -0
- artificialbrains_sdk-0.1.0/artificialbrains_sdk.egg-info/PKG-INFO +370 -0
- artificialbrains_sdk-0.1.0/artificialbrains_sdk.egg-info/SOURCES.txt +18 -0
- artificialbrains_sdk-0.1.0/artificialbrains_sdk.egg-info/dependency_links.txt +1 -0
- artificialbrains_sdk-0.1.0/artificialbrains_sdk.egg-info/requires.txt +5 -0
- artificialbrains_sdk-0.1.0/artificialbrains_sdk.egg-info/top_level.txt +1 -0
- artificialbrains_sdk-0.1.0/pyproject.toml +28 -0
- artificialbrains_sdk-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: artificialbrains_sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ArtificialBrains Python SDK
|
|
5
|
+
Classifier: Programming Language :: Python :: 3
|
|
6
|
+
Classifier: License :: Other/Proprietary License
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: httpx>=0.25
|
|
10
|
+
Requires-Dist: python-socketio>=5.10
|
|
11
|
+
Requires-Dist: websocket-client>=1.6
|
|
12
|
+
Requires-Dist: requests>=2.31
|
|
13
|
+
Requires-Dist: python-dotenv>=1.0
|
|
14
|
+
|
|
15
|
+
# ArtificialBrains Python SDK
|
|
16
|
+
|
|
17
|
+
This repository contains a Python SDK for interacting with the
|
|
18
|
+
Artificial Brains API. Artificial Brains is the end-to-end platform for building biologically inspired brain for robots, using a new apporach to robotic intelligence based on Spiking Neural Networks, bringing continual learning and edge computing as its main benefits.
|
|
19
|
+
|
|
20
|
+
This SDK wraps the REST and realtime endpoints and
|
|
21
|
+
provides helpers for streaming sensor data, decoding neural output
|
|
22
|
+
spikes into robot commands, building feedback rasters and computing
|
|
23
|
+
rewards. The goal of this SDK is to make it easy for developers to
|
|
24
|
+
connect their own robots, simulators or control systems to the
|
|
25
|
+
Artificial Brains backend without having to re‑implement the low level
|
|
26
|
+
protocol.
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
|
|
30
|
+
- **HTTP client** for starting and stopping runs and querying state
|
|
31
|
+
- **Realtime client** built on Socket.IO for streaming inputs and
|
|
32
|
+
receiving telemetry at high rates
|
|
33
|
+
- **Input streamer** that automatically responds to server requests for
|
|
34
|
+
sensor data
|
|
35
|
+
- **Generic spike decoders** that convert brain output spikes into
|
|
36
|
+
actuator deltas using flexible mapping rules and decoding schemes
|
|
37
|
+
commands; includes a ready to use bipolar split decoder
|
|
38
|
+
- **Deviation and reward plugins** for computing error signals and
|
|
39
|
+
global/per‑layer rewards
|
|
40
|
+
- **Feedback error generator** to build correction spikes from
|
|
41
|
+
deviations
|
|
42
|
+
- **Reward modulation** helper mirroring biological-brains behaviour around rewards for learning rules
|
|
43
|
+
|
|
44
|
+
The SDK abstracts away the networking details and allows you to
|
|
45
|
+
focus on your controller and learning logic.
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
### Install from PyPI (recommended)
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install artificialbrains_sdk
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This installs the official, versioned ArtificialBrains Python SDK.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Install from GitHub
|
|
59
|
+
|
|
60
|
+
You can also install the SDK directly from GitHub:
|
|
61
|
+
```bash
|
|
62
|
+
pip install git+https://github.com/artificial-brains-inc/artificial_brains_sdk_py.git
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
To install a specific release:
|
|
66
|
+
```bash
|
|
67
|
+
pip install git+https://github.com/artificial-brains-inc/artificial_brains_sdk_py.git@v0.1.0
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Requirements
|
|
71
|
+
|
|
72
|
+
This SDK requires Python **3.8** or newer. It depends on the
|
|
73
|
+
following third party libraries:
|
|
74
|
+
|
|
75
|
+
- [`python‑socketio` ≥ 5.16.0](https://pypi.org/project/python-socketio/), released on
|
|
76
|
+
24 December 2025【35173131248404†L25-L33】, which provides the Socket.IO client
|
|
77
|
+
implementation used for realtime communication.
|
|
78
|
+
- [`httpx` ≥ 0.28.1](https://pypi.org/project/httpx/), released on
|
|
79
|
+
6 December 2024【174665618111792†L25-L33】, a modern HTTP client that
|
|
80
|
+
supports both synchronous and asynchronous APIs.
|
|
81
|
+
|
|
82
|
+
The SDK itself is pure Python and has no additional compiled
|
|
83
|
+
dependencies.
|
|
84
|
+
|
|
85
|
+
You can install the required dependencies into your project by
|
|
86
|
+
creating a `requirements.txt` file and running `pip install -r requirements.txt`:
|
|
87
|
+
|
|
88
|
+
```txt
|
|
89
|
+
python-socketio==5.16.0
|
|
90
|
+
httpx==0.28.1
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
After installing dependencies you can include this SDK in your
|
|
94
|
+
project by copying the `ab_sdk` directory into your source tree or
|
|
95
|
+
adding it to your Python path.
|
|
96
|
+
|
|
97
|
+
## Quick start
|
|
98
|
+
|
|
99
|
+
The typical workflow when using this SDK is:
|
|
100
|
+
|
|
101
|
+
1. Create an `ABClient` pointing at your Artificial Brains API:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from ab_sdk import ABClient
|
|
105
|
+
client = ABClient("https://artificialbrains.app/api/", api_key="my_secret")
|
|
106
|
+
|
|
107
|
+
# start a run for project 'project_id' -- you'll find it in your project.
|
|
108
|
+
run = client.start("rproject_id")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
2. Attach sensor providers and start streaming inputs:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from ab_sdk import InputStreamer
|
|
115
|
+
|
|
116
|
+
streamer = InputStreamer(run)
|
|
117
|
+
|
|
118
|
+
# provider function returning the latest JPEG image from your camera
|
|
119
|
+
def get_camera_frame():
|
|
120
|
+
# user code here
|
|
121
|
+
img_bytes = ... # bytes of JPEG
|
|
122
|
+
return {
|
|
123
|
+
'format': 'jpeg',
|
|
124
|
+
'meta': {'width': 640, 'height': 480},
|
|
125
|
+
'data': img_bytes,
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
streamer.register_input('cam_rgb', 'Image', get_camera_frame)
|
|
129
|
+
|
|
130
|
+
# provider function returning audio as raw PCM
|
|
131
|
+
def get_audio_chunk():
|
|
132
|
+
pcm = ... # bytes of 16‑bit PCM
|
|
133
|
+
return {
|
|
134
|
+
'format': 'pcm16',
|
|
135
|
+
'meta': {'sampleRate': 16000, 'channels': 1},
|
|
136
|
+
'data': pcm,
|
|
137
|
+
}
|
|
138
|
+
streamer.register_kind('Audio', get_audio_chunk)
|
|
139
|
+
|
|
140
|
+
streamer.start()
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
3. Define a decoder to turn output spikes into robot commands and
|
|
144
|
+
create a control loop:
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from ab_sdk import RobotLoop
|
|
148
|
+
from ab_sdk.plugins.decoder import MappingEntry
|
|
149
|
+
|
|
150
|
+
# define how each output population drives a joint
|
|
151
|
+
mapping = [
|
|
152
|
+
MappingEntry(
|
|
153
|
+
node_id="V1",
|
|
154
|
+
channel="joint:0",
|
|
155
|
+
scheme="bipolarSplit",
|
|
156
|
+
per_step_max=0.004,
|
|
157
|
+
gain=0.5,
|
|
158
|
+
),
|
|
159
|
+
MappingEntry(
|
|
160
|
+
node_id="L1",
|
|
161
|
+
channel="joint:1",
|
|
162
|
+
scheme="bipolarSplit",
|
|
163
|
+
per_step_max=0.004,
|
|
164
|
+
gain=0.5,
|
|
165
|
+
),
|
|
166
|
+
MappingEntry(
|
|
167
|
+
node_id="P1",
|
|
168
|
+
channel="gripper",
|
|
169
|
+
scheme="addition",
|
|
170
|
+
per_step_max=0.001,
|
|
171
|
+
gain=1.0,
|
|
172
|
+
),
|
|
173
|
+
]
|
|
174
|
+
|
|
175
|
+
run.set_decoder(decoder)
|
|
176
|
+
|
|
177
|
+
# callback returning the current robot state
|
|
178
|
+
def get_state():
|
|
179
|
+
return {
|
|
180
|
+
'q': [0.0, 0.0], # joint positions
|
|
181
|
+
'dq': [0.0, 0.0], # joint velocities
|
|
182
|
+
'grip': {'pos': 0.0},
|
|
183
|
+
'dt': 0.02,
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
# callback applying the decoded command to your robot
|
|
187
|
+
def apply_command(cmd):
|
|
188
|
+
dq = cmd['dq']
|
|
189
|
+
dg = cmd['dg']
|
|
190
|
+
# send dq and dg to your motors / gripper here
|
|
191
|
+
print(f"Move joints by {dq}, gripper by {dg}")
|
|
192
|
+
|
|
193
|
+
loop = RobotLoop(run, state_provider=get_state, command_executor=apply_command)
|
|
194
|
+
loop.run_forever()
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Decoder model
|
|
198
|
+
|
|
199
|
+
Decoders in Artificial Brains are **mapping-based and robot-agnostic**.
|
|
200
|
+
|
|
201
|
+
The brain emits spike activity per output population and timestep.
|
|
202
|
+
The SDK converts this activity into actuator deltas using:
|
|
203
|
+
|
|
204
|
+
- a **mapping** from output populations to actuator channels
|
|
205
|
+
- a **scheme** defining how spikes become a scalar value
|
|
206
|
+
|
|
207
|
+
Channel names are arbitrary strings defined by the developer
|
|
208
|
+
(e.g. `"joint:0"`, `"wheel:left"`, `"thruster:z"`, `"gripper"`).
|
|
209
|
+
|
|
210
|
+
Supported decoding schemes include:
|
|
211
|
+
|
|
212
|
+
- `bipolarSplit` – difference between first and second half of spikes
|
|
213
|
+
- `addition` – sum of spikes
|
|
214
|
+
- `booleanThreshold` – binary activation based on spike count
|
|
215
|
+
- `bipolarScalar` – {-1, 0, +1} winner-take-all
|
|
216
|
+
|
|
217
|
+
Multiple output populations may target the same channel; their deltas
|
|
218
|
+
are accumulated per timestep.
|
|
219
|
+
|
|
220
|
+
The decoder produces **per-timestep actuator deltas**, leaving all
|
|
221
|
+
integration, physics, and control semantics to the user’s controller.
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
4. (Optional) Sync the project contract and scaffold learning policies:
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
client.sync_policies("robot_arm", policies_dir="policies")
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
This creates reward and deviation policy files that can be customized
|
|
231
|
+
without risk of being overwritten when the project graph changes.
|
|
232
|
+
|
|
233
|
+
## Policies & Contracts
|
|
234
|
+
|
|
235
|
+
Artificial Brains separates **machine-owned contracts** from
|
|
236
|
+
**user-owned learning logic**.
|
|
237
|
+
|
|
238
|
+
The SDK provides a safe mechanism to scaffold and update learning
|
|
239
|
+
policies without overwriting user code.
|
|
240
|
+
|
|
241
|
+
### Generated policy structure
|
|
242
|
+
|
|
243
|
+
When syncing a project contract, the SDK creates a `policies/` directory:
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
policies/
|
|
247
|
+
├── reward_policy.py # user-owned (created once, never overwritten)
|
|
248
|
+
├── error_deviation_policy.py # user-owned (created once, never overwritten)
|
|
249
|
+
├── _contract.json # machine-owned (always overwritten)
|
|
250
|
+
├── _contract.py # machine-owned (always overwritten)
|
|
251
|
+
└── _contract.sha256 # machine-owned (always overwritten)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
- **Reward policies** define global and per-STDP3-layer rewards.
|
|
255
|
+
- **Deviation policies** define per-feedback deviation signals over time.
|
|
256
|
+
- **Contract files** expose stable IDs for layers and feedback channels,
|
|
257
|
+
allowing policies to remain deterministic even when the graph evolves.
|
|
258
|
+
|
|
259
|
+
### Writing reward policies
|
|
260
|
+
|
|
261
|
+
Reward policies can return both a global reward and per-layer rewards:
|
|
262
|
+
|
|
263
|
+
```python
|
|
264
|
+
from policies._contract import STDP3_LAYERS
|
|
265
|
+
|
|
266
|
+
def compute_reward(summary, *, stdp_layers=STDP3_LAYERS):
|
|
267
|
+
global_reward = 0.5
|
|
268
|
+
by_layer = {layer_id: global_reward for layer_id in stdp_layers}
|
|
269
|
+
return global_reward, by_layer
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Writing deviation policies
|
|
273
|
+
|
|
274
|
+
Deviation policies emit deviations **per feedback input**:
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
from policies._contract import FEEDBACK_IDS
|
|
278
|
+
|
|
279
|
+
def compute_deviation(feedback_id, *, T, ctx=None):
|
|
280
|
+
if feedback_id == "fbP1":
|
|
281
|
+
return [0.0] * T
|
|
282
|
+
return [0.0] * T
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
The backend converts deviations into feedback rasters using the previous
|
|
286
|
+
cycle’s feedback as a baseline, making feedback deterministic and stateful
|
|
287
|
+
across cycles.
|
|
288
|
+
|
|
289
|
+
5. Optionally implement deviation and reward policies:
|
|
290
|
+
|
|
291
|
+
```python
|
|
292
|
+
from ab_sdk.plugins.deviation import DefaultDeviation
|
|
293
|
+
from ab_sdk.plugins.reward import DefaultReward
|
|
294
|
+
|
|
295
|
+
# attach default zero deviation policy
|
|
296
|
+
run.set_deviation(DefaultDeviation(run))
|
|
297
|
+
|
|
298
|
+
# attach a simple reward policy; this one returns a constant reward
|
|
299
|
+
run.set_reward(DefaultReward(run))
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Refer to the docstrings in each module for more detailed
|
|
303
|
+
documentation.
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
## Logging and error handling
|
|
307
|
+
|
|
308
|
+
The SDK uses Python's standard `logging` library. All modules
|
|
309
|
+
inherit the root logger's configuration, so you can control the log
|
|
310
|
+
level globally by configuring logging in your application:
|
|
311
|
+
|
|
312
|
+
```python
|
|
313
|
+
import logging
|
|
314
|
+
logging.basicConfig(level=logging.INFO)
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
During development you may wish to enable debug logging for a more
|
|
318
|
+
detailed view of the realtime messages being sent and received. To
|
|
319
|
+
do so set the level for the `ab_sdk` namespace:
|
|
320
|
+
|
|
321
|
+
```python
|
|
322
|
+
logging.getLogger('ab_sdk').setLevel(logging.DEBUG)
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
If the SDK encounters a problem (for example a provider returns
|
|
326
|
+
invalid data) it will log an error and continue running. Exceptions
|
|
327
|
+
raised by your callback code are logged with stack traces to aid in
|
|
328
|
+
debugging. When a deviation or reward plugin returns values outside
|
|
329
|
+
the allowed range the SDK will clamp them to safe defaults.
|
|
330
|
+
|
|
331
|
+
## License
|
|
332
|
+
ArtificialBrains SDK is source-available.
|
|
333
|
+
|
|
334
|
+
You may use it freely, including in commercial products.
|
|
335
|
+
You may not repackage it, host it as a service, or use it to build a
|
|
336
|
+
competing platform.
|
|
337
|
+
|
|
338
|
+
If you want to embed ArtificialBrains into a commercial system, you’re good.
|
|
339
|
+
If you want to clone ArtificialBrains, you’re not.
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
## Elastic License 2.0 (Modified)
|
|
343
|
+
|
|
344
|
+
Copyright (c) 2026 ArtificialBrains
|
|
345
|
+
|
|
346
|
+
Permission is hereby granted to use, copy, modify, and distribute this
|
|
347
|
+
software for commercial and non-commercial purposes, subject to the
|
|
348
|
+
limitations below.
|
|
349
|
+
|
|
350
|
+
You may:
|
|
351
|
+
- Use the software in production
|
|
352
|
+
- Build and sell commercial products that depend on it
|
|
353
|
+
- Modify the software for internal use
|
|
354
|
+
|
|
355
|
+
You may not:
|
|
356
|
+
- Provide the software as a hosted or managed service
|
|
357
|
+
- Repackage, resell, or sublicense the software itself
|
|
358
|
+
- Use the software to build or offer a competing platform
|
|
359
|
+
- Remove or obscure licensing or attribution notices
|
|
360
|
+
|
|
361
|
+
This license does not grant rights to use the ArtificialBrains name,
|
|
362
|
+
logo, or trademarks.
|
|
363
|
+
|
|
364
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
## Contributing
|
|
368
|
+
|
|
369
|
+
This SDK is a reference implementation. Please open issues or pull requests if you
|
|
370
|
+
find bugs or have suggestions.
|