Skip to content

Software

PySpaceMouse

From github.com/JakubAndrysek/PySpaceMouse (opens in a new tab)

  • Humanoids and robot learning
  • Library
  • MIT

A Python library that reads 3Dconnexion SpaceMouse devices directly over raw HID, without needing the vendor drivers or software. Used for teleoperation and robot control.

Facts

GitHub stars
152read on 28 Nov 2026
Last update
23 Aug 2026Newest commit on master
Maintenance
Maintaineda commit in the last 12 months
Difficulty
Beginner
Hardware it needs, as the project states it
On Linux, read access to the device may need a udev rule for vendor ID 256f; installation via pip pulls in hidapi, which needs nothing else on Linux, macOS or Windows.

Checked on GitHub on 28 Nov 2026.

Licenses

Code
MIT (opens in a new tab)

Read by Robotheca from LICENSE (opens in a new tab) (MIT) at commit 46fa35a (opens in a new tab), on 16 Oct 2026.

Commercial use
Yes

At a glance

What it is
  • Reads six-axis translation and rotation values plus button states from SpaceMouse devices.
  • Works without installing 3Dconnexion drivers, talking to the controller directly through hidapi.
  • Auto-detects connected devices, or opens a specific device by name, index or path.
  • Supports button and per-axis callbacks with deadzone filtering and rate limiting.
  • Offers axis convention options and custom axis remapping or inversion for different coordinate frames.
  • Includes a command-line tool to list connected, supported and HID devices and to test the connection.

Robotheca's summary of the project's documents, not the creator's words.

Robots on Robotheca
No robot on Robotheca uses it yet.
Licence
MIT. Commercial use: Yes. Where it was read
Install
In the creator's words: The project's website (opens in a new tab)
Maintenance
Maintained, last commit on 23 Aug 2026.

Use it

How to install it, in the creator's words: The project's website (opens in a new tab)

Robotheca doesn't review code. Read it before running it.

Files and versions

Facts read at commit 46fa35a

Robotheca never hosts the code: each link goes to the creator's own page.

The README

The creator's own README, copied as written: README.md by @JakubAndrysek, at commit 46fa35a, under MIT (opens in a new tab). The original on GitHub (opens in a new tab).

Read the README here

PySpaceMouse

🎮 Multiplatform Python library for 3Dconnexion SpaceMouse devices using raw HID.

3Dconnexion Space Mouse in Python using raw HID. Note: you don't need to install or use any of the drivers or 3Dconnexion software to use this package. It interfaces with the controller directly with hidapi, via the hidapi (opens in a new tab) Python bindings.

Image (opens in a new tab) (opens in a new tab)

Image (opens in a new tab) (opens in a new tab)

PySpaceMouse (opens in a new tab) is forked from: johnhw/pyspacenavigator (opens in a new tab) and modified to be multiplatform.

Picture: spacemouse-robot.jpg

Supported 3Dconnexion devices
  • SpaceNavigator
  • SpaceMouse Pro / Pro Wireless
  • SpaceMouse Wireless
  • SpaceMouse Compact
  • SpaceMouse Enterprise
  • SpacePilot / SpacePilot Pro
  • 3Dconnexion Universal Receiver
  • ...
  • Add more devices (opens in a new tab)
Installation
pip install pyspacemouse
CLI
pyspacemouse --list-connected    # Show connected devices
pyspacemouse --list-supported    # Show all supported types
pyspacemouse --list-hid          # Show all HID devices
pyspacemouse --test              # Test connection
pyspacemouse --version           # Show version
Linux permissions

On linux, you may not have permission to read from the device. To fix this, you can create a udev rule based on the device's Vendor ID (256f for 3Dconnexion's):

echo 'SUBSYSTEM=="hidraw", ATTRS{idVendor}=="256f", MODE="0660", TAG+="uaccess"' | sudo tee /etc/udev/rules.d/50-spacemouse.rules
echo 'SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="256f", MODE="0660", TAG+="uaccess"' | sudo tee -a /etc/udev/rules.d/50-spacemouse.rules
sudo udevadm control --reload-rules && sudo udevadm trigger
Troubleshooting

See troubleshooting.md (opens in a new tab) for help with common issues.

Quick Start

Here we use has_motion() to check if any of the spatial axes have non-zero values. The optional argument is the threshold used, and is applied per-axis.

import pyspacemouse

# Context manager (recommended) - automatically closes device
with pyspacemouse.open() as device:
    while True:
        state = device.read()
        if state.has_motion(0.01):
            print(state.x, state.y, state.z, state.roll, state.pitch, state.yaw)
API Reference

From version 2.0.0 the API has been modularized and changed. Please look at the API Reference (opens in a new tab) and Examples (opens in a new tab) for more information.

Device Discovery
import pyspacemouse

