Skip to main content

bluebus for Python

Asyncio Bluetooth Low Energy for Linux: scan, connect, read, write and subscribe to GATT characteristics, run a GATT server with advertising (BLE peripheral) and pair with a pairing agent. It talks to the BlueZ daemon over D-Bus through the bluebus Rust crate; every I/O method is an async def-style awaitable.

pip install bluebus

One abi3 wheel per architecture (x86_64, aarch64) covers Python 3.9 and newer. No Python dependencies, no dbus-python, no GLib.

Quick start

import asyncio
import bluebus

async def main():
    session = await bluebus.Session.new()          # or: await bluebus.Session()
    adapter = await session.default_adapter()      # or: await session.adapter("hci1")
    await adapter.power_on()

    for d in await adapter.scan(timeout=5.0, transport="le"):
        print(d.address, d.name, d.rssi, d.manufacturer_data)

    device = await adapter.find_device(name="Sensor", timeout=10.0)
    async with device.connected(timeout=20.0):     # waits for service discovery
        battery: bytes = await device.read("2a19")
        print("battery", battery[0], "%")
        await device.write("2a06", b"\x01", response=True)
        async for value in device.notifications("2a37"):
            print("heart rate", value[1])
            break

asyncio.run(main())

Characteristics are addressed by UUID: "2a19", "0x2A19" or the full form "00002a19-0000-1000-8000-00805f9b34fb".

Scanning

# Collect for a while (devices sorted by address).
devices = await adapter.scan(timeout=5.0, name_prefix="Sensor", service_uuids=["180d"], min_rssi=-80)

# Or react to each advertisement as it arrives.
async for event in adapter.scan_stream(transport="le"):
    print(event.kind, event.device)          # kind: "found" | "updated"
    if event.device.name == "Sensor":
        break                                # discovery stops

# Explicit lifetime:
async with adapter.scan_stream(service_uuids=["180f"]) as events:
    first = await events.__anext__()

DeviceInfo has read-only attributes: address, address_type, name, alias, rssi, tx_power, uuids, manufacturer_data ({company_id: bytes}), service_data ({uuid: bytes}), connected, paired, trusted, services_resolved.

GATT client

device = adapter.device("AA:BB:CC:DD:EE:FF")   # no I/O, or: await adapter.find_device(...)
await device.connect(timeout=20.0)
for service in await device.services():
    for c in service.characteristics:
        print(service.uuid, c.uuid, c.flags, [d.uuid for d in c.descriptors])

value = await device.read("2a00")
await device.write("6e400002-b5a3-f393-e0a9-e50e24dcca9e", b"hi", response=False)
await device.read_descriptor("2a19", "2902")

async with device.notifications("2a37") as values:   # subscribed here
    await device.write("2a39", b"\x01")              # trigger something
    async for v in values:                           # in arrival order
        ...
await device.disconnect()

A notification stream ends when it is closed (aclose(), async with exit, break); several streams on one characteristic share one BlueZ subscription.

Peripheral (GATT server + advertising)

def on_write(value: bytes):          # may also be an `async def`
    print("written:", value)

peripheral = await (
    adapter.peripheral()
    .service(bluebus.Service("180f").characteristic(
        bluebus.Characteristic("2a19", read=True, notify=True, value=b"\x64")))
    .service(bluebus.Service("b1eb0000-0000-4000-8000-000000000001").characteristic(
        bluebus.Characteristic("b1eb0000-0000-4000-8000-000000000002",
                               write=True, on_write=on_write).descriptor("2901", b"control")))
    .advertise(bluebus.Advertisement(local_name="my-sensor", service_uuids=["180f"],
                                     manufacturer_data={0xFFFF: b"\x01\x02"}))
    .start()
)
await peripheral.notify("2a19", b"\x63")   # value + notification to subscribers
await peripheral.stop()                    # or: async with peripheral: ...

