Skip to main content

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

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

  1. Download the latest hidapi release
  2. Extract and copy hidapi.dll (from x64 or x86 folder) to a location in your PATH
  3. Or add the folder containing hidapi.dll to 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 devices
  • show() - Print descriptions of all devices

HIDDevice

Represents a single HID device.

Properties:

  • path - Device path
  • vendor_id - USB Vendor ID
  • product_id - USB Product ID
  • serial_number - Device serial number
  • manufacturer_string - Manufacturer name
  • product_string - Product name
  • release_number - Device release number
  • interface_number - Interface number
  • usage_page - HID usage page
  • usage - HID usage

Methods:

  • open() - Open the device
  • close() - Close the device
  • write(data, report_id=0) - Write data to the device
  • read(size=64, timeout=None) - Read data from the device
  • send_feature_report(data, report_id=0) - Send a feature report
  • get_feature_report(size, report_id=0) - Get a feature report
  • is_open() - Check if device is open
  • is_connected() - Check if device is still connected
  • description() - 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easyhid_ng-0.1.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easyhid_ng-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

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

Hashes for easyhid_ng-0.1.0.tar.gz
Algorithm Hash digest
SHA256 33ec11fecf10aecd015a6e0ef1d5682a21b30218b6b64edf63eba2aba06ef959
MD5 d5abc7e78ff5abf413c6b33a5496d43c
BLAKE2b-256 e1e36cbdea8c8869c53ee6ae95456f0e2bfc24c24bdff1be63e22febc780aa21

See more details on using hashes here.

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

Hashes for easyhid_ng-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71bbfb85b1fd824c109a5cb4d403bf0818293d52b8271589f30fb8ef19195657
MD5 e33a55d0beb833feeae1cb06fe79af8f
BLAKE2b-256 6ac69511d6eb3814d6ddedcc036b084e2268f0a4153d35fd3191209b8bf13a5b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page