Bluetooth Adapters
bluetooth-adapters is a Python library that provides tools to enumerate and find Bluetooth adapters on various operating systems. It is currently at version 2.1.1 and receives regular updates, typically every few months, addressing bugs and dependency updates.
Warnings
- breaking Major versions of the underlying `bleak` library (e.g., 2.x, 3.x) can introduce breaking changes in behavior or API. `bluetooth-adapters` version 2.1.1 explicitly supports `bleak` 1.x. Users integrating with newer `bleak` versions might encounter compatibility issues or require an updated `bluetooth-adapters` release.
- gotcha On Linux, `bluetooth-adapters` relies on the BlueZ service and D-Bus. Issues can arise if D-Bus is not running, if the BlueZ service is not active, or due to incorrect D-Bus permissions, leading to adapter enumeration failures or communication problems.
- gotcha Bluetooth performance (range, stability, audio quality) can be significantly impacted by electromagnetic interference, particularly from USB 3.0 ports. Plugging a Bluetooth adapter into a USB 3.0 port can cause poor signal quality due to interference in the 2.4GHz band.
- deprecated Versions of `bluetooth-adapters` prior to 2.1.0 had a bug that could prevent D-Bus connections from being properly closed, potentially leading to resource leaks or stale connections over time.
Install
-
pip install bluetooth-adapters
Imports
- get_adapter_manager
from bluetooth_adapters import get_adapter_manager
Quickstart
import asyncio
from bluetooth_adapters import get_adapter_manager
async def main():
manager = await get_adapter_manager()
adapters = await manager.adapters()
if not adapters:
print("No Bluetooth adapters found.")
return
print(f"Found {len(adapters)} Bluetooth adapter(s):")
for adapter in adapters:
print(f"- Adapter: {adapter.name} ({adapter.address}) "
f"Powered: {adapter.powered} Discovering: {adapter.discovering}")
if __name__ == "__main__":
asyncio.run(main())