A simple interface to the HIDAPI library.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easyhid_ng-0.1.0.tar.gz.
File metadata
- Download URL: easyhid_ng-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.2 cpython/3.14.2 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33ec11fecf10aecd015a6e0ef1d5682a21b30218b6b64edf63eba2aba06ef959
|
|
| MD5 |
d5abc7e78ff5abf413c6b33a5496d43c
|
|
| BLAKE2b-256 |
e1e36cbdea8c8869c53ee6ae95456f0e2bfc24c24bdff1be63e22febc780aa21
|
File details
Details for the file easyhid_ng-0.1.0-py3-none-any.whl.
File metadata
- Download URL: easyhid_ng-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.2 cpython/3.14.2 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71bbfb85b1fd824c109a5cb4d403bf0818293d52b8271589f30fb8ef19195657
|
|
| MD5 |
e33a55d0beb833feeae1cb06fe79af8f
|
|
| BLAKE2b-256 |
6ac69511d6eb3814d6ddedcc036b084e2268f0a4153d35fd3191209b8bf13a5b
|