index.rst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. .. _micropython_lib:
  2. MicroPython libraries
  3. =====================
  4. .. warning::
  5. Important summary of this section
  6. * MicroPython implements a subset of Python functionality for each module.
  7. * To ease extensibility, MicroPython versions of standard Python modules
  8. usually have ``u`` ("micro") prefix.
  9. * Any particular MicroPython variant or port may miss any feature/function
  10. described in this general documentation (due to resource constraints or
  11. other limitations).
  12. This chapter describes modules (function and class libraries) which are built
  13. into MicroPython. There are a few categories of such modules:
  14. * Modules which implement a subset of standard Python functionality and are not
  15. intended to be extended by the user.
  16. * Modules which implement a subset of Python functionality, with a provision
  17. for extension by the user (via Python code).
  18. * Modules which implement MicroPython extensions to the Python standard libraries.
  19. * Modules specific to a particular `MicroPython port` and thus not portable.
  20. Note about the availability of the modules and their contents: This documentation
  21. in general aspires to describe all modules and functions/classes which are
  22. implemented in MicroPython project. However, MicroPython is highly configurable, and
  23. each port to a particular board/embedded system makes available only a subset
  24. of MicroPython libraries. For officially supported ports, there is an effort
  25. to either filter out non-applicable items, or mark individual descriptions
  26. with "Availability:" clauses describing which ports provide a given feature.
  27. With that in mind, please still be warned that some functions/classes
  28. in a module (or even the entire module) described in this documentation **may be
  29. unavailable** in a particular build of MicroPython on a particular system. The
  30. best place to find general information of the availability/non-availability
  31. of a particular feature is the "General Information" section which contains
  32. information pertaining to a specific `MicroPython port`.
  33. On some ports you are able to discover the available, built-in libraries that
  34. can be imported by entering the following at the REPL::
  35. help('modules')
  36. Beyond the built-in libraries described in this documentation, many more
  37. modules from the Python standard library, as well as further MicroPython
  38. extensions to it, can be found in `micropython-lib`.
  39. Python standard libraries and micro-libraries
  40. ---------------------------------------------
  41. The following standard Python libraries have been "micro-ified" to fit in with
  42. the philosophy of MicroPython. They provide the core functionality of that
  43. module and are intended to be a drop-in replacement for the standard Python
  44. library. Some modules below use a standard Python name, but prefixed with "u",
  45. e.g. ``ujson`` instead of ``json``. This is to signify that such a module is
  46. micro-library, i.e. implements only a subset of CPython module functionality.
  47. By naming them differently, a user has a choice to write a Python-level module
  48. to extend functionality for better compatibility with CPython (indeed, this is
  49. what done by the `micropython-lib` project mentioned above).
  50. On some embedded platforms, where it may be cumbersome to add Python-level
  51. wrapper modules to achieve naming compatibility with CPython, micro-modules
  52. are available both by their u-name, and also by their non-u-name. The
  53. non-u-name can be overridden by a file of that name in your library path (``sys.path``).
  54. For example, ``import json`` will first search for a file ``json.py`` (or package
  55. directory ``json``) and load that module if it is found. If nothing is found,
  56. it will fallback to loading the built-in ``ujson`` module.
  57. .. toctree::
  58. :maxdepth: 1
  59. builtins.rst
  60. array.rst
  61. cmath.rst
  62. gc.rst
  63. math.rst
  64. sys.rst
  65. ubinascii.rst
  66. ucollections.rst
  67. uerrno.rst
  68. uhashlib.rst
  69. uheapq.rst
  70. uio.rst
  71. ujson.rst
  72. uos.rst
  73. ure.rst
  74. uselect.rst
  75. usocket.rst
  76. ussl.rst
  77. ustruct.rst
  78. utime.rst
  79. uzlib.rst
  80. _thread.rst
  81. MicroPython-specific libraries
  82. ------------------------------
  83. Functionality specific to the MicroPython implementation is available in
  84. the following libraries.
  85. .. toctree::
  86. :maxdepth: 1
  87. btree.rst
  88. framebuf.rst
  89. machine.rst
  90. micropython.rst
  91. network.rst
  92. ucryptolib.rst
  93. uctypes.rst
  94. Libraries specific to the pyboard
  95. ---------------------------------
  96. The following libraries are specific to the pyboard.
  97. .. toctree::
  98. :maxdepth: 2
  99. pyb.rst
  100. lcd160cr.rst
  101. Libraries specific to the WiPy
  102. ------------------------------
  103. The following libraries are specific to the WiPy.
  104. .. toctree::
  105. :maxdepth: 2
  106. wipy.rst
  107. Libraries specific to the ESP8266
  108. ---------------------------------
  109. The following libraries are specific to the ESP8266.
  110. .. toctree::
  111. :maxdepth: 2
  112. esp.rst