Bluetooth Data Tools

1.28.4 · active · verified Wed Apr 15

Bluetooth Data Tools is a Python library that provides utilities for converting Bluetooth data and packets. It's currently at version 1.28.4 and maintains an active release cadence, with frequent updates to address bugs and introduce features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse raw BLE advertisement data using `parse_advertisement_data_bytes` to extract common fields like local name, service UUIDs, service data, manufacturer data, and TX power. It also shows the object-oriented approach using `BLEGAPAdvertisement` and `parse_advertisement_data`.

from bluetooth_data_tools import parse_advertisement_data_bytes

# Example raw BLE advertisement bytes (replace with actual data)
# This example is illustrative; real data would come from a BLE scan.
# For a simple test, you could use data from a known device.
raw_advertisement_bytes = bytes([0x02, 0x01, 0x06, 0x11, 0x07, 0x21, 0x91, 0x74, 0x76, 0x05, 0x46, 0x87, 0xB6, 0x74, 0x0E, 0x8C, 0x51, 0x0B, 0x40, 0x90, 0xA0, 0x00, 0x0A, 0xFF, 0x4C, 0x00, 0x10, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])

parsed_data = parse_advertisement_data_bytes(raw_advertisement_bytes)

# The parsed_data is a tuple: (local_name, service_uuids, service_data, manufacturer_data, tx_power)
local_name, service_uuids, service_data, manufacturer_data, tx_power = parsed_data

print(f"Local Name: {local_name}")
print(f"Service UUIDs: {service_uuids}")
print(f"Service Data: {service_data}")
print(f"Manufacturer Data: {manufacturer_data}")
print(f"TX Power: {tx_power}")

# Using the object-oriented interface (requires a list of raw bytes, even if one)
from bluetooth_data_tools import BLEGAPAdvertisement, parse_advertisement_data
adv = parse_advertisement_data([raw_advertisement_bytes])

print(f"\nObject-oriented parsing:")
print(f"Local Name: {adv.local_name}")
print(f"Service UUIDs: {adv.service_uuids}")

view raw JSON →