circuitpython/examples/embedding
Damien George a3f9dec788 py/mpconfig: Enable the sys module at all feature levels by default.
This is a pretty fundamental module, and even minimal ports like unix and
zephyr minimal have it enabled.  So, enabled it by default at the lowest
feature level.

Most things in the `sys` module are configurable, and off by default, so it
shouldn't add too much to ports that don't already have it enabled (which
is just the minimal port).

Also note that `sys` is still disabled on the bare-arm port, to keep that
ultra minimal.  It means we now have bare-arm without `sys` and the minimal
port with `sys`.  That will allow different code size comparisons if/when
new `sys` features are added.

Signed-off-by: Damien George <damien@micropython.org>
2025-08-22 13:31:10 +10:00
..
main.c embed: Improve stack top estimation. 2024-02-15 10:07:32 +11:00
Makefile examples/embedding: Add -fno-common to the sample compiler flags. 2024-01-31 14:29:07 +11:00
Makefile.upylib all: Rename *umodule*.c to remove the "u" prefix. 2023-06-08 17:54:17 +10:00
micropython_embed.mk examples/embedding: Rework example to use ports/embed. 2023-01-20 22:28:50 +11:00
mpconfigport.h py/mpconfig: Enable the sys module at all feature levels by default. 2025-08-22 13:31:10 +10:00
README.md all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00

Example of embedding MicroPython in a standalone C application

This directory contains a simple example of how to embed MicroPython in an existing C application.

A C application is represented here by the file main.c. It executes two simple Python scripts which print things to the standard output.

Building the example

First build the embed port using:

$ make -f micropython_embed.mk

This will generate the micropython_embed directory which is a self-contained copy of MicroPython suitable for embedding. The .c files in this directory need to be compiled into your project, in whatever way your project can do that. The example here uses make and a provided Makefile.

To build the example project, based on main.c, use:

$ make

That will create an executable called embed which you can run:

$ ./embed

Out of tree build

This example is set up to work out of the box, being part of the MicroPython tree. Your application will be outside of this tree, but the only thing you need to do for that is to change MICROPYTHON_TOP (found in micropython_embed.mk) to point to the location of the MicroPython repository. The MicroPython repository may, for example, be a git submodule in your project.