SiFi Bridge Python
SiFi Bridge Python is a Python API for controlling SiFi Labs biosensor devices programmatically. Build custom applications, automate experiments, and integrate physiological data into your research workflow.
Features
- Object-Oriented API - Clean, Pythonic interface for device control
- Real-Time Data Streaming - Access sensor data as NumPy-compatible arrays
- Flexible Configuration - Control all sensor parameters programmatically
- Multiple Output Formats - Stream to CSV, LSL, TCP, or custom handlers
- Multi-Device Support - Manage multiple devices simultaneously
- Easy Integration - Works seamlessly with NumPy, Pandas, scikit-learn, and ML frameworks
Installation
Install via pip:
pip install sifi-bridge-py
Or from source:
git clone https://github.com/SiFiLabs/sifi-bridge-py.git
cd sifi-bridge-py
pip install -e .
See the Installation Guide for detailed instructions.
Quick Start
Connect to a device and stream ECG data in just a few lines:
import sifi_bridge_py as sbp
# Create bridge and connect
sb = sbp.SifiBridge()
sb.connect(sbp.DeviceType.BIOPOINT_V1_3)
# Configure ECG sensor
sb.configure_ecg(state=True, fs=500)
sb.start()
# Read 10 packets
for i in range(10):
packet = sb.get_ecg()
print(f"ECG data: {packet['data']['ecg'][:5]}...")
# Cleanup
sb.stop()
sb.disconnect()
See the Quick Start Guide for more examples.
Use Cases
Data Collection & Export
# Record data to CSV for 60 seconds
sb = sbp.SifiBridge(publishers="csv://./data/")
sb.connect()
sb.configure_sensors(ecg=True, emg=True, imu=True)
sb.start()
time.sleep(60)
sb.stop()
sb.disconnect()
Real-Time Analysis
# Process ECG in real-time
import numpy as np
sb = sbp.SifiBridge()
sb.connect()
sb.configure_ecg(state=True, fs=500)
sb.start()
while True:
packet = sb.get_ecg()
ecg_data = np.array(packet['data']['ecg'])
# Your analysis here
heart_rate = calculate_heart_rate(ecg_data)
print(f"HR: {heart_rate} bpm")
Lab Streaming Layer (LSL)
# Stream to LSL for integration with other tools
sb = sbp.SifiBridge(publishers="lsl://")
sb.connect()
sb.configure_sensors(ecg=True, emg=True)
sb.start()
# Data automatically streams to LSL
# Access from EEGLAB, OpenViBE, etc.
Machine Learning Integration
# Collect training data for ML
import pandas as pd
data_buffer = []
sb = sbp.SifiBridge()
sb.connect()
sb.configure_emg(state=True, fs=2000)
sb.start()
# Collect 1000 packets
for _ in range(1000):
packet = sb.get_emg()
data_buffer.append(packet['data']['emg'])
# Convert to DataFrame for ML
df = pd.DataFrame(data_buffer)
# Train your model...
Key Concepts
Device Connection
Connect to devices by type or specific address:
# Auto-connect to any BioPoint
sb.connect(sbp.DeviceType.BIOPOINT_V1_3)
# Connect by MAC address
sb.connect("AA:BB:CC:DD:EE:FF")
# List available devices first
devices = sb.list_devices(sbp.ListSources.BLE)
sb.connect(devices[0])
Sensor Configuration
Configure each sensor independently:
# ECG at 500 Hz
sb.configure_ecg(state=True, fs=500)
# EMG at 2000 Hz
sb.configure_emg(state=True, fs=2000)
# PPG with custom LED intensity
sb.configure_ppg(state=True, fs=100, led_intensity=200)
# IMU at 100 Hz
sb.configure_imu(state=True, fs=100)
Data Acquisition
Multiple ways to get data:
# Get any packet
packet = sb.get_data()
# Get specific sensor
ecg = sb.get_ecg()
emg = sb.get_emg()
imu = sb.get_imu()
ppg = sb.get_ppg()
# With timeout
packet = sb.get_data(timeout=1.0)
Device Commands
Control LEDs, motors, and feedback:
# LED control
sb.send_command(sbp.DeviceCommand.OPEN_LED_1)
sb.send_command(sbp.DeviceCommand.CLOSE_LED_1)
# Vibration motor
sb.send_command(sbp.DeviceCommand.START_MOTOR, intensity=5)
sb.send_command(sbp.DeviceCommand.STOP_MOTOR)
# Event markers
sb.send_command(sbp.DeviceCommand.EVENT_MARKER, marker=42)
Comparison with CLI
| Feature | Python API | CLI |
|---|---|---|
| Use Case | Custom applications, automation | Interactive exploration, quick data collection |
| Coding Required | Yes | No |
| Integration | Seamless with NumPy, Pandas, ML | Export to CSV, LSL, TCP |
| Flexibility | Full programmatic control | Command-based |
| Best For | Developers, researchers with coding | Researchers without coding, quick tests |
Both interfaces use the same underlying library and offer the same capabilities.
Support
- API Reference - Complete method documentation
- Email: support@sifilabs.com
- GitHub Issues: Report bugs