> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nimbusbci.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK

> Overview of the nimbus-bci Python SDK: sklearn-compatible Bayesian classifiers with MNE integration for motor imagery, P300, and SSVEP.

# Python SDK

The **nimbus-bci** Python library provides sklearn-compatible Bayesian classifiers for Brain-Computer Interface applications. It delivers local probabilistic inference with uncertainty quantification, streaming support, and rich diagnostics. Optional extras add `NimbusSoftmax` via JAX (`pip install nimbus-bci[softmax]`) and pyRiemann feature pipelines (`pip install nimbus-bci[riemann]`).

## Start Here

<CardGroup cols={3}>
  <Card title="Install nimbus-bci" icon="download" href="/python-sdk/installation">
    Install and verify your Python SDK environment.
  </Card>

  <Card title="Run Quickstart" icon="rocket" href="/python-sdk/quickstart">
    Build your first Bayesian BCI classifier in minutes.
  </Card>

  <Card title="Pick a Model" icon="brain" href="/model-specification">
    Compare NimbusLDA, NimbusQDA, NimbusSoftmax, and NimbusSTS.
  </Card>
</CardGroup>

## Overview

`nimbus-bci` is a production-ready Python package available on PyPI that brings Bayesian inference to BCI applications with a familiar sklearn-compatible API.

```bash theme={null}
pip install nimbus-bci
```

<Note>
  **New in `nimbus-bci`:** `CalibrationSession` packages active-learning helpers into a first-class workflow, and `nimbus_bci.riemann.make_riemann_nimbus_pipeline(...)` composes pyRiemann covariance/tangent features with Nimbus heads. See [Active Learning](/python-sdk/active-learning) and [API Reference](/python-sdk/api-reference).
</Note>

## Key Features

<CardGroup cols={2}>
  <Card title="sklearn Compatible" icon="code">
    Drop-in replacement for sklearn classifiers. Works with pipelines, cross-validation, and GridSearchCV.
  </Card>

  <Card title="Streaming Inference" icon="activity">
    Real-time chunk-by-chunk processing for online BCI applications with weighted aggregation.
  </Card>

  <Card title="MNE Integration" icon="brain">
    Seamless integration with MNE-Python for EEG preprocessing and feature extraction.
  </Card>

  <Card title="Riemannian Features" icon="code">
    Optional pyRiemann covariance/tangent feature pipelines feeding existing Nimbus classifier heads.
  </Card>

  <Card title="Rich Diagnostics" icon="chart-line">
    Entropy, calibration metrics (ECE/MCE), ITR calculation, and quality assessment.
  </Card>

  <Card title="Online Learning" icon="graduation-cap">
    Update models incrementally with `partial_fit()` without retraining from scratch.
  </Card>

  <Card title="Active Learning" icon="target" href="/python-sdk/active-learning">
    Rank unlabeled trials, request labels only when useful, and stop calibration when the posterior stabilizes.
  </Card>

  <Card title="Fully Local" icon="lock">
    No API keys required. All processing happens on your machine for maximum privacy.
  </Card>
</CardGroup>

## Quick Example

```python theme={null}
from nimbus_bci import NimbusLDA
import numpy as np

# Create and fit classifier
clf = NimbusLDA()
clf.fit(X_train, y_train)

# Predict with uncertainty
predictions = clf.predict(X_test)
probabilities = clf.predict_proba(X_test)

# Works with sklearn pipelines
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

pipe = make_pipeline(StandardScaler(), NimbusLDA())
pipe.fit(X_train, y_train)
```

## Available Classifiers

The Python SDK provides four Bayesian classifiers:

| Classifier        | Description                                              | Best For                                     |
| ----------------- | -------------------------------------------------------- | -------------------------------------------- |
| **NimbusLDA**     | Bayesian LDA with shared covariance                      | Fast, well-separated classes (motor imagery) |
| **NimbusQDA**     | Bayesian QDA with class-specific covariances             | Complex distributions (P300)                 |
| **NimbusSoftmax** | Bayesian logistic regression (Polya-Gamma VI)            | Non-Gaussian decision boundaries             |
| **NimbusSTS**     | Bayesian Structural Time Series (Extended Kalman Filter) | Non-stationary data, long sessions           |

All classifiers provide:

* Full posterior distributions
* Uncertainty quantification
* Online learning via `partial_fit()`
* sklearn-compatible API

**Note**: NimbusSTS also includes state management methods (`propagate_state()`, `get_latent_state()`, `set_latent_state()`) for temporal adaptation.

## Python vs Julia SDK

Both SDKs implement the same Bayesian models but with different design philosophies:

| Feature          | Python SDK                                             | Julia SDK                        |
| ---------------- | ------------------------------------------------------ | -------------------------------- |
| **Installation** | `pip install nimbus-bci`                               | `Pkg.add("NimbusSDK")` + API key |
| **API Style**    | sklearn-compatible classes                             | Functional + types               |
| **Integration**  | sklearn pipelines, MNE-Python                          | RxInfer.jl ecosystem             |
| **Performance**  | Fast local Python implementation; optional JAX Softmax | Fastest (native Julia)           |
| **API Key**      | Not required                                           | Required                         |
| **Use Case**     | Production ML pipelines                                | Research, custom models          |
| **License**      | Proprietary (free evaluation)                          | Commercial tiers                 |

### When to Use Python SDK

Choose the Python SDK if you:

<br />

