PythonProgramming
Some examples on how to use Python in LiaScript
Install / Use
/learn @LiaPlayground/PythonProgrammingREADME
Python Programming
If you want to teach Python or at least run some Python snippets within your course, we currently recommend two different packages for LiaScript.
What is the difference? Pyodide will load all libraries into your browser and execute it locally, while CodeRunner will compile and execute the code on a foreign server. The first project might cover only a reduced set of libraries, but it scales and adds plotting functionality, in contrast to the second one. In CodeRunner, plots can at the moment only be generated with R.
1. Pyodide
To use this functionality, you will have to import:
<!-- ... import: https://github.com/LiaTemplates/Pyodide/blob/0.1.4/README.md -->Afterwards you can attach the macro
@Pyodide.evalto every Python-Code snippet.Note: All scripts are executed in one global environment
Examples
import sys
for i in range(5):
print("Hello", 'World #', i)
sys.version
@Pyodide.eval
Currently you can only plot one image, but this is shown within the terminal and also stored persitently. Thus, you can switch between different versions of your code and the resulting images will change too.
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(t, s)
ax.grid(True, linestyle='-.')
ax.tick_params(labelcolor='r', labelsize='medium', width=3)
plt.show()
plot(fig) # <- this is required to plot the fig also on the LiaScript canvas
@Pyodide.eval
NOTE: You can resize the terminal and you can click onto the image to enlarge it. The additional loading of libraries is only required once, then they are stored locally...
2. LiaScript Code-Runner
This allows, to run and execute your code on a real
<!-- ... import: https://github.com/LiaScript/CodeRunner/blob/master/README.md --> # ... ```python for i in range(10): print "Hallo Welt", i ``` @LIA.eval(`["main.py"]`, `python -m compileall .`, `python main.pyc`)Afterwards you can attach the macro
@LIA.evalto every Python-Code snippet.The
@LIA.evalmacro might look a bit cryptic, but it actually consists of three steps.
- A list of filenames, if you use require more than one files for your project, then these have to be defined in order. A project can consist of multiple code-snippets attached to each other
- A compilation command
- A execution command
Example
for i in range(10):
print "Hallo Welt", i
@LIA.eval(["main.py"], python -m compileall ., python main.pyc)
Best Practice
If you you have a couple of code-snippets and you do not want to add always the same complex macro, which might eventually change in the future. The best way is to define a custom macro, which defines the macro with all parameters. You can modify this in the future, just by changing the macro-definition an also the import. It is thus not required to change every macro separately:
<!--
...
import: https://github.com/LiaTemplates/Pyodide/blob/0.1.4/README.md
https://github.com/LiaScript/CodeRunner/blob/master/README.md
@@ can also be replaced by @Pyodide.eval
@eval: @LIA.eval(`["main.py"]`, `python -m compileall .`, `python main.pyc`)
-->
# ...
```python
for i in range(10):
print "Hallo Welt", i
```
@eval
```python
for i in range(10):
print "Hello World", i
```
@eval
for i in range(10):
print "Hallo Welt", i
@eval
for i in range(10):
print "Hello World", i
@eval
Related Skills
node-connect
350.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
claude-opus-4-5-migration
109.9kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
109.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
model-usage
350.1kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
Security Score
Audited on Dec 25, 2025
