Python client for connecting to MbientLab's MetaWear boards
Python Makefile Shell
Latest commit 2f11bfc Jan 13, 2017 @hbldh Version 0.7.0
Updating MetaWear-CPPApi to 0.7.4
Refactored connection behaviour: connect keyword in client to avoid autoconnect if desired.
Unit test work done and a working MockBackend.
Moved backends to simple modules instead of packages.
Flake8 adaptations.
Fix for multiple logging handlers bug. Fixes #23
Removed bluepy
Updated docs for removed bluepy.
Removing Tox testing, reverting to old Travis solution.
Added Python 3.6 to tests.
New examples: Two clients and Complimentary filter (#22).



Python package for connecting to and using MbientLab's MetaWear boards.

PyMetawear is meant to be a thin wrapper around the MetaWear C++ API, providing a more Pythonic interface. It has support for two different Python packages for Bluetooth Low Energy communication:

PyMetaWear can be run with Python 2 and 3.4 with both backends, but only with the pygatt backend for Python 3.5.

It is a Linux-only package right now! It can be built on Windows, given that Visual Studio Community 2015 has been installed first, but there is no working backend for Windows BLE yet.


$ pip install pymetawear

Currently, only the pygatt communication backend is installed by default. The other backend can be installed as extras:

$ pip install pymetawear[pybluez]

Debian requirements for pymetawear

  • build-essential
  • python-dev

Additional requirements for pybluez

  • libglib2.0-dev
  • bluetooth
  • libbluetooth-dev
  • libboost-python-dev
  • libboost-thread-dev


Clone this repository and run

$ python build

to pull in the MetaWear C++ API submodule, build it and copy the Python wrappers from it to the PyMetaWear folder. This can also be achieved by running

$ pip install -e .

in the cloned repository's root folder.


Available in the Github pages of this repository.

Basic Usage

The MetaWear client can be used in two ways: either as Pythonic convenience class for handling a MetaWear board or as a simple communication client governed by the libmetawear C++ library.

Creating a client, and thus also setting up a Bluetooth connection to the MetaWear board, is equal for both the two usage profiles:

from pymetawear.client import MetaWearClient
backend = 'pygatt'  # Or 'pybluez'
c = MetaWearClient('DD:3A:7D:4D:56:F0', backend)

An example: blinking with the LED lights can be done like this with the convenience methods:

pattern = c.led.load_preset_pattern('blink', repeat_count=10)
c.led.write_pattern(pattern, 'g')

or like this using the raw libmetawear shared library:

from ctypes import byref
from pymetawear import libmetawear
from pymetawear.mbientlab.metawear.peripheral import Led

pattern = Led.Pattern(repeat_count=10)
libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), Led.PRESET_BLINK)
libmetawear.mbl_mw_led_write_pattern(c.board, byref(pattern), Led.COLOR_GREEN)

Actual addresses to your MetaWear board can be found by scanning, either directly with hcitool lescan or with the included discover_devices method:

from pymetawear.client import discover_devices
out = discover_devices()
print out
[(u'DD:3A:7D:4D:56:F0', u'MetaWear'), (u'FF:50:35:82:3B:5A', u'MetaWear')]

See the examples folder for more examples on how to use the libmetawear library with this client.


All functionality of the MetaWear C++ API is able to be used using the PyMetaWear client, and some of the modules have had convenience methods added to simplify the use of them. Below are two list, one of modules which have had their convenience methods written and one of modules that are awaiting such focus.

Completed Modules Partial Modules Unimplemented Modules
Accelerometer Settings Proximity
Gyroscope   Color Detector
Haptic   Humidity
Switch   GPIO
Barometer   iBeacon
Magnetometer   NeoPixel
Ambient Light