Skip to content

KermanX/slidev-addon-python-runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slidev-addon-python-runner

Python runner for the Monaco Runner feature in Slidev. Code executed in browser using Pyodide.

Demo

Usage

Firstly, install the package:

npm install slidev-addon-python-runner

Then, add it as an addon in your headmatter in slides.md:

---
addons:
  - slidev-addon-python-runner

# Optional configuration for this runner
python:
  # Install packages from PyPI. Default: []
  installs: ["cowsay"]

  # Code executed to set up the environment. Default: ""
  prelude: |
    GREETING_FROM_PRELUDE = "Hello, Slidev!"

  # Automatically load the imported builtin packages. Default: true
  loadPackagesFromImports: true

  # Disable annoying warning from `pandas`. Default: true
  suppressDeprecationWarnings: true

  # Always reload the Python environment when the code changes. Default: false
  alwaysReload: false

  # Options passed to `loadPyodide`. Default: {}
  loadPyodideOptions: {}
---

To add an interactive Python code runner, use the monaco-run directive:

```py {monaco-run}
from termcolor import colored

print(colored("Hello, Slidev!", "blue"))
```

Bundle pyodide

By default, when building slides (i.e. slidev build), the pyodide package will be replaced with the CDN version. This is because of pyodide/pyodide#1949, which causes the imported python packages to be lost when using the bundled version.

To bundle the local version of pyodide, set the PYODIDE_BUNDLE environment variable to true. Note that in this way you can't import python packages in the static build.

About

A Slidev addon for running Python code in your slides.

Topics

Resources

License

Stars

Watchers

Forks