@@ -7,68 +7,47 @@ MicroPython libraries
77
88 Important summary of this section
99
10- * MicroPython implements a subset of Python functionality for each module.
11- * To ease extensibility, MicroPython versions of standard Python modules
12- usually have ``u `` ("micro") prefix.
13- * Any particular MicroPython variant or port may miss any feature/function
14- described in this general documentation (due to resource constraints or
15- other limitations).
16-
10+ * MicroPython provides built-in modules that mirror the functionality of the
11+ Python standard library (e.g. :mod: `os `, :mod: `time `), as well as
12+ MicroPython-specific modules (e.g. :mod: `bluetooth `, :mod: `machine `).
13+ * Most standard library modules implement a subset of the functionality of
14+ the equivalent Python module, and in a few cases provide some
15+ MicroPython-specific extensions (e.g. :mod: `array `, :mod: `os `)
16+ * Due to resource constraints or other limitations, some ports or firmware
17+ versions may not include all the functionality documented here.
18+ * To allow for extensibility, the built-in modules can be extended from
19+ Python code loaded onto the device.
1720
1821This chapter describes modules (function and class libraries) which are built
19- into MicroPython. There are a few categories of such modules:
20-
21- * Modules which implement a subset of standard Python functionality and are not
22- intended to be extended by the user.
23- * Modules which implement a subset of Python functionality, with a provision
24- for extension by the user (via Python code).
25- * Modules which implement MicroPython extensions to the Python standard libraries.
26- * Modules specific to a particular :term: `MicroPython port ` and thus not portable.
27-
28- Note about the availability of the modules and their contents: This documentation
29- in general aspires to describe all modules and functions/classes which are
30- implemented in MicroPython project. However, MicroPython is highly configurable, and
31- each port to a particular board/embedded system makes available only a subset
32- of MicroPython libraries. For officially supported ports, there is an effort
33- to either filter out non-applicable items, or mark individual descriptions
34- with "Availability:" clauses describing which ports provide a given feature.
35-
36- With that in mind, please still be warned that some functions/classes
37- in a module (or even the entire module) described in this documentation **may be
38- unavailable ** in a particular build of MicroPython on a particular system. The
39- best place to find general information of the availability/non-availability
40- of a particular feature is the "General Information" section which contains
41- information pertaining to a specific :term: `MicroPython port `.
22+ into MicroPython. This documentation in general aspires to describe all modules
23+ and functions/classes which are implemented in the MicroPython project.
24+ However, MicroPython is highly configurable, and each port to a particular
25+ board/embedded system may include only a subset of the available MicroPython
26+ libraries.
27+
28+ With that in mind, please be warned that some functions/classes in a module (or
29+ even the entire module) described in this documentation **may be unavailable **
30+ in a particular build of MicroPython on a particular system. The best place to
31+ find general information of the availability/non-availability of a particular
32+ feature is the "General Information" section which contains information
33+ pertaining to a specific :term: `MicroPython port `.
4234
4335On some ports you are able to discover the available, built-in libraries that
44- can be imported by entering the following at the REPL::
36+ can be imported by entering the following at the :term: ` REPL ` ::
4537
4638 help('modules')
4739
4840Beyond the built-in libraries described in this documentation, many more
4941modules from the Python standard library, as well as further MicroPython
50- extensions to it, can be found in `micropython-lib `.
42+ extensions to it, can be found in :term: `micropython-lib `.
5143
5244Python standard libraries and micro-libraries
5345---------------------------------------------
5446
5547The following standard Python libraries have been "micro-ified" to fit in with
5648the philosophy of MicroPython. They provide the core functionality of that
5749module and are intended to be a drop-in replacement for the standard Python
58- library. Some modules below use a standard Python name, but prefixed with "u",
59- e.g. ``json `` instead of ``json ``. This is to signify that such a module is
60- micro-library, i.e. implements only a subset of CPython module functionality.
61- By naming them differently, a user has a choice to write a Python-level module
62- to extend functionality for better compatibility with CPython (indeed, this is
63- what done by the `micropython-lib ` project mentioned above).
64-
65- On some embedded platforms, where it may be cumbersome to add Python-level
66- wrapper modules to achieve naming compatibility with CPython, micro-modules
67- are available both by their u-name, and also by their non-u-name. The
68- non-u-name can be overridden by a file of that name in your library path (``sys.path ``).
69- For example, ``import json `` will first search for a file ``json.py `` (or package
70- directory ``json ``) and load that module if it is found. If nothing is found,
71- it will fallback to loading the built-in ``json `` module.
50+ library.
7251
7352.. toctree ::
7453 :maxdepth: 1
@@ -131,7 +110,7 @@ To access platform-specific hardware use the appropriate library, e.g.
131110
132111
133112Libraries specific to the pyboard
134- ---------------------------------
113+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135114
136115The following libraries are specific to the pyboard.
137116
@@ -143,7 +122,7 @@ The following libraries are specific to the pyboard.
143122
144123
145124Libraries specific to the WiPy
146- ------------------------------
125+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147126
148127The following libraries and classes are specific to the WiPy.
149128
@@ -156,7 +135,7 @@ The following libraries and classes are specific to the WiPy.
156135
157136
158137Libraries specific to the ESP8266 and ESP32
159- -------------------------------------------
138+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
160139
161140The following libraries are specific to the ESP8266 and ESP32.
162141
@@ -168,7 +147,7 @@ The following libraries are specific to the ESP8266 and ESP32.
168147
169148
170149Libraries specific to the RP2040
171- --------------------------------
150+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
172151
173152The following libraries are specific to the RP2040, as used in the Raspberry Pi Pico.
174153
@@ -178,11 +157,32 @@ The following libraries are specific to the RP2040, as used in the Raspberry Pi
178157 rp2.rst
179158
180159Libraries specific to Zephyr
181- ----------------------------
160+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182161
183162The following libraries are specific to the Zephyr port.
184163
185164.. toctree ::
186165 :maxdepth: 2
187166
188167 zephyr.rst
168+
169+ Extending built-in libraries from Python
170+ ----------------------------------------
171+
172+ In most cases, the above modules are actually named ``umodule `` rather than
173+ ``module ``, but MicroPython will alias any module prefixed with a ``u `` to the
174+ non-``u `` version. However a file (or :term: ``frozen module` `) named
175+ ``module.py `` will take precedence over this alias.
176+
177+ This allows the user to provide an extended implementation of a built-in library
178+ (perhaps to provide additional CPython compatibility). The user-provided module
179+ (in ``module.py ``) can still use the built-in functionality by importing
180+ ``umodule `` directly. This is used extensively in :term: `micropython-lib `. See
181+ :ref: `packages ` for more information.
182+
183+ This applies to both the Python standard libraries (e.g. ``os ``, ``time ``, etc),
184+ but also the MicroPython libraries too (e.g. ``machine ``, ``bluetooth ``, etc).
185+ The main exception is the port-specific libraries (``pyb ``, ``esp ``, etc).
186+
187+ *Other than when you specifically want to force the use of the built-in module,
188+ we recommend always using ``import module`` rather than ``import umodule``. *
0 commit comments