Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo executable examples in docs #42

Open
brettcannon opened this issue Jan 11, 2022 · 2 comments
Open

Demo executable examples in docs #42

brettcannon opened this issue Jan 11, 2022 · 2 comments

Comments

@brettcannon
Copy link
Collaborator

If we can get code examples on docs.python.org to be executable in the browser then that might be quite the boon for this project, motivation for others to get involved, and a way to make sure things don't break. 😉

@simonw
Copy link

simonw commented Jan 11, 2022

I love this idea. Relevant Twitter thread: https://twitter.com/alsweigart/status/1480623244919156741

I don't think loading Python WASM for every user who visits a documentation page is a good use of resources - either for the PSF servers or the user's browser. So instead I suggest this works by loading on-demand.

A code example might be presented as a regular syntax highlighted block of code on the page, with a "try this" button.

When clicked, that button would load the relevant Python WASM version and replace the static code block with a pre-populated interactive interpreter.

Thanks to browser caching, any subsequent clicks of that button on other pages should respond really quickly.

@thomasballinger
Copy link

Beyond some Python docs infrastructure, hooking up a web REPL to the WASM Python build, which accepts query parameters for lines of code to run ahead of time (and possibly lines of code to run invisibly to set up an environment) seems like the blocker. This should probably run in a sandboxed or separate-domain iframe to prevent user code from running arbitrary JavaScript on the Python docs page.

Some REPL like the one in the nested iframe on the front page of python.org provided by PythonAnywhere (for design inspiration, implementation may differ since that uses a websocket to a remote server) or the Pyodide REPL (see #32).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants