polar-python


Namepolar-python JSON
Version 0.0.4 PyPI version JSON
download
home_pagehttps://github.com/zHElEARN/polar-python
Summarypolar-python is a Python library for connecting to Polar devices via Bluetooth Low Energy (BLE) using Bleak. It allows querying device capabilities (e.g., ECG, ACC, PPG), exploring configurable options, and streaming parsed data through callback functions.
upload_time2024-09-16 14:09:44
maintainerNone
docs_urlNone
authorZhe_Learn
requires_python>=3.6
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # polar-python

`polar-python` is a Python library designed for seamless integration with Polar devices using Bluetooth Low Energy (BLE) through the Bleak library. With `polar-python`, you can easily connect to Polar devices, query supported functionalities such as ECG, ACC, and PPG, explore configurable options and their possible values, and start data streaming to receive parsed binary data through callback functions.

## Features

-   **Connect to Polar Devices**: Use BLE to connect to Polar devices.
-   **Query Device Capabilities**: Discover supported functionalities like ECG, ACC, and PPG.
-   **Explore Configurable Options**: Query and set measurement settings for each feature.
-   **Stream Data**: Start data streaming and receive parsed binary data via callback functions.

## Installation

You can install `polar-python` from PyPI using pip:

```sh
pip install polar-python
```

## Usage

Below is an example of how to use `polar-python` to connect to a Polar device, query its features, set measurement settings, and start data streaming.

### Step 1: Import Libraries and Initialize Console

```python
import asyncio
from bleak import BleakScanner
from polar_python import PolarDevice, MeasurementSettings, SettingType, ECGData, ACCData
```

### Step 2: Define Data Callback Function

```python
def data_callback(data: Union[ECGData, ACCData]):
    """
    Callback function to handle incoming data from the Polar device.

    Args:
        data (Union[ECGData, ACCData]): The data received from the Polar device.
    """
```

### Step 3: Define Main Function to Connect to Polar Device

```python
async def main():
    """
    Main function to connect to a Polar device, query its features,
    set measurement settings, and start data streaming.
    """
    # Find the Polar H10 device
    device = await BleakScanner.find_device_by_filter(
        lambda bd, ad: bd.name and "Polar H10" in bd.name, timeout=5
    )
    if device is None:
        return
```

### Step 4: Connect to Polar Device and Query Features

```python
    # Establish connection to the Polar device
    async with PolarDevice(device, data_callback) as polar_device:
        # Query available features
        available_features = await polar_device.available_features()

        # Query and print stream settings for each feature
        for feature in available_features:
            settings = await polar_device.request_stream_settings(feature)
```

### Step 5: Define and Start Data Streams

```python
        # Define ECG measurement settings
        ecg_settings = MeasurementSettings(
            measurement_type="ECG",
            settings=[
                SettingType(type="SAMPLE_RATE", array_length=1, values=[130]),
                SettingType(type="RESOLUTION", array_length=1, values=[14]),
            ],
        )

        # Define ACC measurement settings
        acc_settings = MeasurementSettings(
            measurement_type="ACC",
            settings=[
                SettingType(type="SAMPLE_RATE", array_length=1, values=[25]),
                SettingType(type="RESOLUTION", array_length=1, values=[16]),
                SettingType(type="RANGE", array_length=1, values=[2]),
            ],
        )

        # Start data streams for ECG and ACC
        await polar_device.start_stream(ecg_settings)
        await polar_device.start_stream(acc_settings)

        # Keep the stream running for 120 seconds
        await asyncio.sleep(120)
```

### Step 6: Run the Main Function

```python
if __name__ == "__main__":
    asyncio.run(main())
```

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

## Acknowledgements

