{"id":10353,"library":"winrt-windows-devices-enumeration","title":"Windows Devices Enumeration (WinRT)","description":"This package provides the Python projection for the Windows.Devices.Enumeration namespace of the Windows Runtime (WinRT) APIs. It allows Python developers to discover and manage hardware devices available on a Windows system. Part of the larger PyWinRT project, it is currently at version 3.2.1 and follows the PyWinRT release cadence, often tied to Windows SDK updates.","status":"active","version":"3.2.1","language":"en","source_language":"en","source_url":"https://github.com/pywinrt/pywinrt","tags":["windows","winrt","asyncio","device enumeration","hardware"],"install":[{"cmd":"pip install winrt-windows-devices-enumeration","lang":"bash","label":"Install specific enumeration package"}],"dependencies":[],"imports":[{"symbol":"DeviceInformation","correct":"from winrt.windows.devices.enumeration import DeviceInformation"},{"symbol":"DeviceWatcher","correct":"from winrt.windows.devices.enumeration import DeviceWatcher"}],"quickstart":{"code":"import asyncio\nfrom winrt.windows.devices.enumeration import DeviceInformation\n\nasync def list_devices():\n    print(\"Searching for devices...\")\n    # Find all devices asynchronously\n    devices = await DeviceInformation.FindAllAsync()\n\n    if devices.size == 0:\n        print(\"No devices found.\")\n        return\n\n    print(f\"Found {devices.size} devices:\")\n    for i in range(devices.size):\n        device = devices.get_at(i)\n        print(f\"  [{i+1}] Name: {device.name}, Id: {device.id}\")\n\nif __name__ == \"__main__\":\n    # Ensure to run async code using asyncio\n    asyncio.run(list_devices())\n","lang":"python","description":"This quickstart demonstrates how to asynchronously list all discoverable devices using the `DeviceInformation.FindAllAsync()` method. It prints the name and ID of each found device. Remember that WinRT operations are often asynchronous and require `await` and `asyncio`."},"warnings":[{"fix":"Consult the official migration guide (e.g., `pywinrt/scripts/2to3/README.md` on GitHub). Update imports and adjust type casting/boxing logic. `box`/`unbox` are now in `winrt.system`, and `Object.as_()` replaces previous casting patterns.","message":"Version 3.0.0 introduced significant breaking changes, including a new `winrt.runtime` module, changes to `box`/`unbox` functions (moved to `winrt.system`), and the introduction of `winrt.system.Object.as_()` for type casting. Older code will likely fail.","severity":"breaking","affected_versions":"<3.0.0 to >=3.0.0"},{"fix":"Always `await` asynchronous operations (e.g., `await obj.DoSomethingAsync()`). Ensure your code runs within an `async` function and is executed by `asyncio.run()`. From `v3.2.0`, you can use `obj.DoSomethingAsync().get()` or `obj.DoSomethingAsync().wait()` for synchronous calls.","message":"WinRT asynchronous operations (methods ending in `Async`, e.g., `FindAllAsync()`) return awaitable objects. Forgetting to `await` them will result in an `Awaitable` object instead of the final result, leading to type errors if you try to use it directly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always install `winrt-windows-devices-enumeration==2.0.1` (or a later `2.x` release) if you need a specific version in the 2.x range, instead of `2.0.0`.","message":"Version 2.0.0 was never published to PyPI due to compilation issues. If you target `2.x`, attempting to install `2.0.0` will fail or result in an outdated package.","severity":"gotcha","affected_versions":"2.0.0"},{"fix":"Access static events directly on the class (e.g., `MyWinRTClass.StaticEvent += handler`) rather than through instances or older patterns. Refer to updated `pywinrt` documentation for specific event handling examples.","message":"In `v2.1.0`, the handling of static events was changed, moving them to the metaclass of the respective WinRT class. Code accessing static events might need adjustment.","severity":"breaking","affected_versions":"<2.1.0 to >=2.1.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure the package is installed via `pip install winrt-windows-devices-enumeration`. Double-check the import statement for typos.","cause":"The `winrt-windows-devices-enumeration` package is not installed, or there's a typo in the import path.","error":"ModuleNotFoundError: No module named 'winrt.windows.devices.enumeration'"},{"fix":"Prepend `await` to the asynchronous call: `devices = await DeviceInformation.FindAllAsync()`. Ensure the surrounding code runs in an `async` function and is executed via `asyncio.run()`.","cause":"An asynchronous WinRT operation, such as `DeviceInformation.FindAllAsync()`, was called but not `awaited`. The method returns an awaitable object, not the final result.","error":"TypeError: 'winrt.windows.foundation.IAsyncOperation_1[winrt.windows.devices.enumeration.DeviceInformationCollection]' object is not iterable"},{"fix":"Ensure you are using `obj.as_(TargetType)` for explicit type casting where necessary, especially when dealing with generic `winrt.system.Object` types or after deserialization. Verify the object's actual type at runtime.","cause":"This error often occurs after upgrading to `v3.0.0` if old patterns for type casting or accessing properties are still used. `Object.as_()` was introduced for explicit type casting.","error":"AttributeError: 'Object' object has no attribute 'name'"}]}