Windows Devices Enumeration (WinRT)

3.2.1 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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`.

import asyncio
from winrt.windows.devices.enumeration import DeviceInformation

async def list_devices():
    print("Searching for devices...")
    # Find all devices asynchronously
    devices = await DeviceInformation.FindAllAsync()

    if devices.size == 0:
        print("No devices found.")
        return

    print(f"Found {devices.size} devices:")
    for i in range(devices.size):
        device = devices.get_at(i)
        print(f"  [{i+1}] Name: {device.name}, Id: {device.id}")

if __name__ == "__main__":
    # Ensure to run async code using asyncio
    asyncio.run(list_devices())

view raw JSON →