Documentation > User Manual > MicroPython (mpy)
LugalOS includes MicroPython v1.24.1 (mpy.elf), running as an isolated user-mode (U-mode) ELF program with software 32-bit floating-point, math, json, uasyncio, urequests (HTTP and HTTPS), mip, and native bindings for LugalOS sensors, canvases, UI widgets, and hardware buses.
Run Python from the lsh> shell using either mpy or python (they invoke the same /sd0/system/bin/mpy.elf or /flash0/system/bin/mpy.elf binary):
# Interactive REPL (Ctrl-D to exit)
lsh> python
# Evaluate an expression or statement (-c)
lsh> mpy -c print(1+2,1/2)
3 0.5
# Run a script file
lsh> mpy /sd0/demos/sensor_log.py
# Run a frozen or installed module by name (-m)
lsh> mpy -m mip install pkg
Note
The lsh> shell splits command lines on spaces. For one-liners with spaces inside -c, wrap the code in exec("...\\x20...") or put your script in a .py file on /sd0/ or /ram0/.
- Core & Math:
sys,os,time,gc,math,cmath(not enabled),json,re,struct,binascii,hashlib(sha256),random,collections,io. - Async & Networking:
uasyncio(frozen),asyncio,select,socket,urequests(frozen, supports HTTP & HTTPS via LugalOS TLS 1.3),mip(frozen package installer). - LugalOS Hardware & UI:
lugal(lugal.sensor,lugal.canvas,lugal.ui,lugal.chan,lugal.http_request),machine(machine.I2C,machine.Pin).
Two ready-to-run Python demos ship on /sd0/demos/:
- Async Sensor Logger (
/sd0/demos/sensor_log.py): Usesuasyncio,lugal.sensor, andjsonto sample all detected environmental sensors (or a simulated reading when none are attached) and append JSON Lines to/nvme0/sensor_log.jsonl(VisionFive 2) or/sd0/demos/sensor_log.jsonl. - Live Canvas Chart (
/sd0/demos/canvas_chart.py): Opens a graphical canvas vialugal.canvasand plots live sensor telemetry on display-equipped boards.
MicroPython searches sys.path in order:
.frozen(built-in frozen modules:uasyncio,urequests,mip)/nvme0/lib/python(VisionFive 2 NVMe SSD)/sd0/lib/python(MicroSD card)/flash0/lib/python(on-board flash)
On networked boards, install pure-Python packages directly to /sd0/lib/python (or /nvme0/lib/python if mounted) with mip:
lsh> mpy -m mip install pkg-or-url
- Python Scripting &
lugal.*API Reference -- full API documentation forlugal.sensor,lugal.canvas,lugal.ui,lugal.chan,machine, andsocket. - HTTPS Certificates & Root Trust Stores -- how
/sd0/system/etc/ssl/roots.bin(public Mozilla roots) relates tohost/ca(/dev/tlsca, private CA). - Shell & Command Environment -- running ELF programs and backgrounding tasks.