0.1.3 • Published 11 months ago

slidev-addon-python-runner v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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 https://github.com/pyodide/pyodide/issues/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.

0.1.3

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago