Skip to main content

Bluetooth Classic

CI Status Documentation Status Test coverage percentage

Poetry ruff pre-commit

PyPI Version Supported Python versions License

Bluetooth Classic (BR/EDR) discovery, pairing, scans and RFCOMM serial connections on Linux.

Python has good libraries for Bluetooth Low Energy, such as Bleak, but none of them handle Bluetooth Classic devices: speakers, headphones, printers and serial adapters. This library fills that gap. It talks to BlueZ over D-Bus with dbus-fast, in your own asyncio event loop, without compiled extensions.

  • Discover nearby Classic devices, with their names, services and signal strength.
  • Pair with a built-in agent for devices without a screen or keyboard, and trust them.
  • Find a device: whether a device is on and discoverable, with a short Classic scan that never connects to it, so it does not wake a device that wakes when connected to.
  • Unpair a device, removing it from BlueZ.
  • Open a connection to one of a device's RFCOMM services, such as its serial port, made by aio-rfcomm through BlueZ's profile API.

It covers what a Classic device needs that the usual Python Bluetooth libraries do not, and nothing about any one kind of device. Method names follow bleak's where there is an equivalent.

A Bluetooth Classic device is reached in layers, and each operation here acts on one of them.

  • The device. It is found by a scan, then paired and trusted, which BlueZ remembers. BluetoothClassic works at this level: discover(), find_device_by_address(), pair(), trust(), unpair(). None of them connects to the device; a scan only listens.
  • The link. When anything needs to talk to the device, BlueZ connects a link to it (the device's connection). One link carries all the services in use on that device at once: an RFCOMM connection, audio, a keyboard. BlueZ owns it: it brings the link up when the first service needs it and takes it down a little after the last one is done. This library never connects or disconnects a device's link itself.
  • A service connection. A device offers services, each identified by a UUID, such as its Serial Port (1101). An RfcommConnection is a connection to one of them (in the RFCOMM specification, a data link connection to the service's channel; BlueZ finds the channel). It is opened and closed: opening it brings the link up if it is not up already, which may wake a device that wakes when connected to; closing it ends only this connection, and leaves the link, and any other services on it, to BlueZ.

What a service connection carries is a byte stream. Data arrives in chunks as the device sends it, with no message boundaries, so framing the bytes into a device's messages is the caller's job. A write is done once the bytes are on their way; the stream has no acknowledgement that the device read them.

Two more things follow from how connections are made:

  • One owner per process. aio-rfcomm allows one Bluetooth object in a process. This library opens it on first use and every caller shares it, so open connections through this library rather than opening aio-rfcomm directly. A device's service has at most one connection at a time.
  • Bytes on open. Some devices change state soon after a connection opens and only answer a request sent before then. Bytes given as write_on_open are sent from this library's own thread the moment the connection opens, however busy the application's event loop is.

Installation

Install this via pip (or your favourite package manager):

pip install bluetooth-classic

It needs Linux with BlueZ 5, and Python 3.11 or newer.

Usage

import asyncio

from bluetooth_classic import SERIAL_PORT, BluetoothClassic, RfcommConnection


async def main() -> None:
    async with BluetoothClassic() as bluetooth:
        for device in await bluetooth.discover(timeout=10):
            print(device.address, device.name, device.rssi)

        device = await bluetooth.pair("00:11:22:33:44:55")
        await bluetooth.trust(device.address)

        found = await bluetooth.find_device_by_address(device.address)
        print("on" if found else "off")

    # The device's Serial Port service, connected by BlueZ.
    async with RfcommConnection(
        "00:11:22:33:44:55", service=SERIAL_PORT, data_callback=print
    ) as connection:
        await connection.write(b"hello")


asyncio.run(main())

A Classic scan uses the same radio as Low Energy scanning and interrupts it while it runs. Keep scans short, and in an application that also scans for Low Energy devices, let one part of it decide when they run.

Contributing

See CONTRIBUTING.md.

Credits

The project layout and tooling follow the Bluetooth-Devices libraries, which were created with browniebroke/cookiecutter-pypackage.

Metadata

Release files for bluetooth-classic 0.9.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 bluetooth-classic 0.9.0
File Size Uploaded Provenance Actions
bluetooth_classic-0.9.0.tar.gz 25.4 kB With provenance Details for bluetooth_classic-0.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bluetooth-classic 0.9.0
File Interpreter ABI Platform Actions
bluetooth_classic-0.9.0-py3-none-any.whl Python 3 none any Details for bluetooth_classic-0.9.0-py3-none-any.whl

Total release size: 51.4 kB

Release files / bluetooth_classic-0.9.0.tar.gz

Download URL bluetooth_classic-0.9.0.tar.gz
Size 25.4 kB
Tags Source
SHA-256 checksum
How to use checksums
00a682e77d1ea624a0cdb71c9b0d4ecc00c7e6d02c5d569fa0f597be009f5e82
BLAKE2b-256 checksum
How to use checksums
fa4e8e30012417ae46bca35a27ff3ce8c7905392cf12863f9e9e494a2cb4755a
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 25, 2026.

Transparency log

Release files / bluetooth_classic-0.9.0-py3-none-any.whl

Download URL bluetooth_classic-0.9.0-py3-none-any.whl
Size 26.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
491ecc06564100098c858a16bc2cab49c1b2fa306d459de8777632fd25821525
BLAKE2b-256 checksum
How to use checksums
2ae696851c1f9561a424371ea9c363b6b280ab75528dd2fedded6a8275cbc6b4
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 25, 2026.

Transparency log

Security for bluetooth-classic 0.9.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bluetooth_classic-0.9.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 25, 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.

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