-   [Bleak](https://github.com/hbldh/bleak) - BLE library for Python.
-   [Rich](https://github.com/Textualize/rich) - Python library for rich text and beautiful formatting in the terminal.
-   [bleakheart](https://github.com/fsmeraldi/bleakheart) - For providing inspiration and valuable insights.
-   [Polar BLE SDK](https://github.com/polarofficial/polar-ble-sdk) - For providing official BLE SDK and documentation for Polar devices.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zHElEARN/polar-python",
    "name": "polar-python",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Zhe_Learn",
    "author_email": "personal@zhelearn.com",
    "download_url": "https://files.pythonhosted.org/packages/7e/8d/4f10dec415c03ce3dcec8d6ae4f3fab68ff7dd61300687ef161919c1bc6d/polar_python-0.0.4.tar.gz",
    "platform": null,
    "description": "# polar-python\n\n`polar-python` is a Python library designed for seamless integration with Polar devices using Bluetooth Low Energy (BLE) through the Bleak library. With `polar-python`, you can easily connect to Polar devices, query supported functionalities such as ECG, ACC, and PPG, explore configurable options and their possible values, and start data streaming to receive parsed binary data through callback functions.\n\n## Features\n\n-   **Connect to Polar Devices**: Use BLE to connect to Polar devices.\n-   **Query Device Capabilities**: Discover supported functionalities like ECG, ACC, and PPG.\n-   **Explore Configurable Options**: Query and set measurement settings for each feature.\n-   **Stream Data**: Start data streaming and receive parsed binary data via callback functions.\n\n## Installation\n\nYou can install `polar-python` from PyPI using pip:\n\n```sh\npip install polar-python\n```\n\n## Usage\n\nBelow is an example of how to use `polar-python` to connect to a Polar device, query its features, set measurement settings, and start data streaming.\n\n### Step 1: Import Libraries and Initialize Console\n\n```python\nimport asyncio\nfrom bleak import BleakScanner\nfrom polar_python import PolarDevice, MeasurementSettings, SettingType, ECGData, ACCData\n```\n\n### Step 2: Define Data Callback Function\n\n```python\ndef data_callback(data: Union[ECGData, ACCData]):\n    \"\"\"\n    Callback function to handle incoming data from the Polar device.\n\n    Args:\n        data (Union[ECGData, ACCData]): The data received from the Polar device.\n    \"\"\"\n```\n\n### Step 3: Define Main Function to Connect to Polar Device\n\n```python\nasync def main():\n    \"\"\"\n    Main function to connect to a Polar device, query its features,\n    set measurement settings, and start data streaming.\n    \"\"\"\n    # Find the Polar H10 device\n    device = await BleakScanner.find_device_by_filter(\n        lambda bd, ad: bd.name and \"Polar H10\" in bd.name, timeout=5\n    )\n    if device is None:\n        return\n```\n\n### Step 4: Connect to Polar Device and Query Features\n\n```python\n    # Establish connection to the Polar device\n    async with PolarDevice(device, data_callback) as polar_device:\n        # Query available features\n        available_features = await polar_device.available_features()\n\n        # Query and print stream settings for each feature\n        for feature in available_features:\n            settings = await polar_device.request_stream_settings(feature)\n```\n\n### Step 5: Define and Start Data Streams\n\n```python\n        # Define ECG measurement settings\n        ecg_settings = MeasurementSettings(\n            measurement_type=\"ECG\",\n            settings=[\n                SettingType(type=\"SAMPLE_RATE\", array_length=1, values=[130]),\n                SettingType(type=\"RESOLUTION\", array_length=1, values=[14]),\n            ],\n        )\n\n        # Define ACC measurement settings\n        acc_settings = MeasurementSettings(\n            measurement_type=\"ACC\",\n            settings=[\n                SettingType(type=\"SAMPLE_RATE\", array_length=1, values=[25]),\n                SettingType(type=\"RESOLUTION\", array_length=1, values=[16]),\n                SettingType(type=\"RANGE\", array_length=1, values=[2]),\n            ],\n        )\n\n        # Start data streams for ECG and ACC\n        await polar_device.start_stream(ecg_settings)\n        await polar_device.start_stream(acc_settings)\n\n        # Keep the stream running for 120 seconds\n        await asyncio.sleep(120)\n```\n\n### Step 6: Run the Main Function\n\n```python\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Acknowledgements\n\n-   [Bleak](https://github.com/hbldh/bleak) - BLE library for Python.\n-   [Rich](https://github.com/Textualize/rich) - Python library for rich text and beautiful formatting in the terminal.\n-   [bleakheart](https://github.com/fsmeraldi/bleakheart) - For providing inspiration and valuable insights.\n-   [Polar BLE SDK](https://github.com/polarofficial/polar-ble-sdk) - For providing official BLE SDK and documentation for Polar devices.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "polar-python is a Python library for connecting to Polar devices via Bluetooth Low Energy (BLE) using Bleak. It allows querying device capabilities (e.g., ECG, ACC, PPG), exploring configurable options, and streaming parsed data through callback functions.",
    "version": "0.0.4",
    "project_urls": {
        "Homepage": "https://github.com/zHElEARN/polar-python"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7fe60b3c19d03bfd21cbf16bd0656f449a2ba0fd16d481bf16ac72263e2a3a6d",
                "md5": "e8d9dda2203884548651bd64a95ba2ac",
                "sha256": "3ccbb636eb3866637b0b03e7092fcea6863a4f230dc7a7c260ed6b436d1c22c4"
            },
            "downloads": -1,
            "filename": "polar_python-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e8d9dda2203884548651bd64a95ba2ac",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 8627,
            "upload_time": "2024-09-16T14:09:43",
            "upload_time_iso_8601": "2024-09-16T14:09:43.279736Z",
            "url": "https://files.pythonhosted.org/packages/7f/e6/0b3c19d03bfd21cbf16bd0656f449a2ba0fd16d481bf16ac72263e2a3a6d/polar_python-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7e8d4f10dec415c03ce3dcec8d6ae4f3fab68ff7dd61300687ef161919c1bc6d",
                "md5": "bf079468a36d014bb83051ed134d1348",
                "sha256": "62d41584920ce717516a7fb26220d8384f9d9575dff1576a81aed7a6e72a6d7c"
            },
            "downloads": -1,
            "filename": "polar_python-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "bf079468a36d014bb83051ed134d1348",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 8774,
            "upload_time": "2024-09-16T14:09:44",
            "upload_time_iso_8601": "2024-09-16T14:09:44.265737Z",
            "url": "https://files.pythonhosted.org/packages/7e/8d/4f10dec415c03ce3dcec8d6ae4f3fab68ff7dd61300687ef161919c1bc6d/polar_python-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-16 14:09:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zHElEARN",
    "github_project": "polar-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "polar-python"
}
        
Elapsed time: 1.13371s