Myo API (myo)

myo.init(self, dist_path=None)

Initializes the MyoLibrary by detecting the name of the library to load with ctypes based on the current platform.


dist_path – If specified, must point to the directory where the Myo shared library is located.

  • RuntimeError – If the library is already initialized.
  • EnvironmentError – If the current platform is not supported. Usually raised already by myo.utils.platform.
  • OSError – If the library could not be loaded.

Changed in 0.2.1 - Removed add_to_path parameter.

class myo.Hub

High-level interface for the Myo Hub which manages data processing and event triggering for a Myo device.


There can only be one Hub instance. The constructor of the Hub class will return the existing instance if it has not been shut down since then.


If an exception is set, the Hub can not be re-run. This method will clear the stored exception if there is any.


Set when an exception occured within the listener. The Hub can not be re-run if this is set. Use clear_exception() to remove the exception from the Hub.


If the Hub was run with a thread, it can be joined (waiting blocked) with this method. If the Hub was not started within a thread, this method will do nothing.

run(interval_ms, listener, lil_sleep=0.01)

Run the Hub with an execution interval of interval_ms and the specified listener until the Hub was stopped. This method does not block the main thread. Returns the thread object that was created.

The Hub and its thread will stop as soon as stop() was called or the DeviceListener returns False from one of its callback methods.

lil_sleep specifies a number of seconds to sleep after the Hub has been started. This will allow the Hub thread to start before anything else is called.

run_once(duration_ms, listener)

Run listener for duration_ms seconds.

Returns:True if the Hub is running, False if not.

Sets the locking policy.


Shut the hub down. If the hub is still running, it will be stopped right where it is. Call it before the hub is being garbage collected, or a warning will be printed that it has not been called.

Do not call this method from a DeviceListener as it would cause the current thread to be joined which is not possible. Use stop() to request a stop.


Request the Stop of the Hub when it is running. When join is True, this function will block the current thread until the Hub is not running anymore.

Returns:True if the Hub has been stopped with a call to stop(), False if not. The Hub could still be running though.
Returns:True if the Hub has been stopped with a call to stop(), False if not. The Hub could still be running though.
class myo.DeviceListener

Interface for listening to data sent from a Myo device. Return False from one of its callback methods to instruct the Hub to stop processing.

The DeviceListener operates between the high and low level of the myo Python bindings. The myo object that is passed to callback methods is a myo.lowlevel.ctyping.Myo object.

on_accelerometor_data(myo, timestamp, acceleration)
on_arm_sync(myo, timestamp, arm, x_direction, rotation, warmup_state)
on_arm_unsync(myo, timestamp)
on_battery_level_received(myo, timestamp, level)
on_connect(myo, timestamp, firmware_version)
on_disconnect(myo, timestamp)
on_emg_data(myo, timestamp, emg)
on_event(kind, event)

Called before any of the event callbacks.

on_event_finished(kind, event)

Called after the respective event callbacks have been invoked. This method is always triggered, even if one of the callbacks requested the stop of the Hub.

on_gyroscope_data(myo, timestamp, gyroscope)
on_lock(myo, timestamp)
on_orientation_data(myo, timestamp, orientation)
on_pair(myo, timestamp, firmware_version)
on_pose(myo, timestamp, pose)
on_rssi(myo, timestamp, rssi)
on_unlock(myo, timestamp)
on_unpair(myo, timestamp)
on_warmup_completed(myo, timestamp, warmup_result)
class myo.Feed

This class implements the DeviceListener interface to collect all data and make it available to another thread on-demand.

import myo as libmyo
feed = libmyo.device_listener.Feed()
hub = libmyo.Hub(), feed)

    while True:
        myos = feed.get_connected_devices()
        if myos:
            print myos[0], myos[0].orientation
class MyoProxy(low_myo, timestamp, firmware_version)

Requests the RSSI of the Myo armband. Until the RSSI is retrieved, rssi returns None.

Feed.get_connected_devices(self) → list of Feed.MyoProxy

Returns a list of connected Myo’s.

Feed.get_devices() → list of Feed.MyoProxy

Returns a list of paired and connected Myo’s.

Feed.on_event(kind, event)
Feed.wait_for_single_device(timeout) → Feed.MyoProxy or None

Waits until a Myo is was paired and connected with the Hub and returns it. If the timeout is exceeded, returns None. This function will not return a Myo that is only paired but not connected.

  • timeout – The maximum time to wait for a device.
  • interval – The interval at which the function should exit sleeping. We can not sleep endlessly, otherwise the main thread can not be exit, eg. through a KeyboardInterrupt.