winrt-windows-devices-bluetooth-advertisement
raw JSON → 3.2.1 verified Mon Apr 27 auth: no python
Python projection of the Windows Runtime (WinRT) Bluetooth Advertisement APIs, part of the pywinrt project. Provides access to Bluetooth LE advertisement watcher, publisher, and related types. Current version 3.2.1, requires Python >=3.9, release cadence irregular (major/minor patches monthly to quarterly).
pip install winrt-windows-devices-bluetooth-advertisement Common errors
error ModuleNotFoundError: No module named 'winrt' ↓
cause Installed only the subpackage without the runtime or core package, or missing dependencies.
fix
Install the required base packages:
pip install winrt-runtime winrt-windows-foundation winrt-windows-devices-bluetooth error AttributeError: module 'winrt.windows.devices.bluetooth.advertisement' has no attribute 'BluetoothLEAdvertisementWatcher' ↓
cause Wrong import casing or version mismatch (v2.x uses different namespace).
fix
Use exact import:
from winrt.windows.devices.bluetooth.advertisement import BluetoothLEAdvertisementWatcher error winrt.system.AccessDeniedException: Access denied ↓
cause Bluetooth permission not granted or administrator privileges required.
fix
Run script with administrator privileges and ensure Bluetooth is enabled in Windows settings.
Warnings
breaking Breaking change in v3.0.0: namespace paths changed to match C# casing (e.g., `winrt.windows.devices.bluetooth.advertisement`). Old paths like `winrt.windows.devices.bluetooth.advertisement` (lowercase) may still exist in v2.x but are removed in v3.x. ↓
fix Use exact casing: `from winrt.windows.devices.bluetooth.advertisement import ...`.
breaking Breaking change in v3.0.0: Event registration returns `EventRegistrationToken` but no longer accepts lambdas with `+=` directly? Check documentation; `+=` pattern is supported. ↓
fix Use `watcher.received += handler` with a callable that accepts (sender, args).
gotcha Async operations must be awaited or called with `.get()` / `.wait()` (v3.2.0+). In v2.x, some async methods had to be called differently (e.g., `.start()` returns IAsyncAction). Use `await` or `asyncio.run()`. ↓
fix Use `await watcher.start()` if it returns an async action, or `watcher.start()` if it is synchronous. Check return type.
gotcha Bluetooth LE permissions must be enabled in Windows settings. Missing permission can cause `AccessDeniedException` or silent failure. ↓
fix Enable Bluetooth and grant permission in Windows Settings > Privacy & security > Bluetooth.
Imports
- BluetoothLEAdvertisementWatcher
from winrt.windows.devices.bluetooth.advertisement import BluetoothLEAdvertisementWatcher - BluetoothLEAdvertisementPublisher
from winrt.windows.devices.bluetooth.advertisement import BluetoothLEAdvertisementPublisher - BluetoothLEAdvertisement
from winrt.windows.devices.bluetooth.advertisement import BluetoothLEAdvertisement - BluetoothLEAdvertisementDataTypes
from winrt.windows.devices.bluetooth.advertisement import BluetoothLEAdvertisementDataTypes
Quickstart
import asyncio
from winrt.windows.devices.bluetooth.advertisement import BluetoothLEAdvertisementWatcher
async def watch():
watcher = BluetoothLEAdvertisementWatcher()
watcher.received += lambda s, e: print(f"Received: {e.bluetooth_address}")
watcher.start()
await asyncio.sleep(5)
watcher.stop()
asyncio.run(watch())