Embed live REPL on a website

code
Author

Alonso Silva

Published

June 15, 2025

TIL that it’s possible to embed a live REPL on a website. This is possible thanks to JupyterLite.

You can write some code:

code_str = """
import numpy as np

np.random.randint(10, size=5)"""

You can use urllib.parse.quote, which handles special characters as needed for URLs:

import urllib.parse

code = urllib.parse.quote(code_str)

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

IFrame(f"https://jupyterlite.github.io/demo/repl/index.html?toolbar=1&kernel=python&promptCellPosition=left&code={code}&execute=0", width=850, height=200)

There are several configuration options.

I find this very cool especially for writing tutorials and blog posts.