You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!doctype html><html><head><metacharset="utf-8"/><title>RustPython Demo</title><scriptdefer="defer" src="index.js"></script><linkhref="styles.css" rel="stylesheet"></head><body><h1>RustPython Demo</h1><p>RustPython is a Python interpreter written in Rust. This demo is compiled from Rust to WebAssembly so it runs in the browser.<br>Input your Python code below and click <kbd>Run</kbd> (or <kbd>Ctrl+Enter</kbd>), or you can open up your browser's devtools and play with <code>rp.pyEval('1 + 1')</code></p><divid="code-wrapper"><selectid="snippets"><option>asyncbrowser</option><option>fetch</option><optionselected="selected">fibonacci</option><option>fizzbuzz</option><option>import_pypi</option><option>mandelbrot</option></select></div><buttonid="run-btn">Run ▷</button><divid="error"></div><h3>Standard Output</h3><textareaid="console" readonly="readonly">Loading...</textarea><h3>Interactive shell</h3><divid="terminal"></div><p>Here's some info regarding the <code>rp.pyEval()</code>, <code>rp.pyExec()</code>, and <code>rp.pyExecSingle()</code> functions</p><ul><li>You can return variables from python and get them returned to JS, with the only requirement being that they're serializable with <code>json.dumps</code>.</li><li>You can pass an options object as the second argument to the function:<ul><li><code>stdout</code>: either a string with a css selector to a textarea element or a function that receives a string when the <code>print</code> function is called in python. The default value is <code>console.log</code>.</li><li><code>vars</code>: an object that will be available in python as the variable <code>js_vars</code>. Only functions and values that can be serialized with <code>JSON.stringify()</code> will go through.</li></ul></li><li>JS functions that get passed to python will receive positional args as positional args and kwargs as the <code>this</code> argument</li></ul><p>Limited Interaction with browser is possible from Python by using the <code>browser</code> module. Browser APIs such as <code>alert()</code>, <code>confirm()</code>, <code>prompt()</code> and <code>fetch()</code> are included in the module.</p><ahref="https://github.com/RustPython/RustPython"><imgstyle="position: absolute; top: 0; right: 0; border: 0;" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_green_007200.png" alt="Fork me on GitHub"/></a></body></html>
0 commit comments