Metadata-Version: 2.5
Name: gatt-link-ble
Version: 0.7.1
Summary: Async BLE GATT discovery, parsing, and state updates.
Project-URL: Homepage, https://github.com/infoyouth/gatt-link-ble
Project-URL: Repository, https://github.com/infoyouth/gatt-link-ble
Project-URL: Issues, https://github.com/infoyouth/gatt-link-ble/issues
Author: infoyouth
License-Expression: MIT
License-File: LICENSE
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Home Automation
Requires-Python: <3.16,>=3.14.2
Requires-Dist: bleak-retry-connector>=4.7.0
Requires-Dist: bleak>=3.0.2
Description-Content-Type: text/markdown

# GATT Link BLE

[![CI](https://github.com/infoyouth/gatt-link-ble/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/infoyouth/gatt-link-ble/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/gatt-link-ble)](https://pypi.org/project/gatt-link-ble/)
[![License](https://img.shields.io/pypi/l/gatt-link-ble)](https://github.com/infoyouth/gatt-link-ble/blob/main/LICENSE)

**Connect to BLE GATT devices. Start with raw data. Add structure only when
you need it.**

GATT Link BLE is a lightweight Python library for discovering, connecting to,
and interacting with Bluetooth Low Energy devices. Use generic GATT services
and characteristics directly, or add device-specific profiles and parsers
when you need structured data. Unknown devices do not need predefined profiles;
device-specific interpretation stays separate from the generic client.

## Features

- Discover GATT services, characteristics, and their properties.
- Read and write raw characteristic values.
- Receive raw notifications and indications.
- Choose PUSH connections or POLL_AND_DISCONNECT reads.
- Reconnect after unexpected disconnects and restore eligible subscriptions.
- Add optional device profiles and parsers through public registration APIs.
- Inspect connection and characteristic diagnostics.
- Python `>=3.14.2,<3.16`; built on Bleak.

## Install

```shell
python -m pip install gatt-link-ble
```

## Quick start

This example scans for a device, connects, lists its GATT services, and reads
the first characteristic that advertises the `read` property.

```python
import asyncio

from bleak import BleakScanner
from gatt_link_ble import ConnectionMode, GattLinkClient


async def main() -> None:
    address = input("BLE address: ")
    device = await BleakScanner.find_device_by_address(address, timeout=10)
    if device is None:
        raise RuntimeError(f"No BLE device found at {address}")

    client = GattLinkClient(device, mode=ConnectionMode.PUSH)
    try:
        await client.start()
        snapshot = await client.discover()
        for service in snapshot.services:
            print(f"Service {service.uuid}")
            for characteristic in service.characteristics:
                print(f"  {characteristic.uuid}: {sorted(characteristic.properties)}")

        readable = next(
            (
                characteristic
                for service in snapshot.services
                for characteristic in service.characteristics
                if "read" in characteristic.properties
            ),
            None,
        )
        if readable is not None:
            value = await client.read_characteristic(readable.uuid)
            print(f"Raw value: {value.hex(' ')}")
    finally:
        await client.stop()


asyncio.run(main())
```

## Unknown BLE devices

**No predefined profile? No problem.**

Discover services and characteristics, inspect their properties, read or write
raw values, and subscribe to notifications without registering a profile or
parser. Unknown payloads remain accessible; the library does not guess their
meaning, units, or data types.

## Profiles and parsers

Profiles describe a device identity and its expected service/characteristic
signature. Parsers interpret payloads for known characteristics. Register them
independently with `register_gatt_profile` and `register_gatt_parser`; neither
is required for generic GATT access.

## Devices and validation

| Device | Status |
| --- | --- |
| Nordic Thingy:52 | Hardware-validated reference profile, with recorded-payload regression tests. |
| Other BLE devices | Generic GATT access (adapter/device dependent); no device-specific hardware validation. |

## Development

- [Live scanner](scripts/live_scan.py) lists nearby devices and can inspect raw readable values.
- [Tests](tests/) use mocked BLE clients; they do not require hardware.
- [Issues and bug reports](https://github.com/infoyouth/gatt-link-ble/issues)

Run the test suite with `uv sync --locked --all-groups && uv run pytest`.
