Skip to main content

An open-source Python SDK for connecting, monitoring, and capturing raw physiological and IMU data from Polar BLE devices.

Project description

Polar BLE Python SDK

CI PyPI License: MIT Python Code style: black

An open-source Python SDK for connecting, monitoring, and capturing raw physiological and IMU data from Polar BLE devices (H10, Verity Sense, Vantage/Grit watches). The project offers real-time monitoring, machine-learning-based stress detection, a reactive Streamlit dashboard with live waveform charts, and a premium console terminal dashboard with event logging and hotkey markers.


๐Ÿš€ Quick Start

1. Installation & Setup

Requirements: Python 3.8+, Windows 10/11 (Bluetooth capable).

Option A: Package Install from PyPI (Recommended for Library Use)

You can install the core BLE SDK directly from PyPI:

pip install polar-ble-sdk

To install optional features (such as ML predictors or dashboards):

  • Install ML training and dependencies: pip install polar-ble-sdk[ml]
  • Install Streamlit dashboard dependencies: pip install polar-ble-sdk[dashboard]
  • Install all dependencies: pip install polar-ble-sdk[ml,dashboard]

Option B: Local Repository Install (Recommended for Dashboard/CLI Apps)

Run the automatic setup script in PowerShell to create the virtual environment and install all dependencies:

.\setup.ps1

(Alternatively, configure manually: python -m venv .venv, .\.venv\Scripts\Activate.ps1, pip install -r requirements.txt)

2. Streamlit Dashboard

Verify setup and launch the Streamlit dashboard using:

.\start.ps1

(Manual command: streamlit run src/polar_ble_sdk/app_streamlit.py)

3. Premium Terminal Dashboard

Launch the premium command-line dashboard with real-time event markers, battery monitoring, and 1 Hz CSV data logging:

.venv\Scripts\python.exe scripts\monitor_polar_terminal.py
  • Specify Device: Target a specific device (like a Vantage watch) by passing the name or MAC address:
    .venv\Scripts\python.exe scripts\monitor_polar_terminal.py --device Vantage
    
  • Hotkey Event Markers: Press SPACE (marker), S (stimulus_on), B (baseline_start), or R (rest_start) to log markers on-screen and save them directly in the CSV files under data/.

4. Dual-Device Terminal Dashboard

If you want to monitor both a Polar H10 chest strap and a Polar Verity Sense optical sensor side-by-side simultaneously:

.venv\Scripts\python.exe scripts\monitor_dual_polar.py
  • Optional Filters: Specify target devices:
    .venv\Scripts\python.exe scripts\monitor_dual_polar.py --h10 "H10 EA396220" --sense "Sense 11781835"
    
  • Separate Logging: Automatically saves independent, conflict-free CSV logs under data/ for each connected device.

๐Ÿ“Š Sensor Sampling Frequencies & CSV Logging

1. Device Capabilities (Maximum Sampling Rates)

Polar devices transmit sensor data at high frequencies via their PMD (Physical Measurement Device) service:

  • Polar H10:
    • ACC (Accelerometer): 25, 50, 100, 200 Hz (Resolution: 16-bit, Range: 2, 4, 8 G)
    • ECG (Electrocardiogram): 130 Hz (Resolution: 14-bit)
    • Heart Rate / RR-Intervals: Event-driven (per heartbeat, ~1 Hz)
  • Polar Verity Sense:
    • PPG (Photoplethysmography): 55 Hz (Resolution: 22-bit, Channels: 4)
    • ACC (Accelerometer): 52 Hz (Resolution: 16-bit, Range: 8 G, Channels: 3)
    • GYRO (Gyroscope): 52 Hz (Resolution: 16-bit, Range: 2000 dps, Channels: 3)
    • MAG (Magnetometer): 10, 20, 50, 100 Hz (Resolution: 16-bit, Range: 50 Gauss, Channels: 3)
    • HR / PPI (Pulse-to-Pulse / HRV): Event-driven (per pulse, ~1 Hz)
  • Polar Smartwatches (Grit X, Vantage, etc.):
    • PPG (Photoplethysmography): Natively configured up to 135 Hz (varies by model)
    • ACC / GYRO (Kinematics): Configurable up to 208 Hz (varies by model)

2. CSV Logging Rates & High-Frequency Option

  • Default 1 Hz Logging: By default, the terminal dashboards (monitor_polar_terminal.py and monitor_dual_polar.py) sample and record data to CSV at 1 Hz. This contains the latest values at each second boundary. This downsampling prevents the creation of extremely sparse CSV files that result from mixing different sampling rates (e.g. 200 Hz ACC vs 1 Hz HR).
  • High-Frequency Recording: To record data at the maximum native rate (e.g. capturing all 200 Hz accelerometer samples or all 130 Hz ECG samples), you should write samples to the CSV directly within the device callback functions (such as acc_callback_h10 or ppg_callback_sense) in the scripts. To prevent rate mismatch conflicts, it is recommended to write to separate stream-specific files (e.g., *_acc.csv, *_ppg.csv).

