A small BLE GATT transport for framed JSON and binary messages between Python desktops and Android devices.
Project description
BLE Message Bridge
BLE Message Bridge is a small transport layer for sending framed JSON and binary payloads over Bluetooth Low Energy GATT.
It is useful when you want a desktop Python app to talk to an Android device over BLE without rewriting the same plumbing every time:
- split large payloads into BLE-sized packets;
- reassemble packets on the other side;
- gzip larger JSON/text payloads;
- send compact binary ping/pong heartbeats;
- reconnect with jittered backoff;
- use one write characteristic and one notify characteristic for duplex messages.
This library started as the reusable BLE transport extracted from a desktop-to-Android app. The public package is intentionally app-agnostic: it does not know about chat, AI models, prompts, screenshots, or any product-specific message schema.
Install
pip install ble-message-bridge
Quick Start
import asyncio
from ble_message_bridge import BleBridgeClient
def on_event(event: dict) -> None:
print(event)
async def main() -> None:
async with BleBridgeClient(event_sink=on_event) as client:
devices = await client.scan()
if not devices:
raise SystemExit("No bridge devices found")
await client.connect(devices[0].address)
await client.send_json({"type": "hello", "text": "ciao"})
await asyncio.sleep(3)
asyncio.run(main())
Custom UUIDs
The defaults are stable UUIDs from the reference Android bridge. For your own app, create your own service and characteristic UUIDs:
from ble_message_bridge import BleBridgeClient, BleBridgeConfig
config = BleBridgeConfig(
service_uuid="00000000-0000-0000-0000-000000000001",
write_char_uuid="00000000-0000-0000-0000-000000000002",
notify_char_uuid="00000000-0000-0000-0000-000000000003",
)
client = BleBridgeClient(config=config)
Events
BleBridgeClient reports everything through an optional event sink:
def on_event(event: dict) -> None:
match event["type"]:
case "json":
print("message", event["message"])
case "payload":
print("bytes", event["payload"])
case "link_quality":
print("rtt", event.get("rtt_ms"))
Common event types:
scan_resultconnecteddisconnectedsenttransfer_progressjsonpayloadbundlelink_qualitylink_statuserror
Android
This repo includes reference Kotlin sources in android/ for an Android BLE peripheral/server that speaks the same framing protocol.
The Android side is not published to Maven yet. For now, copy the small reference classes into your app module, or use them as the basis for your own BLE service.
See docs/android.md.
Protocol
The packet format is intentionally small:
[version:1][transport_id:2][chunk_index:2][chunk_total:2][payload:n]
All integers are big-endian. Payloads larger than one BLE write/notification are split into multiple frames with the same transport_id.
See docs/protocol.md.
Status
0.1.x is alpha. The framing format is simple and tested, but the public API may still evolve while real projects try it.
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ble_message_bridge-0.1.0.tar.gz.
File metadata
- Download URL: ble_message_bridge-0.1.0.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2d8380c751b6d54cbe886cdac17d5d6d200e1ade4f369935d3ae25c3fcaabd8
|
|
| MD5 |
ed68ae19f91b6301da1a49cc44b1533e
|
|
| BLAKE2b-256 |
22c9d9d4076d17c9043f19298ffc760f6d87f28dba7a372287a52c27c91b928b
|
Provenance
The following attestation bundles were made for ble_message_bridge-0.1.0.tar.gz:
Publisher:
publish.yml on MN-company/ble-message-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ble_message_bridge-0.1.0.tar.gz -
Subject digest:
a2d8380c751b6d54cbe886cdac17d5d6d200e1ade4f369935d3ae25c3fcaabd8 - Sigstore transparency entry: 1392783630
- Sigstore integration time:
-
Permalink:
MN-company/ble-message-bridge@79ec9491a2400e22352d5345aa40e9a54b99c33b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/MN-company
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@79ec9491a2400e22352d5345aa40e9a54b99c33b -
Trigger Event:
release
-
Statement type:
File details
Details for the file ble_message_bridge-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ble_message_bridge-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
983b74af627d67dbf5a6d3d5da57141538afdf0b1d0a3cd0477e936d362a9f79
|
|
| MD5 |
97131e72fa1be10dc463b13ab8121548
|
|
| BLAKE2b-256 |
c5d2746453efaec1b945845f7188826677aad2eb38f3b092df5ec544bf1a26f2
|
Provenance
The following attestation bundles were made for ble_message_bridge-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on MN-company/ble-message-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ble_message_bridge-0.1.0-py3-none-any.whl -
Subject digest:
983b74af627d67dbf5a6d3d5da57141538afdf0b1d0a3cd0477e936d362a9f79 - Sigstore transparency entry: 1392783633
- Sigstore integration time:
-
Permalink:
MN-company/ble-message-bridge@79ec9491a2400e22352d5345aa40e9a54b99c33b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/MN-company
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@79ec9491a2400e22352d5345aa40e9a54b99c33b -
Trigger Event:
release
-
Statement type: