sys-system specific functions

This module implements a subset of the corresponding CPython module, as described below. For more information, please refer to the original CPython documentation: sys.



Terminate the current program with the given exit code. According to this, this function raises the "SystemExit" exception. If a parameter is given, its value is given as the parameter of SystemExit.

sys.print_exception(exc, file=sys.stdout)

Use traceback to file-like object files (or sys.stdout by default) to print exceptions.

Difference from CPython
This is a simplified version of a function that appears in the backtracking module of CPython. Unlike traceback.print_exception(), this function only accepts outliers instead of exception types, outliers and traceback objects; the file parameter should be positional; other parameters are not supported. A traceback module compatible with CPython can be found in micropython-lib.



The variable parameter list when the current program is started.


The byte order of the system ("little endian" or "big endian"`).


An object containing information about the current Python implementation. For MicroPython, it has the following attributes:

  • name-the string "micropython"
  • version-tuple (major, minor, micro), e.g. (1, 7, 0)

This object is the recommended way to distinguish MicroPython from other Python implementations (note that it may still not exist in very small ports).

Difference from CPython
CPython requires more attributes for this object, but the minimum requirement to actually be useful is implemented in MicroPython.


The maximum value that the native integer type can save on the current platform, or the maximum value that the MicroPython integer type can represent, if it is less than the platform maximum value (for the MicroPython port without long int support).

This attribute is very useful for detecting the "bitness" of the platform (32-bit and 64-bit, etc.). It is recommended not to directly compare this attribute with a value, but to calculate the number of digits:

bits = 0
v = sys.maxsize
while v:
    bits += 1
    v >>= 1
if bits> 32:
    # 64-bit (or more) platform
    # 32-bit (or less) platform
    # Note that on 32-bit platform, value of bits may be less than 32
    # (e.g. 31) due to peculiarities described above, so use "> 16",
    # "> 32", "> 64" style of comparisons.


Load the dictionary of the module. On some ports, it may not contain built-in modules.


A variable directory list for searching imported modules.


The platform on which MicroPython is running. For OS/RTOS ports, this is usually the identifier of the OS, for example, "LINUX". For bare metal ports, it is the identifier of the circuit board, such as "pyboard" for the original MicroPython reference board. Therefore, it can be used to distinguish one board from another. If you need to check whether your program is running on MicroPython (compared to other Python implementations), please use sys.implementation.


Standard error stream.


Standard input stream.


Standard output stream.


The implemented Python version, returns a string


The implemented Python version, which returns a tuple of integers