# List connected SpaceMouse devices
pyspacemouse.get_connected_devices()
# Returns: ["SpaceNavigator", "SpaceMouse Pro", ...]

# List connected SpaceMouse devices with paths
pyspacemouse.get_connected_devices_by_path()
# Returns: {"/dev/hidraw0": "SpaceNavigator", ...}

# List all supported device types
pyspacemouse.get_supported_devices()
# Returns: [(name, vendor_id, product_id), ...]

# List ALL HID devices (for debugging)
pyspacemouse.get_all_hid_devices()
# Returns: [(product, manufacturer, vid, pid), ...]
Opening Devices
# Auto-detect and open first device
with pyspacemouse.open() as device:
    state = device.read()

# Open specific device by name
with pyspacemouse.open(device="SpaceNavigator") as device:
    state = device.read()

# Open second device when multiple identical devices are connected
with pyspacemouse.open(device_index=1) as device:
    state = device.read()

# Open by filesystem path (Linux: /dev/hidraw0)
with pyspacemouse.open_by_path("/dev/hidraw0") as device:
    state = device.read()
Reading State
with pyspacemouse.open() as device:
    state = device.read()

    # 6-DOF axes (range: -1.0 to 1.0)
    print(state.x, state.y, state.z)  # Translation
    print(state.roll, state.pitch, state.yaw)  # Rotation

    # Buttons (list of 0/1)
    print(state.buttons)

    # Timestamp
    print(state.t)
Axis Conventions

For new code, opt into an axis convention by passing an enum value on device open:

import pyspacemouse
from pyspacemouse import AxisConvention

with pyspacemouse.open(axis_convention=AxisConvention.HID_Z_UP) as device:
    state = device.read()

See Axis Conventions (opens in a new tab) for the full mapping table. Custom device_spec mappings are used exactly as provided and cannot be combined with axis_convention.

Callbacks
import pyspacemouse
import time


# Button callback
def on_button(state, buttons, pressed):
    print(f"Button {pressed} pressed!")


button_callbacks = [
    pyspacemouse.ButtonCallback(0, on_button),  # Button 0
    pyspacemouse.ButtonCallback([0, 1], on_button),  # Both 0 and 1
]

# DOF callback with filtering
dof_callbacks = [
    pyspacemouse.DofCallback(
        axis="x",
        callback=lambda s, v: print(f"X: {v}"),
        callback_minus=lambda s, v: print(f"X negative: {v}"),
        filter=0.1,  # Deadzone
        sleep=0.05,  # Rate limit
    ),
]

with pyspacemouse.open(
    button_callbacks=button_callbacks,
    dof_callbacks=dof_callbacks,
) as device:
    while True:
        device.read()  # Triggers callbacks
        time.sleep(0.001)  # NOTE: avoid larger sleeps, which can cause data to buffer
Custom Axis Mapping

Choose a built-in convention for common application frames:

import pyspacemouse
from pyspacemouse import AxisConvention

with pyspacemouse.open(axis_convention=AxisConvention.ROS) as device:
    state = device.read()

For custom coordinate frames, remap or invert axes explicitly:

import pyspacemouse

# Get existing device spec and modify axes
specs = pyspacemouse.get_device_specs()
base = specs["SpaceNavigator"]

custom = pyspacemouse.modify_device_info(
    base,
    remap_axes={"x": "y", "y": ("x", -1), "yaw": ("yaw", -1)},
)

with pyspacemouse.open(device_spec=custom) as device:
    state = device.read()

See Custom Device Configuration (opens in a new tab) for full API.

Examples

See the examples/ (opens in a new tab) directory:

ExampleDescription
01_basic.pySimple reading with context manager
02_callbacks.pyButton and DOF callbacks
03_multi_device.pyUsing two devices simultaneously
04_open_by_path.pyOpen specific device by path
05_discovery.pyList and inspect devices
06_axis_callbacks.pyPer-axis callbacks with filtering
07_led.pyLED control
08_buttons.pyButton names and handling
09_invert_rotations.pyInvert rotations
10_custom_config_unity.pyA totally custom device config using the Unity axis convention
Dependencies

pip install pyspacemouse pulls in the hidapi (opens in a new tab) package, whose wheels bundle the hidapi C library. There is nothing else to install on Linux, macOS or Windows.

Developing / Contributing

This project includes a Makefile with commands for creating a virtual environment (using hatch), and publishing to pypi.

You will need hatch and pre-commit for this. You can get these by using

# Most recently tested with hatch 1.17.0
pipx install hatch pre-commit

If you're not familiar with pipx, it lets you install python tools into isolated environments in ~/.local.

For building the documentation locally, you will also need doxygen installed and on the path.

Used In

Robotheca lists software as a reference: nothing is hosted or run here, and every fact links to where it was read.