Headless Python client interfaces for BitChat bridges
Project description
python-bitchat-client
python-bitchat-client is a small, headless Python package for integrating with the
BitChat BLE mesh protocol. It comes with a basic sample client application, but it's
intended to be embedded and used by other tools.
It doesn't currently implement channel discovery.
What this package provides
- A minimal client interface (
BitChatClient) for:- starting/stopping BLE mesh connectivity
- joining a channel (defaults to
#mesh) - receiving inbound messages via callback
- sending text messages to the current channel
- receiving status telemetry (connected, disconnected, retries, errors)
- A BLE implementation (
BleBitChatClient) powered bybleak - A fallback no-op implementation (
NullBitChatClient) when BLE backend is not available - Protocol helpers for packet parsing/building
- Flood relay/rebroadcast with TTL decrement for transit packets
- Swappable dedupe cache (default exact LRU+TTL cache)
Installation
You can install this package from pypi using pip install python-bitchat-client
Basic usage
from python_bitchat_client import create_client
client = create_client()
client.set_handle("crystal-jim")
client.join_channel("#mesh")
def on_message(msg):
print(f"[{msg.channel}] <{msg.sender}> {msg.text}")
def on_status(status):
print(f"[{status.level}] {status.code}: {status.detail}")
client.set_message_handler(on_message)
client.set_status_handler(on_status)
client.start()
ok = client.send_message("@crystal-jim say hello from python")
print("sent:", ok)
Relay and dedupe behavior
- Inbound packets with
ttl > 1may be relayed withttl - 1. - Relay suppression uses a dedupe key of
sender_id + timestamp + message_type. - Default dedupe is an exact in-memory LRU cache with TTL expiry (no false positives).
You can inject your own dedupe cache at construction time. If omitted, a default
LruTtlDedupeCache instance is created.
from python_bitchat_client.client import create_client
class BloomLikeCache:
def is_duplicate(self, key: str) -> bool:
...
def mark_seen(self, key: str) -> None:
...
client = create_client(dedupe_cache=BloomLikeCache())
Note: probabilistic dedupe caches (for example Bloom filters) can produce false positives and may suppress legitimate relays.
Interactive test harness
A simple terminal harness is included for manual send/receive testing.
Path:
examples/terminal_harness.py
Run from repository root:
uv run python examples/terminal_harness.py --handle my-handle --channel "#mesh"
# Verbose packet/transport debugging
uv run python examples/terminal_harness.py --handle my-handle --channel "#mesh" --log-level DEBUG
Harness commands:
- Type any line and press Enter to send it to the channel
/quitor/exitto stop/helpto print command help--log-level DEBUGto include package debug logs
Inbound channel messages are printed to stdout while the prompt remains active.
Runtime notes and permissions
- This package does not require running your whole app as root.
- BLE access depends on host Bluetooth policy.
- On Linux, you typically need:
bluetoothdrunning- user permission to access BlueZ over D-Bus
- distro-specific group/polkit setup
If no peer is found, the client reports status code no_peer_found and keeps retrying.
Status telemetry
Common status codes emitted by the BLE client:
startingpeer_foundconnecteddisconnectedno_peer_foundconnect_failedsend_failedstoppedbackend_unavailable(fallback client)
Development
Run package-related tests from repository root:
uv run pytest tests/test_python_bitchat_client_protocol.py tests/test_python_bitchat_client_client.py
Set up pre-commit hooks:
uvx pre-commit install
uvx pre-commit run --all-files
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 python_bitchat_client-0.2.0.tar.gz.
File metadata
- Download URL: python_bitchat_client-0.2.0.tar.gz
- Upload date:
- Size: 78.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c89c57036bde32b47157f87926bf26e3de766af10120cf921a3d1435f8e3da4d
|
|
| MD5 |
b3691fbb33cb592afe24c5439a68f9fd
|
|
| BLAKE2b-256 |
6985e5bb14f2d3b861883d2b5341cc252a8927f8257851b7fe6292d3842a479f
|
File details
Details for the file python_bitchat_client-0.2.0-py3-none-any.whl.
File metadata
- Download URL: python_bitchat_client-0.2.0-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e1e897b75dcecff4541bc9b3c12e89acbcda5bd83bb7e5b2cb6f77a13445d13
|
|
| MD5 |
5faf53a17a3a7053272957cf0ffcb885
|
|
| BLAKE2b-256 |
95988ff53832af07dfe46a0d23206ca292e0edc66b5478b9ca13f43f2f33abc7
|