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 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).

You can 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

AWE_Polar_Project/
โ”œโ”€โ”€ 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.0.tar.gz (51.6 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.0-py3-none-any.whl (47.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polar_ble_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 51.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for polar_ble_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4b0242b272967e08c621a07ec97e9867a90db8a3e1e84c5ec1d83b64dcd1dab5
MD5 8fcceb88cf81b0e94d3b01aa2973a2a7
BLAKE2b-256 756bceec154e9d4266d48e019a1ba10b940a154540777cff384b9cb056431475

See more details on using hashes here.

File details

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

File metadata

  • Download URL: polar_ble_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 47.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for polar_ble_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b96e7faf6340f06e76e414f8ab2c5e4fcca87ddc3ade7583403ca4aefdc52163
MD5 afd13f0d42732365fc476b43bff6fd05
BLAKE2b-256 84e1591d7675c46b8f4b5cce1887733112e2c9eb596ab6c25fb810cfea508aa8

See more details on using hashes here.

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