This is a library of packages designed to be useful for writing MicroPython applications.
The packages here fall into four categories corresponding to the four top-level directories:
-
python-stdlib: Compatible versions of modules from The Python Standard Library. These should be drop-in replacements for the corresponding Python modules, although many have reduced functionality or missing methods or classes (which may not be an issue for many most cases).
-
python-ecosys: Compatible, but reduced-functionality versions of packages from the larger Python ecosystem, for example that might be found in thePython Package Index.
-
micropython: MicroPython-specific packages that do not have equivalents in other Python environments. This includes drivers for hardware (e.g. sensors, peripherals, or displays), or libraries to work with embedded functionality (e.g. bluetooth), or MicroPython-specific packages that do not have equivalents in CPython.
-
unix-ffi: These packages are specifically for the MicroPython Unix port and provide access to operating-system and third-party libraries via FFI, or functionality that is not useful for non-Unix ports.
To install a micropython-lib package, there are four main options. For more information see the Package management documentation documentation.
As of MicroPython v1.20 (and nightly builds since October 2022), boards
with WiFi and Ethernet support include the mip
package manager.
>>> import mip
>>> mip.install("package-name")
This is the officially-supported tool for interacting with a MicroPython
device, and since v0.4.0 it supports installing packages using the mip
command.
$ mpremote connect /dev/ttyUSB0 mip install package-name
See the mpremote documentation.
If you are building your own firmware, all packages in this repository include
a manifest.py
that can be included into your board manifest via the
require()
command. See Manifest files for
more information.
Many micropython-lib packages are just single-file modules, and you can
quickly get started by copying the relevant Python file to your device. For
example, to add the base64
library, you can directly copy
python-stdlib/base64/base64.py
to the lib
directory on your device.
For packages that are implemented as a package directory, you'll need to copy
the directory instead. For example, to add collections.defaultdict
, copy
collections/collections/__init__.py
and
collections-defaultdict/collections/defaultdict.py
to a directory named
lib/collections
on your device.
Note that unlike the other three approaches based on mip
or manifest.py
,
you will need to manually sort out dependencies. You can look at the
manifest.py
file to see which other packages a given package depends on.
We use GitHub Discussions as our forum, and Discord for chat. These are great places to ask questions and advice from the community or to discuss your MicroPython-based projects.
The MicroPython Wiki is also used for micropython-lib.
For bugs and feature requests, please raise an issue.
We welcome pull requests to add new packages, fix bugs, or add features. Please be sure to follow the Contributor's Guidelines & Code Conventions. Note that MicroPython is licenced under the MIT license, and all contributions should follow this license.
- Develop a set of example programs using these packages.
- Develop more MicroPython packages for common tasks.
- Expand unit testing coverage.
- Add support for referencing remote/third-party repositories.
The terms library, package, and module are overloaded and lead to some confusion. The interpretation used in by the MicroPython project is that:
A library is a collection of installable packages, e.g. The Python Standard Library, or micropython-lib.
A package can refer to two things. The first meaning, "library package", is
something that can be installed from a library, e.g. via mip
(or pip
in
CPython/PyPI). Packages provide modules that can be imported. The ambiguity
here is that the module provided by the package does not necessarily have to
have the same name, e.g. the pyjwt
package provides the jwt
module. In
CPython, the pyseral
package providing the serial
module is another
common example.
A module is something that can be imported. For example, "the os module".
A module can be implemented either as a single file, typically also called
a module or "single-file module", or as a package (the second meaning),
which in this context means a directory containing multiple .py
files
(usually at least an __init__.py
).
In micropython-lib, we also have the concept of an extension package which
is a library package that extends the functionality of another package, by
adding additional files to the same package directory. These packages have
hyphenated names. For example, the collections-defaultdict
package extends
the collections
package to add the defaultdict
class to the collections
module.