Embed
MicroPython is built to sit inside another program. The official paths are C (the embed port) and JavaScript (the webassembly port). Other languages FFI to one of those two.
C and C++
ports/embed produces a small set of sources you compile into your firmware or desktop app. You own main, the heap, and any native modules you register. Typical calls:
mp_embed_init(heap, sizeof heap);
mp_embed_exec_str("print(1 + 2)");
mp_embed_deinit();
This is the Lua-style embedding story. Expose your own C functions with MP_DEFINE_CONST_FUN_OBJ and a globals dict. The C modules chapter covers the macros.
JavaScript and the browser
ports/webassembly builds micropython.mjs and micropython.wasm. PyScript uses this. You get runPython, proxies between JS objects and Python, and a js module. You do not get machine.Pin — there is no SoC. For GPIO in a browser, use a board emulator instead.
const mp = await loadMicroPython();
mp.runPython("print(1 + 2)");
Other languages
There is no first-party PHP, Go or Rust host kit yet. The practical routes today:
- Rust / Go / Zig — compile the embed port as C and call it through FFI, or host the WASM build.
- PHP — host the WASM build (ext-wasm or a sidecar) or wrap the C embed as a PHP extension. We will publish a kit under tools / embed.
- Python (CPython) — usually you just run CPython. Use embed when you want the MicroPython dialect and bytecode on purpose.
What embedding cannot do
Host kits run the language. They do not magically grow Pico GPIO. To script real pins you either run on the device, or you run an emulator that models those pins and load the same firmware.