Skip to main content

Python bindings for CereLink SDK (Blackrock Neurotech Cerebus devices)

Project description

pycbsdk

PyPI version

Python bindings for the CereLink SDK, providing real-time access to Blackrock Neurotech Cerebus neural signal processors.

Built on cffi (ABI mode) — no compiler needed at install time.

Installation

pip install pycbsdk

# With numpy support (zero-copy array access for continuous data)
pip install pycbsdk[numpy]

Windows prerequisite: The bundled shared library requires the Microsoft Visual C++ Redistributable. Most Windows systems already have it installed. If you get a DLL load error, download it from Microsoft.

Quick Start

from pycbsdk import Session
import time

with Session("HUB1") as session:
    # Register a callback for spike events
    @session.on_event("FRONTEND")
    def on_spike(header, data):
        print(f"Spike on channel {header.chid} at t={header.time}")

    # Register a callback for 30kHz continuous data
    @session.on_group(5, as_array=True)
    def on_continuous(header, samples):
        # samples is a numpy int16 array of shape (n_channels,)
        print(f"Group packet: {len(samples)} channels")

    time.sleep(10)
    print(session.stats)

Features

  • Callback-driven: decorator-based registration for event, group, config, and catch-all packet callbacks
  • Context manager: automatic cleanup on exit
  • numpy integration (optional): zero-copy arrays for continuous data, ring buffer accumulator, blocking read_continuous() collector
  • Device support: LEGACY_NSP, NSP, HUB1, HUB2, HUB3, NPLAY

API Overview

Session

session = Session(device_type="HUB1", callback_queue_depth=16384)

Callbacks (decorator style):

Decorator Description
@session.on_event("FRONTEND") Spike / event packets for a channel type
@session.on_group(5) Continuous sample group (1-6)
@session.on_group(5, as_array=True) Same, but data as numpy array
@session.on_config(pkt_type) Config / system packets
@session.on_packet() All packets (catch-all)
session.on_error(fn) Error messages

Configuration access:

  • session.get_channel_label(chan_id) — channel label string
  • session.get_channel_smpgroup(chan_id) — channel's sample group (0-6)
  • session.get_group_channels(group_id) — list of channel IDs in a group
  • session.runlevel — current device run level
  • Session.max_chans(), Session.num_fe_chans(), Session.num_analog_chans()

Commands:

  • session.send_comment("marker text", rgba=0xFF0000) — inject a comment
  • session.set_digital_output(chan_id, value) — set digital output
  • session.set_runlevel(level) — change system run level
  • session.set_channel_sample_group(n, "FRONTEND", group_id) — configure sampling
  • session.set_channel_spike_sorting(n, "FRONTEND", sort_options) — configure spike sorting

CCF Configuration Files:

  • session.save_ccf("config.ccf") — save current device config to XML file
  • session.load_ccf("config.ccf") — load config from file and apply to device

Recording Control (requires Central):

  • session.start_central_recording("filename", comment="session 1") — start recording
  • session.stop_central_recording() — stop recording

Clock Synchronization:

# Convert device timestamp to Python's time.monotonic()
@session.on_event("FRONTEND")
def on_spike(header, data):
    t = session.device_to_monotonic(header.time)
    latency_ms = (time.monotonic() - t) * 1000
    print(f"Spike latency: {latency_ms:.1f} ms")
  • session.device_to_monotonic(device_time_ns) — convert device timestamp to time.monotonic() seconds
  • session.clock_offset_ns — raw clock offset (device_ns - steady_clock_ns), or None
  • session.clock_uncertainty_ns — uncertainty (half-RTT), or None
  • session.send_clock_probe() — send a sync probe

Statistics:

stats = session.stats  # Stats dataclass
print(stats.packets_received, stats.packets_dropped)
session.reset_stats()

numpy Integration

Requires pip install pycbsdk[numpy].

# Blocking data collection
data = session.read_continuous(group_id=5, duration=2.0)
# data.shape == (n_channels, ~60000), dtype int16

