PyWinRT - Windows.Devices.Bluetooth Projection

3.2.1 · active · verified Fri Apr 17

PyWinRT is a set of Python projections for Windows Runtime (WinRT) APIs, allowing Python developers to access native Windows features. This specific package, `winrt-windows-devices-bluetooth`, provides access to Bluetooth-related functionalities from the `Windows.Devices.Bluetooth` namespace. It is currently at version 3.2.1 and follows a frequent release cadence, often aligned with Windows SDK and App SDK updates.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to retrieve information about the default Bluetooth adapter on a Windows system using the `BluetoothAdapter` class. It highlights the typical asynchronous pattern required for most WinRT API calls.

import asyncio
from winrt.windows.devices.bluetooth import BluetoothAdapter

async def get_bluetooth_adapter_info():
    print("Attempting to get default Bluetooth adapter...")
    adapter = await BluetoothAdapter.GetDefaultAsync()

    if adapter:
        print(f"\nBluetooth Adapter Found:")
        print(f"  Device ID: {adapter.DeviceId}")
        print(f"  Is Low Energy Supported: {adapter.IsLowEnergySupported}")
        print(f"  Is Central Role Supported: {adapter.IsCentralRoleSupported}")
        print(f"  Is Peripheral Role Supported: {adapter.IsPeripheralRoleSupported}")
        print(f"  Address: {adapter.BluetoothAddress:X}")
    else:
        print("No Bluetooth adapter found or enabled on this system.")
        print("Ensure Bluetooth is turned on in Windows settings.")

if __name__ == "__main__":
    # Ensure asyncio event loop is running to await WinRT async operations
    asyncio.run(get_bluetooth_adapter_info())

view raw JSON →