✅ Work primarily in Python<br />
✅ Use sklearn pipelines and MNE-Python<br />
✅ Want immediate installation without API keys<br />
✅ Need sklearn-compatible API for easy integration<br />
✅ Prefer fully local processing

### When to Use Julia SDK

Choose the Julia SDK if you:

<br />

✅ Need maximum performance (native Julia)<br />
✅ Want to build custom Bayesian models<br />
✅ Work with RxInfer.jl ecosystem<br />
✅ Need pre-trained model distribution<br />
✅ Require enterprise support

## Architecture

```
EEG Data → MNE-Python → nimbus-bci → Your Application
           (Preprocessing)  (Classification)  (Control/Analysis)
```

**Key Design Principles:**

* **Local Processing**: All computation happens on your machine
* **Privacy First**: Your EEG data never leaves your computer
* **sklearn Compatible**: Works with existing ML workflows
* **Fast Inference**: Efficient local inference, with optional JAX support for `NimbusSoftmax`
* **Uncertainty Aware**: Full Bayesian posterior distributions

## Use Cases

<CardGroup cols={2}>
  <Card title="Motor Imagery BCI" icon="hand">
    Control devices with imagined movements using CSP features and NimbusLDA
  </Card>

  <Card title="P300 Speller" icon="keyboard">
    Communication interfaces using ERP features and NimbusQDA
  </Card>

  <Card title="Real-time Neurofeedback" icon="activity">
    Streaming inference for live brain state monitoring
  </Card>

  <Card title="Research Pipelines" icon="flask-conical">
    sklearn-compatible API for reproducible BCI research
  </Card>
</CardGroup>

## What's Included

The `nimbus-bci` package provides:

**Classifiers:**

* `NimbusLDA` - Bayesian Linear Discriminant Analysis
* `NimbusQDA` - Bayesian Quadratic Discriminant Analysis
* `NimbusSoftmax` - Bayesian Multinomial Logistic Regression
* `NimbusSTS` - Bayesian Structural Time Series (Extended Kalman Filter)

**Data Structures:**

* `BCIData` - Container for features, metadata, labels
* `BCIMetadata` - Metadata for BCI experiments

**Inference:**

* `predict_batch()` - Batch inference with diagnostics
* `StreamingSession` - Real-time chunk processing

**Active Learning:**

* `CalibrationSession` - Manage pool-based calibration rounds and stopping snapshots
* `suggest_next_trial()` - Rank unlabeled feature pools by informativeness
* `should_query()` - Decide whether an arriving trial is worth labeling
* `calibration_sufficient()` - Stop calibration when the posterior stabilizes

**Metrics:**

* `compute_entropy()` - Prediction uncertainty
* `compute_calibration_metrics()` - ECE/MCE
* `calculate_itr()` - Information Transfer Rate
* `assess_trial_quality()` - Quality checks

**Utilities:**

* `estimate_normalization_params()` - Feature normalization
* `diagnose_preprocessing()` - Preprocessing diagnostics
* `compute_fisher_score()` - Feature discriminability

**MNE Integration:**

* `from_mne_epochs()` - Convert MNE Epochs to BCIData
* `extract_csp_features()` - CSP feature extraction
* `extract_bandpower_features()` - Bandpower features

**Optional Riemannian Features:**

* `make_riemann_nimbus_pipeline()` - Build an EEG-epoch pipeline from pyRiemann covariance/tangent transforms to a Nimbus classifier head

## Next Read

<CardGroup cols={2}>
  <Card title="Installation" icon="download" href="/python-sdk/installation">
    Install nimbus-bci and verify your setup
  </Card>

  <Card title="Quickstart" icon="rocket" href="/python-sdk/quickstart">
    Build your first BCI classifier in 5 minutes
  </Card>

  <Card title="API Reference" icon="book" href="/python-sdk/api-reference">
    Complete API documentation with examples
  </Card>

  <Card title="Active Learning" icon="target" href="/python-sdk/active-learning">
    Reduce calibration time with label-efficient trial selection
  </Card>

  <Card title="MNE Integration" icon="brain" href="/python-sdk/mne-integration">
    Use nimbus-bci with MNE-Python
  </Card>
</CardGroup>

## Support

Need help? We're here for you:

* **Email**: [hello@nimbusbci.com](mailto:hello@nimbusbci.com)
* **Documentation**: Browse our comprehensive guides
* **GitHub**: [github.com/nimbusbci/nimbuspysdk](https://github.com/nimbusbci/nimbuspysdk)
* **Examples**: Check out working code samples in the package

***

Ready to get started? Head to the [Installation Guide](/python-sdk/installation) to install nimbus-bci.

<script
  type="application/ld+json"
  dangerouslySetInnerHTML={{
__html: JSON.stringify({
  '@context': 'https://schema.org',
  '@type': 'TechArticle',
  headline: 'Python SDK',
  description:
    'Overview of the nimbus-bci Python SDK: sklearn-compatible Bayesian classifiers with MNE integration for motor imagery, P300, and SSVEP.',
  author: {
    '@type': 'Organization',
    name: 'Nimbus BCI',
    url: 'https://nimbusbci.com',
  },
  publisher: {
    '@type': 'Organization',
    name: 'Nimbus BCI',
    url: 'https://nimbusbci.com',
  },
  inLanguage: 'en-US',
  isAccessibleForFree: true,
  url: 'https://docs.nimbusbci.com/python-sdk/introduction',
}),
}}
/>
