Skip to main content

Tools for converting bluetooth data and packets

Project description

Bluetooth Data Tools

CI Status Documentation Status Test coverage percentage CodSpeed Badge

Poetry black pre-commit

PyPI Version Supported Python versions License

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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bluetooth_data_tools-1.29.13.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bluetooth_data_tools-1.29.13-cp314-cp314-manylinux_2_41_x86_64.whl (149.5 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.41+ x86-64

File details

Details for the file bluetooth_data_tools-1.29.13.tar.gz.

File metadata

  • Download URL: bluetooth_data_tools-1.29.13.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for bluetooth_data_tools-1.29.13.tar.gz
Algorithm Hash digest
SHA256 4f1e3d9c3b6285ae56480e0923a06736532a67bed9b205c681420e8bc1dde516
MD5 b8f9c55046f3fb4d17fd74266402b273
BLAKE2b-256 7787987380b4836167a79eef36791a2864d93fbe452fa86d73e7de4a5cf77cdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for bluetooth_data_tools-1.29.13.tar.gz:

Publisher: ci.yml on Bluetooth-Devices/bluetooth-data-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bluetooth_data_tools-1.29.13-cp314-cp314-manylinux_2_41_x86_64.whl.

File metadata

File hashes

Hashes for bluetooth_data_tools-1.29.13-cp314-cp314-manylinux_2_41_x86_64.whl
Algorithm Hash digest
SHA256 faa6878f7941efa95356097af5fe3bde31620abf2fc98308b9bb47c6cd390f8a
MD5 78cdc93717af013e0d05b6607e9c8304
BLAKE2b-256 4e02207ded504e7f2a2c089e3045199845f36956efd0daf32fb558e59fb7151f

See more details on using hashes here.

Provenance

The following attestation bundles were made for bluetooth_data_tools-1.29.13-cp314-cp314-manylinux_2_41_x86_64.whl:

Publisher: ci.yml on Bluetooth-Devices/bluetooth-data-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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