โœจ Key Features

  • Multi-Device Support: Captures raw physiological telemetry from the Polar H10 chest strap, Polar Verity Sense optical sensor, and Polar smartwatch line (Grit, Vantage).
  • High-Frequency Waveforms: Live streaming and rendering of ECG electrical signals (130Hz), PPG optical pulse waves (55Hz), and IMU kinematics (3-axis Accelerometer, Gyroscope, and Magnetometer).
  • Stress & HRV Analysis: Dynamic calculation of RMSSD from R-R intervals (heart rate variability) and optical PPI data feed.
  • Console Terminal Dashboard: Full-featured interactive terminal view with a heart rate trend sparkline graph, background battery status checking, active stream rate monitor, and live event marker logs.
  • Automated Logging: Saves session data periodically at 1 Hz directly to CSV files inside the data/ directory.

๐Ÿ“‚ Project Structure

Polar-Python-SDK/
โ”œโ”€โ”€ setup.ps1                  # PowerShell automatic environment setup
โ”œโ”€โ”€ start.ps1                  # PowerShell application launcher
โ”œโ”€โ”€ src/polar_ble_sdk/
โ”‚   โ”œโ”€โ”€ app_streamlit.py       # Main Streamlit Dashboard (tabbed waveforms & kinematics)
โ”‚   โ”œโ”€โ”€ connector/             # BLE Device connection and data streaming layer
โ”‚   โ”‚   โ””โ”€โ”€ stream/            # Specialized device modules (Base, H10, VeritySense, Watch)
โ”‚   โ”œโ”€โ”€ dashboard_utils.py     # Shared helpers (RMSSD, sparkline, battery, CSV logging)
โ”‚   โ”œโ”€โ”€ reader/                # Real-time data reading and ML stress inference logic
โ”‚   โ””โ”€โ”€ ml/                    # Machine learning package (sample_data, train_model)
โ”œโ”€โ”€ scripts/                   # Consolidated CLI Tools
โ”‚   โ”œโ”€โ”€ monitor_polar_terminal.py # Premium live console dashboard with logging & hotkeys
โ”‚   โ”œโ”€โ”€ connect_polar.py       # Simple streaming utility
โ”‚   โ”œโ”€โ”€ download_datasets.py   # Dataset setup helper
โ”‚   โ”œโ”€โ”€ replicate_tabnet_stress.py # TabNet model training pipeline
โ”‚   โ”œโ”€โ”€ scan_ble.py            # BLE device discovery scanner
โ”‚   โ”œโ”€โ”€ pair_watch.ps1         # Windows WinRT device pairing script
โ”‚   โ””โ”€โ”€ ...                    # Helper and setup utilities
โ”œโ”€โ”€ tests/                     # 83 verified unit tests (pytest)
โ”œโ”€โ”€ data/                      # Session log files and datasets
โ”œโ”€โ”€ models/                    # Pickled ML models and scalers
โ””โ”€โ”€ docs/                      # Project guides

๐Ÿงช Testing & Code Quality

The codebase includes comprehensive unit testing and static type checking.

# Run the complete unit test suite
pytest tests/ -v --cov=.

# Run static type analysis checks
mypy src/ scripts/

๐Ÿ“„ License & Credits

See the LICENSE file for details.
Built for Python 3.8+ natively on Windows 10/11 environments.

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

polar_ble_sdk-0.1.1.tar.gz (50.7 kB view details)

Uploaded Source

Built Distribution

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

polar_ble_sdk-0.1.1-py3-none-any.whl (47.5 kB view details)

Uploaded Python 3

File details

Details for the file polar_ble_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: polar_ble_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 50.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for polar_ble_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6f66e6e0db1d57a80cce0b33d7669c1bed3caa8ce3931fd49a753473e6fe20e6
MD5 3e33ce6c352bbc00ee6519da731a27cd
BLAKE2b-256 55751d36c73b52085f662ede3787b8fda952c76c6161e9fc4e21bf8a84938ff8

See more details on using hashes here.

Provenance

The following attestation bundles were made for polar_ble_sdk-0.1.1.tar.gz:

Publisher: publish.yml on PhelaPoscam/Polar-Python-SDK

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

File details

Details for the file polar_ble_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: polar_ble_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 47.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for polar_ble_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e4e33b34d48a4bc3979dd9b828e27a92e33617a018342ed0e6c12c12c1cbb61c
MD5 e2b9dd538f6fff4359970b09ba9c2346
BLAKE2b-256 7a92d6b815658aca916bb1897e5588f4ab4116409e18bd20a5ddb531de0816a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for polar_ble_sdk-0.1.1-py3-none-any.whl:

Publisher: publish.yml on PhelaPoscam/Polar-Python-SDK

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