{"id":10355,"library":"winrt-windows-devices-radios","title":"WinRT Windows Devices Radios","description":"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.","status":"active","version":"3.2.1","language":"en","source_language":"en","source_url":"https://github.com/pywinrt/pywinrt","tags":["windows","winrt","interop","hardware","radios","bluetooth","wifi","network"],"install":[{"cmd":"pip install winrt-windows-devices-radios","lang":"bash","label":"Install specific package"},{"cmd":"pip install pywinrt","lang":"bash","label":"Install all WinRT packages"}],"dependencies":[],"imports":[{"note":"WinRT types are typically imported directly from their module path.","wrong":"import winrt.windows.devices.radios.Radio","symbol":"Radio","correct":"from winrt.windows.devices.radios import Radio"},{"symbol":"RadioState","correct":"from winrt.windows.devices.radios import RadioState"}],"quickstart":{"code":"import asyncio\nfrom winrt.windows.devices.radios import Radio, RadioState\n\nasync def list_radios():\n    try:\n        radios = await Radio.get_radios_async()\n        if not radios:\n            print(\"No radios found.\")\n            return\n\n        print(f\"Found {len(radios)} radios:\")\n        for radio in radios:\n            print(f\"  Name: {radio.name}\")\n            print(f\"  Kind: {radio.kind}\")\n            print(f\"  State: {radio.state}\")\n            # Example of setting state (requires appropriate user permissions)\n            # if radio.state == RadioState.ON:\n            #     print(f\"  Attempting to turn OFF {radio.name}...\")\n            #     # await radio.set_state_async(RadioState.OFF)\n            #     # print(f\"  Turned OFF {radio.name}\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n        print(\"Ensure you are running on Windows with necessary permissions.\")\n\nif __name__ == \"__main__\":\n    # os.environ.get('WINRT_DEBUG', 'false') # Example for auth check if needed\n    asyncio.run(list_radios())\n","lang":"python","description":"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."},"warnings":[{"fix":"Consult the `pywinrt` migration guide for updating code from v2.x to v3.x. Key changes include importing `box_value` from `winrt.system` and using `obj.as_(TargetType)`.","message":"Version 3.0.0 introduced significant breaking changes, including a new `winrt.runtime` module, changes to boxing/unboxing functions, and how `winrt.system.Object` methods like `as_()` are used. Refer to the migration guide for details.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Ensure your development and deployment environment is running Windows. For cross-platform solutions, consider platform-agnostic alternatives.","message":"This library is a projection of Windows Runtime (WinRT) APIs and is therefore strictly Windows-only. Attempting to install or run it on non-Windows operating systems will result in `ImportError` or `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `await` with WinRT async methods and ensure your application runs within an `asyncio` event loop (e.g., by calling `asyncio.run()` for top-level async functions).","message":"Many WinRT methods are asynchronous, indicated by names ending in `_async` (e.g., `get_radios_async`). These methods return `IAsyncOperation` or `IAsyncAction` objects and must be `await`ed within an `asyncio` event loop.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install winrt-windows-devices-radios` to install the package in your active Python environment.","cause":"The `winrt-windows-devices-radios` package is not installed or the Python environment is incorrect.","error":"ModuleNotFoundError: No module named 'winrt.windows.devices.radios'"},{"fix":"Ensure all async WinRT operations are `await`ed inside `async` functions, and that your main function uses `asyncio.run(your_async_main_function())`.","cause":"An `await` call was made outside of an `async` function, or an `async` function was called without `asyncio.run()` or a running event loop.","error":"RuntimeError: The current thread has no asyncio event loop."},{"fix":"Verify you are on a compatible Windows OS. Ensure your Python installation matches your system architecture (usually 64-bit). Try reinstalling the `winrt-windows-devices-radios` package. Ensure relevant Windows system components are up to date.","cause":"This error typically occurs if a necessary Windows DLL (e.g., Visual C++ Redistributable, or a core Windows component) is missing, corrupted, or if the Python environment's architecture (32-bit vs. 64-bit) does not match the Windows installation, or if attempting to run on non-Windows.","error":"ImportError: DLL load failed while importing _winrt_windows_devices_radios: The specified module could not be found."}]}