This is the documentation for the latest development branch of MicroPython and may refer to features that are not available in released versions.

If you are looking for the documentation for a specific release, use the drop-down menu on the left and select the desired version.

builtins – builtin functions and exceptions

All builtin functions and exceptions are described here. They are also available via builtins module.

Functions and types

abs()
all()
any()
bin()
class bool
class bytearray

See CPython documentation: bytearray.

class bytes

See CPython documentation: bytes.

decode(encoding='utf-8', errors='strict')

Decode the bytes object to a string using the specified encoding.

MicroPython supports the following encodings:

  • 'utf-8' or 'utf8' - UTF-8 encoding (default)

  • 'ascii' - ASCII encoding (subset of UTF-8)

The errors parameter controls how decoding errors are handled:

  • 'strict' - Raise a UnicodeError on invalid UTF-8 (default)

  • 'ignore' - Skip invalid bytes (requires MICROPY_PY_BUILTINS_BYTES_DECODE_ERRORS)

  • 'replace' - Replace invalid bytes with U+FFFD ‘�’ (requires MICROPY_PY_BUILTINS_BYTES_DECODE_ERRORS)

Note

Error handler support depends on build configuration. On constrained systems, only 'strict' mode may be available.

Example:

>>> b'\xc2\xa9 2024'.decode('utf-8')  # © symbol
'© 2024'
>>> b'hello\xffworld'.decode('utf-8', 'ignore')  # Skip invalid bytes
'helloworld'

Raises LookupError if the encoding is not supported, or UnicodeError if the data contains invalid UTF-8 and errors='strict'.

callable()
chr()
classmethod()
compile()
class complex
delattr(obj, name)

The argument name should be a string, and this function deletes the named attribute from the object given by obj.

class dict
dir()
divmod()
enumerate()
eval()
exec()
filter()
class float
class frozenset
getattr()
globals()
hasattr()
hash()
hex()
id()
input()
class int
classmethod from_bytes(bytes, byteorder)

In MicroPython, byteorder parameter must be positional (this is compatible with CPython).

to_bytes(size, byteorder, /, *, signed=False)

In MicroPython, byteorder parameter must be positional (this is compatible with CPython).

isinstance()
issubclass()
iter()
len()
class list
locals()
map()
max()
class memoryview

See CPython documentation: memoryview.

min()
next()
class object
oct()
open()
ord()
pow()
print()
property()
range()
repr()
reversed()
round()
class set
setattr()
class slice

The slice builtin is the type that slice objects have.

sorted()
staticmethod()
class str
encode(encoding='utf-8')

Encode the string to bytes using the specified encoding.

MicroPython supports the following encodings:

  • 'utf-8' or 'utf8' - UTF-8 encoding (default)

  • 'ascii' - ASCII encoding (subset of UTF-8)

Example:

>>> '© 2024'.encode('utf-8')  # Copyright symbol
b'\xc2\xa9 2024'

Raises LookupError if the encoding is not supported.

center(width)

Return a centered string of length width. Padding is done using spaces.

When Unicode support is enabled (MICROPY_PY_BUILTINS_STR_UNICODE), this method counts Unicode characters rather than bytes, ensuring proper alignment for multi-byte UTF-8 characters.

Example:

>>> 'café'.center(10)  # é is 2 bytes in UTF-8
'   café   '
sum()
super()
class tuple
type()
zip()

Exceptions

exception AssertionError
exception AttributeError
exception Exception
exception ImportError
exception IndexError
exception KeyboardInterrupt

See CPython documentation: KeyboardInterrupt.

See also in the context of Soft Bricking (failure to boot).

exception KeyError
exception MemoryError
exception NameError
exception NotImplementedError
exception OSError
exception RuntimeError
exception StopIteration
exception SyntaxError
exception SystemExit

See CPython documentation: SystemExit.

On non-embedded ports (i.e. Windows and Unix), an unhandled SystemExit exits the MicroPython process in a similar way to CPython.

On embedded ports, an unhandled SystemExit currently causes a Soft Reset of MicroPython.

exception TypeError

See CPython documentation: TypeError.

exception ValueError
exception ZeroDivisionError