Skip to content

pb_client.compile.pack_program

pack_program(modules)

Pack compiled modules into the container the hub stores.

The hub reads stored program data as a run of modules, each one a 32-bit little-endian size, a zero-terminated module name, and that module's .mpy bytes -- with no padding or alignment between them. There is no bare-.mpy alternative: the firmware parses this header before looking at the MicroPython magic, so a bare .mpy is read as a garbage header and refused.

Parameters:

Name Type Description Default
modules Sequence[tuple[str, bytes]]

Name and compiled bytes for each module. The one the hub starts goes first: current firmware runs whichever module comes first, whatever it is called, and takes the program's displayed name from it. Before Pybricks profile v1.5.0 it was found by the name __main__ instead, so a hub that old needs the first one called that -- which is what CompiledProgram.pack decides.

required

Returns:

Type Description
bytes

The bytes to store on the hub.