Skip to main content

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)

The session talks to the device directly, whether or not Central is running on the same PC. Setting the environment variable CERELINK_CENTRAL_COMPAT=1 attaches to Central's shared memory instead while Central is running (without Central it has no effect); it is deprecated, prints a notice on stderr, and will be removed in the next major release.

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_sample_group(n, "FRONTEND", group_id) — configure sampling
  • session.set_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 running; works from any session, since the device echoes the commands to 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

Timestamp convention. A device timestamp lags the sample's true sampling instant by a fixed, device-dependent latency (measured against a PTP-locked reference edge; this is not a clock-sync error): about 1 sample period (~31 us at 30 kHz) on an NSP, about 1.3 sample periods (~44 us) on a Hub front end. Analog and digital samples in the same NSP frame share one stamp. Stamps are per-sample PTP times, not a fixed grid (the 30 kHz sample clock runs a few ppm off PTP), so do not reconstruct them as t0 + n / 30000.

device_to_monotonic(), device_to_monotonic_batch() (and the C++/C toLocalTime / cbsdk_session_to_local_time) subtract two corrections, so the result approximates the sampling instant:

  • Device latency, built in. A table of {device type, protocol version, latency} keyed by procinfo.version (readable as session.proc_version; Gemini firmware 7.8 reports 0x00040002 = protocol 4.2; 7.7 is 4.1, 7.9 will be 4.3): NSP 31 us; HUB1/HUB2/HUB3 44 us (identical hub hardware and firmware; measured HUB1 42.6, HUB2 43.7-44.8); other device types 0. The device reports no firmware release number, so releases sharing a protocol version share the entries; a version not in the table uses the device type's most recent entry and logs once that it is unverified. Override with Session(..., device_latency_ns=N) (C++ SdkConfig::device_latency_ns, C cbsdk_config_t.device_latency_ns; -1 = default); 0 disables it.
  • Host clock bias, per host, calibrated by you against a physical signal. The clock-probe offset makes host times late by a host-dependent amount (measured 40-140 us on macOS, ~0 on Linux). Set session.set_host_clock_bias_ns(N) (ns the host is late; C++ setHostClockBiasNs, C cbsdk_session_set_host_clock_bias_ns). It lives in shared memory: any process attached to the device (STANDALONE or CLIENT) can set it and every process applies it. Default 0; a launcher can set the initial value with env CBSDK_HOST_CLOCK_BIAS_NS before the device is opened. Not available (always 0) under Central-compatible layouts.

Raw timestamps (header.time) and clock_offset_ns are never modified. Filter delays (headstage, digital filters) are not compensated.

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.

Metadata

Release files for pycbsdk 10.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycbsdk 10.8.1
File Size Uploaded Provenance Actions
pycbsdk-10.8.1.tar.gz 108.3 kB With provenance Details for pycbsdk-10.8.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pycbsdk 10.8.1
File Actions
pycbsdk-10.8.1-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for pycbsdk-10.8.1-py3-none-win_amd64.whl
pycbsdk-10.8.1-py3-none-manylinux_2_39_x86_64.whl Python 3 none Linux glibc 2.39+ x86-64 Details for pycbsdk-10.8.1-py3-none-manylinux_2_39_x86_64.whl
pycbsdk-10.8.1-py3-none-manylinux_2_39_aarch64.whl Python 3 none Linux glibc 2.39+ ARM64 Details for pycbsdk-10.8.1-py3-none-manylinux_2_39_aarch64.whl
pycbsdk-10.8.1-py3-none-macosx_26_0_universal2.whl Python 3 none macOS 26.0+ universal2 (ARM64, x86-64) Details for pycbsdk-10.8.1-py3-none-macosx_26_0_universal2.whl

Total release size: 2.4 MB

Release files / pycbsdk-10.8.1.tar.gz

Download URL pycbsdk-10.8.1.tar.gz
Size 108.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d5d6b02cdec9be643e744c1594375342392cb429762b7d99054b86ecd8e70806
BLAKE2b-256 checksum
How to use checksums
585bf40349a6e5d1b810b6f467a0ab1e5e8a1892215e14c0cb79d0b05983ccf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / pycbsdk-10.8.1-py3-none-win_amd64.whl

Download URL pycbsdk-10.8.1-py3-none-win_amd64.whl
Size 368.2 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
cff258b3efd3ec61d8064648d0a7d6150a52cbae0907730243203559b9fc3e3c
BLAKE2b-256 checksum
How to use checksums
8646d3688f8217bbe68f824e35ca8d1897ca30a5e8f047c7d003ef896bf09428
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / pycbsdk-10.8.1-py3-none-manylinux_2_39_x86_64.whl

Download URL pycbsdk-10.8.1-py3-none-manylinux_2_39_x86_64.whl
Size 599.7 kB
Tags Linux glibc 2.39+ x86-64 Python 3
SHA-256 checksum
How to use checksums
b8563ffce76ce553ee2941d2fe6d8228fdb3813197f34a67bc2a5ba9e58c34e0
BLAKE2b-256 checksum
How to use checksums
5f274cb75e43fadf9a0be27ccbf6d343c9649b7101efe666d5972e8bd378a4d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / pycbsdk-10.8.1-py3-none-manylinux_2_39_aarch64.whl

Download URL pycbsdk-10.8.1-py3-none-manylinux_2_39_aarch64.whl
Size 528.0 kB
Tags Linux glibc 2.39+ ARM64 Python 3
SHA-256 checksum
How to use checksums
b8035ee0b5d1b142c8c705db34f41ad87f05692e3e183ebb7d8893f8cd877ee7
BLAKE2b-256 checksum
How to use checksums
c07950a978321602e6268bda4b225ecf08163382821737012e92967788bae377
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / pycbsdk-10.8.1-py3-none-macosx_26_0_universal2.whl

Download URL pycbsdk-10.8.1-py3-none-macosx_26_0_universal2.whl
Size 837.9 kB
Tags Python 3 macOS 26.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
353612ab16cbe5f56ca13bee1416977ac0a98073e61696f46bf4222c3ba0fc9b
BLAKE2b-256 checksum
How to use checksums
23432fbf9fa24cbed01a32c7f57177c6fca8e44a55b96127284921e4f1fb2503
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for pycbsdk 10.8.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for pycbsdk-10.8.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

10.8.1 This release

5 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page