easyhid-ng
A simple Python interface to the HIDAPI library.
This is a modernized fork published as python-easyhid-ng for use with the PySpaceMouse package.
Credits
- Original library by ahtn
- macOS M1/M2/M3 fixes by bglopez
- Modernized for Python 3.8+ by JakubAndrysek
Thanks to all maintainers for their contributions!
Installation
pip install easyhid-ng
Requirements
This library requires the hidapi native library to be installed on your system.
macOS
Install hidapi using Homebrew:
brew install hidapi
For Apple Silicon (M1/M2/M3): You need to add hidapi to your library path:
# Check your hidapi version
brew info hidapi
# Add to your shell config (.bashrc or .zshrc) - replace version number as needed:
export DYLD_LIBRARY_PATH=/opt/homebrew/Cellar/hidapi/0.14.0/lib:$DYLD_LIBRARY_PATH
Linux
# Debian/Ubuntu
sudo apt install libhidapi-hidraw0
# Fedora
sudo dnf install hidapi
Windows
- Download the latest hidapi release
- Extract and copy
hidapi.dll(from x64 or x86 folder) to a location in your PATH - Or add the folder containing
hidapi.dllto your system PATH environment variable
Usage
from easyhid import Enumeration
# Stores an enumeration of all the connected USB HID devices
en = Enumeration()
# Return a list of devices based on the search parameters
devices = en.find(manufacturer="Company", product="Widget", interface=3)
# Print a description of the devices found
for dev in devices:
print(dev.description())
# Open a device
dev.open()
# Write some bytes to the device
dev.write(bytearray([0, 1, 2, 3]))
# Read some bytes
print(dev.read())
# Close a device
dev.close()
Context Manager
You can also use devices as context managers:
from easyhid import Enumeration
en = Enumeration()
devices = en.find(vid=0x1234, pid=0x5678)
if devices:
with devices[0] as dev:
dev.write(bytearray([0x00, 0x01]))
data = dev.read(size=64, timeout=1000)
Examples
See the examples folder for complete examples:
list_devices.py- List all connected HID devices with detailed information
python examples/list_devices.py
API Reference
Enumeration
Create an enumeration of all connected HID devices.
en = Enumeration(vid=0, pid=0) # 0 = any
Methods:
find(vid, pid, serial, interface, path, release_number, manufacturer, product, usage, usage_page)- Filter devicesshow()- Print descriptions of all devices
HIDDevice
Represents a single HID device.
Properties:
path- Device pathvendor_id- USB Vendor IDproduct_id- USB Product IDserial_number- Device serial numbermanufacturer_string- Manufacturer nameproduct_string- Product namerelease_number- Device release numberinterface_number- Interface numberusage_page- HID usage pageusage- HID usage
Methods:
open()- Open the deviceclose()- Close the devicewrite(data, report_id=0)- Write data to the deviceread(size=64, timeout=None)- Read data from the devicesend_feature_report(data, report_id=0)- Send a feature reportget_feature_report(size, report_id=0)- Get a feature reportis_open()- Check if device is openis_connected()- Check if device is still connecteddescription()- Get device description string
Troubleshooting
ModuleNotFoundError: No module named 'easyhid'
Install the library:
pip install easyhid-ng
AttributeError: function/symbol 'hid_enumerate' not found
The HIDAPI native library is not installed. Follow the installation instructions above for your OS.
OSError: cannot load library 'hidapi.dll' (Windows)
Download hidapi.dll from the hidapi releases and add it to your PATH.
Testing HIDAPI Installation
You can verify hidapi is working using hidapitester:
# List connected devices
./hidapitester --list
# Read from a device
./hidapitester --vidpid 1234/5678 --open --read-input
License
MIT License - see LICENSE for details.
Metadata
Release files for easyhid-ng 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| easyhid_ng-0.1.0.tar.gz | 7.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| easyhid_ng-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.7 kB
Release files / easyhid_ng-0.1.0.tar.gz
| Download URL | easyhid_ng-0.1.0.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
33ec11fecf10aecd015a6e0ef1d5682a21b30218b6b64edf63eba2aba06ef959
|
|
BLAKE2b-256 checksum How to use checksums |
e1e36cbdea8c8869c53ee6ae95456f0e2bfc24c24bdff1be63e22febc780aa21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.2 cpython/3.14.2 HTTPX/0.28.1
|
Release files / easyhid_ng-0.1.0-py3-none-any.whl
| Download URL | easyhid_ng-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
71bbfb85b1fd824c109a5cb4d403bf0818293d52b8271589f30fb8ef19195657
|
|
BLAKE2b-256 checksum How to use checksums |
6ac69511d6eb3814d6ddedcc036b084e2268f0a4153d35fd3191209b8bf13a5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.2 cpython/3.14.2 HTTPX/0.28.1
|