USB Devices

0.4.5 · active · verified Thu Apr 16

usb-devices is a Python library providing tools for mapping, describing, and resetting USB devices connected to the system. It offers a cross-platform API to enumerate devices and retrieve detailed information such as product, manufacturer, and serial numbers, and provides functionality to reset individual devices. The library is actively maintained, with version 0.4.5 being the latest, and sees frequent minor releases addressing compatibility and stability.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to discover and list all connected USB devices using `USBDeviceInfo.get_all_usb_devices()`. It prints key details for each device. Note that features like `reset_device()` typically require elevated permissions and are commented out for safe execution.

from usb_devices import USBDeviceInfo

print("Discovering USB devices...")

try:
    devices = USBDeviceInfo.get_all_usb_devices()
    if not devices:
        print("No USB devices found.")
    for usb_device in devices:
        print(f"Path: {usb_device.path}")
        print(f"Product: {usb_device.product}")
        print(f"Manufacturer: {usb_device.manufacturer}")
        print(f"Serial: {usb_device.serial_number}")
        print(f"VendorId: {usb_device.vendor_id}")
        print(f"ProductId: {usb_device.product_id}")
        print(f"Bus: {usb_device.bus_number}")
        print(f"Address: {usb_device.device_address}")
        print(f"Port: {usb_device.port_number}")
        # Example of resetting a device (requires permissions)
        # if "MyDevice" in str(usb_device.product):
        #     print(f"Attempting to reset {usb_device.product}...")
        #     usb_device.reset_device()
        #     print("Device reset.")
        print("-----------------------------------")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →