Pyodide for LiaScript: Run Python Directly in Your Course

Pyodide for LiaScript: Run Python Directly in Your Course

Python is the most widely taught programming language in the world. With the Pyodide template, you can bring it directly into your LiaScript course — executable, editable, and fully browser-based.

No server, no Jupyter notebook to maintain, no student setup required. Just import the template, write Python code blocks, and your course runs Python live in the browser via WebAssembly.


What is Pyodide?

Pyodide is a full port of CPython to WebAssembly. It runs a complete Python interpreter inside the browser — no backend, no connection to a remote Python server.

Scientific libraries like numpy, matplotlib, scipy, and pandas are supported and load automatically on first use. The first execution of a new library takes a few seconds while it downloads; afterwards the browser caches it.

The LiaScript Pyodide template wraps this into two simple macros that work directly with LiaScript code blocks.


Quick Start

Add this line to your course header:

<!--
import: https://raw.githubusercontent.com/LiaTemplates/Pyodide/master/README.md
-->

That’s it. Both macros are now available in your document.


Editable Code: @Pyodide.eval

The primary macro turns any Python code block into a live, editable Python interpreter. Learners can modify the code, run it, and see the output immediately — without leaving the course page.

``` python
import sys

for i in range(5):
    print("Hello", "World #" + str(i))

sys.version
```
@Pyodide.eval

Try it live:


Hidden Execution: @Pyodide.exec

@Pyodide.exec runs Python code without showing the editor to the learner. Only the output is visible.

This is useful for pre-loading state, computing results in the background, or showing live output without distracting boilerplate:

@Pyodide.exec(`import sys
result = [x**2 for x in range(1, 6)]
print("Squares:", result)
print("Python:", sys.version)`)

Scientific Libraries: numpy and matplotlib

Pyodide automatically downloads any missing package when first referenced. Standard scientific libraries work out of the box:

``` python
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2 * np.pi, 200)
y = np.sin(x)

fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_title("Sine Wave")
ax.set_xlabel("x")
ax.set_ylabel("sin(x)")

plt.show()
```
@Pyodide.eval

Note: Use plt.show() as the last line — the template intercepts this call and renders the figure as an inline image in the course.

Try it live:


Full Template Demo

The full Pyodide README is itself a self-documenting LiaScript course — explore all features and examples live:


Use Cases

Introductory programming courses — Run Python from the very first lesson. No environment to install, no “it works on my machine” problems. Students open the course URL and start coding immediately.

Data science educationnumpy, pandas, matplotlib, and scipy are all available. Students can run data analysis exercises, plot results, and explore datasets — entirely in the browser.

STEM and physics courses — Combine Python code with LiaScript’s interactive elements. Use sliders, surveys, and quiz blocks alongside live Python simulations.

Assessment and exercises — Use @Pyodide.exec for hidden setup code, then present editable problems for learners to complete and run themselves.

OER and accessibility — Because Python runs in the browser and course sources are plain Markdown, your material is version-controllable, forkable, and platform-independent.


Technical Facts

Runs in browserYes — WebAssembly (WASM), no backend
Python versionCPython via Pyodide 0.29
Scientific librariesnumpy, matplotlib, scipy, pandas — auto-downloaded
External dependencyPyodide runtime loaded from CDN on first use
Offline capableAfter first load (browser cache)
Interactive editingYes, with @Pyodide.eval
stdin supportYes — via browser prompt()
LicenseMIT
MaintainedYes — last update April 2026

Try It

Try in LiaScript Open in LiveEditor View on GitHub
  • CodeRunner — server-side execution for 20+ languages including Python, Java, C, and Ruby
  • MicroBit-Simulator — MicroPython in the browser for BBC micro:bit simulations
  • JSCPP — C++ interpreter running entirely in the browser, no server needed
  • SQLite — SQL databases and queries directly in the browser

Related Posts

MicroBit-Simulator for LiaScript: Teach MicroPython Without a Physical Device

Simulate a BBC micro:bit and run MicroPython code directly inside your LiaScript course — no hardware, no server, just a browser.

Read More

AlaSQL for LiaScript: Teach SQL and Query CSV Data in the Browser

Use the AlaSQL template to run SQL queries directly inside LiaScript courses — with support for CSV data, JSON, and JavaScript arrays. No server, no setup.

Read More

CodeRunner for LiaScript: Execute Code in 50+ Languages Server-Side

Run Python, Java, C, C++, Ruby, Rust, Go, Haskell, and 40+ more languages directly inside LiaScript courses via a server-side code runner — no browser limitations, real compilers.

Read More