Daily tips and tricks from the experts at Adafruit!
View this email in your browser

One big difference between MicroPython and Python on your desktop is the support for standard Python modules.  Because MicroPython has to be small enough to fit on tiny microcontrollers it can’t by default include all the same modules as Python.  For example things like base 64 encoding/decoding with the base64 module or accessing a webpage with the urllib.request module aren’t included in MicroPython.  Only the most basic and core Python modules are available in MicroPython–see the documentation for a full list.

What do you do if you need to use a Python module that isn’t built-in to MicroPython?  One place to check is the micropython-lib repository–this is a repository of code that includes small ports of Python modules to MicroPython.  For example you can find a base64 MicroPython port and urllib.requests MicroPython port.  If you grab the source for those modules and put them on your MicroPython board you can import and use them just like with desktop Python!  However be aware there typically differences in the implementation of micropython-lib modules and the standard desktop Python versions.  Again memory and other constraints mean that MicroPython modules usually can’t include all of the same functionality as their desktop counterparts.  For example the urllib.request MicroPython module only supports the most basic HTTP 1.0 URL access and none of the advanced features of the standard urllib.request module.

Another tip is to carefully review the modules in micropython-lib before using them–you’ll find many modules are empty placeholder shells that are waiting to be filled in with an implementation.  Unfortunately there’s no list of the currently implemented modules so you’ll need to check each one and its Python source to see if there’s an implementation.  Over time expect to see more modules implemented, or even try implementing some of them yourself as a good way to contribute to the project!