Welcome to bluetooth-data-tools documentation!¶
Installation & Usage
Project Info
- CHANGELOG
- v1.28.2 (2025-07-02)
- v1.28.1 (2025-04-28)
- v1.28.0 (2025-04-27)
- v1.27.0 (2025-04-03)
- v1.26.5 (2025-04-02)
- v1.26.4 (2025-04-02)
- v1.26.3 (2025-04-02)
- v1.26.2 (2025-03-22)
- v1.26.1 (2025-03-15)
- v1.26.0 (2025-03-10)
- v1.25.1 (2025-03-05)
- v1.25.0 (2025-03-05)
- v1.24.1 (2025-03-05)
- v1.24.0 (2025-03-05)
- v1.23.4 (2025-02-04)
- v1.23.3 (2025-02-02)
- v1.23.2 (2025-02-02)
- v1.23.1 (2025-02-02)
- v1.23.0 (2025-02-02)
- v1.22.0 (2025-01-17)
- v1.21.0 (2025-01-17)
- v1.20.0 (2024-08-24)
- v1.19.4 (2024-07-29)
- v1.19.3 (2024-06-24)
- v1.19.2 (2024-06-24)
- v1.19.1 (2024-06-24)
- v1.19.0 (2023-12-21)
- v1.18.0 (2023-12-13)
- v1.17.0 (2023-12-03)
- v1.16.0 (2023-12-01)
- v1.15.0 (2023-11-24)
- v1.14.0 (2023-11-05)
- v1.13.0 (2023-10-18)
- v1.12.0 (2023-09-24)
- v1.11.0 (2023-09-01)
- v1.10.0 (2023-09-01)
- v1.9.1 (2023-08-27)
- v1.9.0 (2023-08-23)
- v1.8.0 (2023-08-10)
- v1.7.0 (2023-08-05)
- v1.6.1 (2023-07-24)
- v1.6.0 (2023-07-13)
- v1.5.0 (2023-07-13)
- v1.4.0 (2023-07-13)
- v1.3.0 (2023-06-29)
- v1.2.0 (2023-06-15)
- v1.1.0 (2023-06-14)
- v1.0.0 (2023-06-07)
- v0.4.0 (2023-04-15)
- v0.3.1 (2022-12-19)
- v0.3.0 (2022-11-13)
- v0.2.0 (2022-10-27)
- v0.1.2 (2022-08-13)
- v0.1.1 (2022-08-12)
- v0.1.0 (2022-08-12)
- Contributing
Bluetooth Data Tools¶
Tools for converting bluetooth data and packets
Installation¶
Install this via pip (or your favourite package manager):
pip install bluetooth-data-tools
Usage¶
Parsing BLE GAP Advertisement Data¶
Parse raw BLE advertisement bytes into structured data:
from bluetooth_data_tools import parse_advertisement_data_bytes
# Parse raw GAP advertisement bytes
parsed = parse_advertisement_data_bytes(raw_bytes)
local_name = parsed[0] # str | None
service_uuids = parsed[1] # list[str]
service_data = parsed[2] # dict[str, bytes]
manufacturer_data = parsed[3] # dict[int, bytes]
tx_power = parsed[4] # int | None
Or use the object-oriented interface:
from bluetooth_data_tools import BLEGAPAdvertisement, parse_advertisement_data
adv = parse_advertisement_data([raw_bytes1, raw_bytes2])
print(adv.local_name)
print(adv.service_uuids)
print(adv.service_data)
print(adv.manufacturer_data)
print(adv.tx_power)
Bluetooth Address Utilities¶
from bluetooth_data_tools import (
int_to_bluetooth_address,
mac_to_int,
short_address,
human_readable_name,
)
# Convert integer to MAC address
int_to_bluetooth_address(0x123456789ABC)
# "12:34:56:78:9A:BC"
# Convert MAC address to integer
mac_to_int("FF:FF:FF:FF:FF:FF")
# 281474976710655
# Get short address (last 2 octets)
short_address("AA:BB:CC:DD:EE:FF")
# "EEFF"
# Format a human-readable device name
human_readable_name("My Sensor", "", "AA:BB:CC:DD:EE:FF")
# "My Sensor (EEFF)"
Distance Estimation¶
Estimate distance from TX power and RSSI:
from bluetooth_data_tools import calculate_distance_meters
distance = calculate_distance_meters(power=-59, rssi=-60)
# ~1.135 meters
Monotonic Time¶
A fast monotonic clock optimized for Bluetooth event timing. On Linux, uses CLOCK_MONOTONIC_COARSE via Cython for lower overhead:
from bluetooth_data_tools import monotonic_time_coarse
now = monotonic_time_coarse()
Private Address Resolution (RPA)¶
Resolve Bluetooth Low Energy random private addresses using an Identity Resolving Key:
from bluetooth_data_tools import get_cipher_for_irk, resolve_private_address
cipher = get_cipher_for_irk(irk_bytes) # 16-byte Identity Resolving Key
is_match = resolve_private_address(cipher, "40:01:02:0A:C4:A6")
Contributors ✨¶
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
Credits¶
This package was created with Cookiecutter and the browniebroke/cookiecutter-pypackage project template.