Discovering Bluetooth devices in Python with M1 MacBook

1.1k Views Asked by At

Is there any way to discover nearby Bluetooth devices using Python on macOS running on the newer Apple Silicon?

I tried Pybluez, but lightblue, one of its dependencies, doesn't seem to be supported.

1

There are 1 best solutions below

0
Netanel Bollag On

You can use bleak, it works for me on M1 macOS Ventura

Just make sure you have the necessary permissions to access Bluetooth from your terminal app (iTerm, for example), I spent really annoying 15 minutes on this error. go to "System Preferences" > "Privacy & Security" > "Bluetooth" and enable access for your terminal application.

Install bleak using pip:

pip install bleak

Here's a short example that demonstrates how to discover nearby Bluetooth devices:

import asyncio
from bleak import BleakScanner

async def discover_devices():
    devices = await BleakScanner.discover()
    for device in devices:
        print(f"Device: {device.name}, Address: {device.address}")

asyncio.run(discover_devices())

Learn more at Bleak official documentation. Happy Bluetoothing!