WinRT Windows Devices Radios

3.2.1 · active · verified Fri Apr 17

winrt-windows-devices-radios is a Python projection of a subset of Windows Runtime (WinRT) APIs, specifically those related to managing wireless radios like Wi-Fi and Bluetooth. It allows Python applications to interact with system hardware for radio control on Windows. Part of the broader `pywinrt` project, it is currently at version 3.2.1 and receives regular updates corresponding to new Windows SDK releases and `pywinrt` core improvements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to enumerate available wireless radios (Wi-Fi, Bluetooth) and their current state using the WinRT API. It requires an `asyncio` event loop as most WinRT operations are asynchronous.

import asyncio
from winrt.windows.devices.radios import Radio, RadioState

async def list_radios():
    try:
        radios = await Radio.get_radios_async()
        if not radios:
            print("No radios found.")
            return

        print(f"Found {len(radios)} radios:")
        for radio in radios:
            print(f"  Name: {radio.name}")
            print(f"  Kind: {radio.kind}")
            print(f"  State: {radio.state}")
            # Example of setting state (requires appropriate user permissions)
            # if radio.state == RadioState.ON:
            #     print(f"  Attempting to turn OFF {radio.name}...")
            #     # await radio.set_state_async(RadioState.OFF)
            #     # print(f"  Turned OFF {radio.name}")

    except Exception as e:
        print(f"An error occurred: {e}")
        print("Ensure you are running on Windows with necessary permissions.")

if __name__ == "__main__":
    # os.environ.get('WINRT_DEBUG', 'false') # Example for auth check if needed
    asyncio.run(list_radios())

view raw JSON →