Skip to main content

Module python

Module python 

Source
Expand description

The Python runtimes a firmware can speak, and the staging text pasted into their REPLs.

A board configured with a Python runtime boots a stock interpreter instead of the project’s own application. The runner never imports or executes the guest’s Python itself: it waits for the REPL prompt, sends the raw-REPL control bytes and pastes a program, so everything here is pure bytes and strings. Keeping it separate from the run loop is what makes the handshake testable without booting a chip.

MicroPython and CircuitPython share the friendly-REPL prompt and the raw paste framing. They differ in the file the interpreter runs on boot — CircuitPython looks for code.py, MicroPython for main.py — and in whether a program may already be running when the paste arrives.

Enums§

PythonRuntime
Which interpreter a board’s console speaks.

Constants§

REPL_PROMPT
The friendly-REPL prompt both runtimes print. It is the only sign the interpreter is ready; matching a banner would tie the runner to one build’s wording.

Functions§

detect
Which interpreter a board’s console speaks, from the configured runtime and a firmware hint: its file name or a captured banner.
detect_bytes
detect for a firmware image or a console banner the caller already holds as bytes. The scan is case-insensitive and does not require the hint to be UTF-8.
entry_candidates
PythonRuntime::entry_candidates as a free function.
entry_name
PythonRuntime::entry_name as a free function, so a call site that already holds the runtime can read entry_name(runtime).
interrupt_sequence
PythonRuntime::interrupt_sequence as a free function.
raw_paste_begin
PythonRuntime::raw_paste_begin as a free function.
raw_paste_end
PythonRuntime::raw_paste_end as a free function.
stage_program
The Python a multi-file project pastes. It writes every staged file through open(..., 'wb'), creating the directories the path needs, then runs the entry file in the REPL’s own globals so __name__ stays __main__.