diff --git a/docs/usage/pyodide.md b/docs/usage/pyodide.md
index 3077a92..8953b86 100644
--- a/docs/usage/pyodide.md
+++ b/docs/usage/pyodide.md
@@ -33,6 +33,18 @@ cowsay.cow("Hello World")
Packages installed with Micropip are cached by the browser as well,
making future installations much faster.
+## Pyodide version
+
+You can select a specific Pyodide version with the `version` option:
+
+````md
+```pyodide version="0.26.4"
+print("Hello.")
+```
+````md
+
+NOTE: **All Pyodide blocks on the same page should use the same version!**
+
## Sessions
Editors with the same session share the same `globals()` dictionary,
diff --git a/src/markdown_exec/formatters/pyodide.py b/src/markdown_exec/formatters/pyodide.py
index 7620999..f6e3f86 100644
--- a/src/markdown_exec/formatters/pyodide.py
+++ b/src/markdown_exec/formatters/pyodide.py
@@ -16,7 +16,7 @@
assets = """
-
+
"""
@@ -46,6 +46,7 @@
def _format_pyodide(code: str, md: Markdown, session: str, extra: dict, **options: Any) -> str: # noqa: ARG001
global _counter # noqa: PLW0603
_counter += 1
+ version = extra.pop("version", "0.26.4").lstrip("v")
install = extra.pop("install", "")
install = install.split(",") if install else []
exclude_assets = extra.pop("assets", "1").lower() in {"0", "false", "no", "off"}
@@ -66,4 +67,4 @@ def _format_pyodide(code: str, md: Markdown, session: str, extra: dict, **option
rendered = template % data
if exclude_assets:
return rendered
- return assets + rendered
+ return assets.format(version=version) + rendered