= """
code_str import numpy as np
np.random.randint(10, size=5)"""
TIL that it’s possible to embed a live REPL on a website. This is possible thanks to JupyterLite.
You can write some code:
You can use urllib.parse.quote
, which handles special characters as needed for URLs:
import urllib.parse
= urllib.parse.quote(code_str) code
Then you can then use the public facing https://jupyterlite.github.io/demo/repl as an example and embed a live REPL on a website:
from IPython.display import IFrame
f"https://jupyterlite.github.io/demo/repl/index.html?toolbar=1&kernel=python&promptCellPosition=left&code={code}&execute=0", width=850, height=200) IFrame(
There are several configuration options.
I find this very cool especially for writing tutorials and blog posts.