Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Python client for connecting to MbientLab's MetaWear boards

Project Description


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    


v0.7.1 (2017-02-04)

  • Using MetaWear-CppAPI version 0.7.10
  • Sensor fusion module contributed from user m-georgi (#26).
  • Fix to magnetometer power preset setting due to change in MetaWear-CppAPI (#25).

v0.7.0 (2017-01-13)

  • Using MetaWear-CppAPI version 0.7.4
  • Removed bluepy backend due to it not being fully functional.
  • Refactored connection behaviour. Optional autoconnect via keyword.
  • Unit test work started with Mock backend.
  • Flake8 adaptations.
  • Fix for logging bug (#22)
  • New examples: Two client setup and complimentary filter sensor fusion (#23).

v0.6.0 (2016-10-31)

  • Using MetaWear-CppAPI version 0.6.0
  • Replaced print-logging with proper logging module usage.
  • Removed 64-bit special handling that was no longer needed.

v0.5.2 (2016-10-13)

  • Temperature Module
  • Using Pygatt 3.0.0 (including PR from PyMetaWear contributors)
  • Builds on Windows

v0.5.1 (2016-09-15)

  • Corrections to make it distributable via PyPI.

v0.5.0 (2016-09-15)

  • Using MetaWear-CppAPI version 0.5.22
  • Changed building procedure to handle ARM processors
  • Updated requirements to make pygatt default, all others extras
  • Bluepy backend implemented and partially working
  • BL interface selection for all backends
  • Magnetometer module
  • Barometer module
  • Ambient Light module
  • Modifying notification wrappers to accommodate Epoch value in the data.
  • High speed sampling for accelerometer and gyroscope

v0.4.4 (2016-04-28)

  • Updated MetaWear-CppAPI submodule version.
  • Removed temporary build workaround.

v0.4.3 (2016-04-27)

  • Critical fix for switch notifications.
  • Updated MetaWear-CppAPI submodule version.
  • Now using the new setup_metawear method.
  • Restructured the IS_64_BIT usage which is still needed.

v0.4.2 (2016-04-27)

  • Critical fix for timeout in pybluez/gattlib backend.
  • Added Gyroscope module.
  • Added soft reset method to client.
  • Updated examples.
  • Updated documentation.

v0.4.1 (2016-04-20)

  • Cleanup of new modules sensor data parsing.
  • Bug fix related to accelerometer module.
  • Timeout parameter for client and backends.

v0.4.0 (2016-04-17)

  • Major refactorisation into new module layout.
  • New examples using the new module handling.
  • Accelerometer convenience methods shows strange lag still.

v0.3.1 (2016-04-10)

  • Critical fix for data signal subscription method.
  • handling of building made better,
  • Documentation improved.

v0.3.0 (2016-04-09)

  • Major refactoring: all BLE comm code practically moved to backends.
  • Backend pybluez with gattlib now works well.
  • Travis CI problems with Python 2.7 encoding led to that we are now building on 2.7.11

v0.2.3 (2016-04-07)

  • Changed from using gattlib on its own to using pybluez with gattlib
  • Travis CI and Coveralls
  • Travis CI deploys documentation to gh-pages.
  • Some documentation written.

v0.2.2 (2016-04-06)

  • Convenience method for switch.
  • Sphinx documentation added.
  • Docstring updates.

v0.2.1 (2016-04-04)

  • Refactoring in moving functionality back to client from backends.
  • Enable BlueZ 4.X use with pygatt.
  • Disconnect methods added.
  • Example with switch button notification.

v0.2.0 (2016-04-02)

  • Two backends: pygatt and gattlib
  • pygatt backend can be fully initialize, i.e. handles notifications.
  • gattlib backend cannot fully initialize, i.e. does not handles notifications.

v0.1.1 (2016-03-30)

  • Fix to support Python 3

v0.1.0 (2016-03-30)

  • Initial release
  • Working communication, tested with very few API options.

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(224.3 kB) Copy SHA256 Hash SHA256
Source None Mar 3, 2017

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers