Hint

Refer to QMK’s documentation for details on how to use community modules

Warning

This is currently broken and WIP, dont use it because it will crash your board.

micropython

Embeds microypthon’s interpreter into your board

Since that’s not very useful by itself, a module is provided to hook into QMK APIs. Namely, you use: import qmk

To execute some code, store it as a string and feed it into the mp_embed_exec_str function

Tip

Writing a C-string directly is not convenient (eg: no IntelliSense for suggestions/typo detection)

To circumvent that, you can write a regular .py file, and then use euc py2c <file.py> to generate the equivalent string in a standalone file, which you can later #include

You could also point your editor at the qmk folder, and get auto-completion thanks to the .pyi files in it

Important

In the future, I plan to integrate import ... with QMK filesystem API (not a thing yet)

When (if) this happens, you would be able to run dynamic code, opposed to the current state, where you can only execute something defined as a const char* at compile time

Available APIs are:

"""Utilities to interact with QMK from MicroPython."""

# ruff: noqa: F401
# the modules being imported dont really exist on the VM
# these imports are the result of having multiple `.c` files
# to organize the code (each one gets its own `.pyi` generated)
#
# this is: you can't `import qmk.keycode` nor `import _keycode`
# instead, you `import qmk` and use it as `qmk.keycode.foo()`

from . import _keycode as keycode
from . import _rgb as rgb

version: str
"""Version of QMK on which this firmware was built, as a raw string."""

version_info: tuple[int, int, int]
"""Version of QMK on which this firmware was built, as a (major, minor, patch) tuple."""

def get_highest_active_layer() -> int:
    """Get what the highest (currently active) layer is."""

def send_string(text: str, /) -> None:
    """Send a string over HID."""

def tap_code(kc: int, /) -> None:
    """Send a basic keycode over HID."""