# Ring buffer for ongoing collection
reader = session.continuous_reader(group_id=5, buffer_seconds=10)
import time; time.sleep(5)
data = reader.read()        # most recent samples
data = reader.read(1000)    # last 1000 samples
print(reader.total_samples, reader.dropped)
reader.close()

Supported Devices

Device Type Description
LEGACY_NSP Legacy NSP (default)
NSP NSP
HUB1 Gemini Hub 1
HUB2 Gemini Hub 2
HUB3 Gemini Hub 3
NPLAY nPlay

Development

# Build the shared library
cmake -S . -B build -DCBSDK_BUILD_SHARED=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build --target cbsdk_shared --config Release

# Install pycbsdk in development mode
cd pycbsdk
pip install -e ".[dev,numpy]"

# Point to the shared library
export CBSDK_LIB_PATH=/path/to/libcbsdk.dll  # or .so / .dylib

License

BSD 2-Clause. See LICENSE.txt.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycbsdk-9.3.0.tar.gz (38.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pycbsdk-9.3.0-py3-none-win_amd64.whl (244.2 kB view details)

Uploaded Python 3Windows x86-64

pycbsdk-9.3.0-py3-none-manylinux_2_38_x86_64.whl (978.8 kB view details)

Uploaded Python 3manylinux: glibc 2.38+ x86-64

pycbsdk-9.3.0-py3-none-macosx_15_0_universal2.whl (594.4 kB view details)

Uploaded Python 3macOS 15.0+ universal2 (ARM64, x86-64)

File details

Details for the file pycbsdk-9.3.0.tar.gz.

File metadata

  • Download URL: pycbsdk-9.3.0.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycbsdk-9.3.0.tar.gz
Algorithm Hash digest
SHA256 b6521ddfc8f70186ee4208775ce8a90bc0169f9c88ad4b90c01adfd91638bd20
MD5 d65be7b6608772d003fe85290e433ec5
BLAKE2b-256 ee59b1207f824e015e5a53b00fbfe66e3b73e6cc378c2e78eb3eb54641ff08cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycbsdk-9.3.0.tar.gz:

Publisher: build_pycbsdk.yml on CerebusOSS/CereLink

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycbsdk-9.3.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: pycbsdk-9.3.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 244.2 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycbsdk-9.3.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 9e5f9087bc765b61d97eba2e84a1d568b8988c6eba328c88009246de39ac3a61
MD5 ea15d6b528848785101e481df1c8800a
BLAKE2b-256 e01249f0ea60fc1b53fc3e5b6f1cf6b1dbe6d85062fc01ba6e5d1d34717138fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycbsdk-9.3.0-py3-none-win_amd64.whl:

Publisher: build_pycbsdk.yml on CerebusOSS/CereLink

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycbsdk-9.3.0-py3-none-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for pycbsdk-9.3.0-py3-none-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 1f2d5395b39e11ddf5b0e7c5468a0bdd298b641d2467ede11eb7b89ce5921b70
MD5 aa131927c48c64668ff1bcc819b1d3b7
BLAKE2b-256 c0512ddc695d2f20390a1767de56c0f3f5cc782fbba38fd37bd8b267a874d4f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycbsdk-9.3.0-py3-none-manylinux_2_38_x86_64.whl:

Publisher: build_pycbsdk.yml on CerebusOSS/CereLink

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycbsdk-9.3.0-py3-none-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for pycbsdk-9.3.0-py3-none-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 e9b7bbdf6a33c1603e0f0572c2df0c2ce9b859d8c393bc3e4cdd5c0f3e40179a
MD5 e4d0fc16ee2d2cad62fe6f900227d772
BLAKE2b-256 596b1e8e2157708b5ca802d72d7febeac0d598a5ead174eff083d81314b0dd12

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycbsdk-9.3.0-py3-none-macosx_15_0_universal2.whl:

Publisher: build_pycbsdk.yml on CerebusOSS/CereLink

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page