{"id":7843,"library":"usb-devices","title":"USB Devices","description":"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.","status":"active","version":"0.4.5","language":"en","source_language":"en","source_url":"https://github.com/bluetooth-devices/usb-devices","tags":["usb","device","hardware","discovery","enumeration"],"install":[{"cmd":"pip install usb-devices","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"USBDeviceInfo","correct":"from usb_devices import USBDeviceInfo"}],"quickstart":{"code":"from usb_devices import USBDeviceInfo\n\nprint(\"Discovering USB devices...\")\n\ntry:\n    devices = USBDeviceInfo.get_all_usb_devices()\n    if not devices:\n        print(\"No USB devices found.\")\n    for usb_device in devices:\n        print(f\"Path: {usb_device.path}\")\n        print(f\"Product: {usb_device.product}\")\n        print(f\"Manufacturer: {usb_device.manufacturer}\")\n        print(f\"Serial: {usb_device.serial_number}\")\n        print(f\"VendorId: {usb_device.vendor_id}\")\n        print(f\"ProductId: {usb_device.product_id}\")\n        print(f\"Bus: {usb_device.bus_number}\")\n        print(f\"Address: {usb_device.device_address}\")\n        print(f\"Port: {usb_device.port_number}\")\n        # Example of resetting a device (requires permissions)\n        # if \"MyDevice\" in str(usb_device.product):\n        #     print(f\"Attempting to reset {usb_device.product}...\")\n        #     usb_device.reset_device()\n        #     print(\"Device reset.\")\n        print(\"-----------------------------------\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"On Linux, configure udev rules (e.g., `sudo usermod -a -G dialout $USER`, then log out/in) or run the script with `sudo`. On Windows, ensure the script is run as Administrator.","message":"Accessing USB devices often requires elevated permissions (e.g., root/administrator on Linux/Windows, or specific udev rules on Linux). Failure to do so will result in `Permission denied` errors, especially when attempting operations like `reset_device()`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you are using `usb-devices` version 0.4.2 or newer. If issues persist, verify system drivers and run with administrative privileges.","message":"Earlier versions (prior to v0.4.2) had known issues importing and running correctly on Windows. While fixed in v0.4.2+, specific Windows configurations or device drivers might still cause unexpected behavior or prevent device detection.","severity":"gotcha","affected_versions":"< 0.4.2"},{"fix":"Upgrade to `usb-devices` version 0.4.1 or newer. Always check for `None` when accessing `usb_device.manufacturer` or `usb_device.product` for robustness.","message":"Some USB devices may not provide complete `manufacturer` or `product` information. In such cases, these attributes on the `USBDevice` object will be `None`. Prior to v0.4.1, this could sometimes lead to errors if not explicitly handled.","severity":"gotcha","affected_versions":"< 0.4.1"},{"fix":"If device presence changes are critical, re-call `USBDeviceInfo.get_all_usb_devices()` periodically or upon a trigger to refresh the device list.","message":"The `get_all_usb_devices()` method provides a snapshot of currently connected devices. It does not automatically update when devices are hot-plugged (connected or disconnected). To detect changes, you must call the method again.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the package using pip: `pip install usb-devices`","cause":"The `usb-devices` package is not installed in your Python environment or is not accessible via the Python path.","error":"ModuleNotFoundError: No module named 'usb_devices'"},{"fix":"Verify that your operating system's USB device file structure is intact and accessible. This might indicate an issue with the OS configuration or an unsupported environment.","cause":"The library could not find the expected system files for enumerating USB devices. This typically happens on Linux if `/sys/bus/usb/devices` is not mounted or accessible, or if the system uses an unusual file structure.","error":"FileNotFoundError: [Errno 2] No such file or directory: '/sys/bus/usb/devices/...' (or similar path)"},{"fix":"Run your script with `sudo` (e.g., `sudo python your_script.py`) or, for a more persistent solution, configure `udev` rules to grant your user access to USB devices. On Windows, ensure you are running as Administrator.","cause":"This error, often seen on Linux, indicates that the current user lacks the necessary permissions to perform the requested USB operation (e.g., accessing device information or resetting a device).","error":"Error: Operation not permitted"}]}