on_write callbacks run on the asyncio event loop that called start(), in the order the writes arrived. Coroutine callbacks are scheduled as tasks. A callback that raises is logged on the "bluebus" logger; BlueZ and the Rust runtime never wait for Python code.

Pairing

await session.set_agent("auto")            # accept "Just Works" / confirmations
await session.set_agent(passkey=123456)    # answer passkey (and PIN) requests
await device.pair()
await device.trust(True)
await session.remove_agent()

Errors

Exception Raised for Also a
bluebus.BluebusError base class of all errors Exception
bluebus.BluebusTimeout scan/connect/power waits TimeoutError
bluebus.NotFound unknown adapter, device, characteristic LookupError
bluebus.InvalidArgument bad UUID, MAC address, timeout, … ValueError
bluebus.DBusError BlueZ / D-Bus errors; .name is e.g. "org.bluez.Error.NotReady"

Awaitables can be cancelled (asyncio.wait_for, task cancellation); the Rust operation is dropped with them.

Compared to bleak

bleak is cross-platform (Windows, macOS, Linux, Android) and central-only. bluebus is Linux-only (BlueZ; tested with 5.72) and adds what bleak does not have on Linux:

  • a GATT server (peripheral role) with write callbacks and notifications, and LE advertising (local name, service UUIDs, manufacturer and service data, broadcast beacons);
  • a pairing agent (set_agent("auto"), set_agent(passkey=…));
  • scan filters applied on both sides (BlueZ discovery filter + local name/address/RSSI matching), find_device and scan_stream events.

The API shape is close to bleak's (async with, UUID strings, bytes values), so a Linux central ports over with few changes.

Requirements

  • Linux with BlueZ (bluetoothd) running and permission to use it on the system bus (desktop users have it; otherwise the bluetooth group).
  • DBUS_SYSTEM_BUS_ADDRESS is honoured, e.g. to point at a test bus.

Development

cd python
uv venv && uv pip install maturin pytest pytest-asyncio
maturin develop --uv
pytest -q tests          # against the mock BlueZ (needs dbus-daemon)
python examples/e2e.py hci1 hci2   # real BlueZ, two (virtual) controllers

The tests start examples/mock_bluez.rs (a mock org.bluez on a private dbus-daemon, shared with the Rust test suite); set BLUEBUS_MOCK to a prebuilt binary to skip cargo build.

License

MIT or Apache-2.0, like the bluebus crate.

Metadata

Release files for bluebus 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bluebus 0.1.0
File Size Uploaded Provenance Actions
bluebus-0.1.0.tar.gz 154.1 kB With provenance Details for bluebus-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for bluebus 0.1.0
File Interpreter ABI Platform Actions
bluebus-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for bluebus-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
bluebus-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for bluebus-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Total release size: 7.3 MB

Release files / bluebus-0.1.0.tar.gz

Download URL bluebus-0.1.0.tar.gz
Size 154.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8c1901866d4fb4b2219af7f3beb3a1fae0b31def11f6821ca7093ff304a195c6
BLAKE2b-256 checksum
How to use checksums
eec710c2959d33954b289d9a0dbf40fc4b2616e9852ca3cd7059b489fd360785
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / bluebus-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL bluebus-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 3.5 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
694a405ad6bd4b874fc4a9be3a763bb5929b1c68e20c1e4b7eb955fd7d2a8753
BLAKE2b-256 checksum
How to use checksums
5eb46660e48c20cf25f611b0689336ac7fc4346648d65d419761493ac273f3c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / bluebus-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL bluebus-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 3.6 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
7526f5d61a28b3bbba1f58928645aac52c51ae3aebc3d0d82db72b3431b2c8d0
BLAKE2b-256 checksum
How to use checksums
b3e1182d4ccda6782a33f371be76540700ec40eb7db707a56096820848322038
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for bluebus 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 3 files in this release have been uploaded with provenance metadata.

Select from 3 files

Attestation for bluebus-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

3 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page