|
| 1 | +<!doctype html> |
| 2 | +<html> |
| 3 | + |
| 4 | +<head> |
| 5 | + <meta charset="UTF-8"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 7 | + <link href="output.css" rel="stylesheet"> |
| 8 | +</head> |
| 9 | + |
| 10 | +<body class="bg-gray-400"> |
| 11 | + <header class="bg-black text-white p-6 font-bold"> |
| 12 | + MicroPython Technical Preview <div class="float-right"><a href="https://github.com/pyscript/upys" title="github" target="_blank" ><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewBox="0 0 24 24" style="fill: #FFF;width:30px"><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"></path></svg></a></div> |
| 13 | + </header> |
| 14 | + <div class="flex flex-col p-2 pt-0 content-end"> |
| 15 | + <ul style="list-style-type:none" class="p-2 flex flex-wrap text-sm font-medium text-center text-gray-800 dark:text-gray-200"> |
| 16 | + <div class="grow"></div> |
| 17 | + <li class="mr-2"> |
| 18 | + <a href="index.html" class="inline-block p-2 rounded-lg hover:text-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800 dark:hover:text-gray-300">Examples</a> |
| 19 | + </li> |
| 20 | + <li class="mr-2"> |
| 21 | + <a href="simple.html" class="inline-block p-2 rounded-lg hover:text-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800 dark:hover:text-gray-300">Simple</a> |
| 22 | + </li> |
| 23 | + <li class="mr-2"> |
| 24 | + <a href="repl.html" class="inline-block p-2 rounded-lg hover:text-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800 dark:hover:text-gray-300">REPL</a> |
| 25 | + </li> |
| 26 | + <li class="mr-2"> |
| 27 | + <a href="about.html" aria-current="page" class="rounded-lg inline-block p-2 text-blue-600 bg-gray-100 active dark:bg-gray-800 dark:text-blue-500">About</a> |
| 28 | + </li> |
| 29 | + <div class="grow"></div> |
| 30 | + </ul> |
| 31 | + <div class="overflow-y-visible p-2 bg-white dark:bg-slate-800 rounded-lg ring-1 ring-slate-900/5 shadow-xl"> |
| 32 | + <h1>PyScript Runtimes - MicroPython Technical Preview</h1> |
| 33 | + <p><a href="https://pyscript.net">PyScript</a> is an open-source platform, |
| 34 | + using |
| 35 | + <a href="https://webassembly.org/">web assembly</a> (WASM), for Python in |
| 36 | + the browser.</p> |
| 37 | + |
| 38 | + <p>Given this HTML fragment:</p> |
| 39 | + |
| 40 | +<pre><py-script> |
| 41 | +def hello(name="world"): |
| 42 | + """ |
| 43 | + Return a friendly greeting. |
| 44 | + """ |
| 45 | + return f"Hello, {name} (from PyScript)" |
| 46 | + |
| 47 | +print(hello()) |
| 48 | +</py-script> |
| 49 | +<script src="pyscript.js" type="module"></script></pre> |
| 50 | + |
| 51 | + <p>You get:</p> |
| 52 | + |
| 53 | +<py-script> |
| 54 | +def hello(name="world"): |
| 55 | + """ |
| 56 | + Return a friendly greeting. |
| 57 | + """ |
| 58 | + return f"Hello, {name} (from PyScript)" |
| 59 | + |
| 60 | +print(hello()) |
| 61 | +</py-script> |
| 62 | + |
| 63 | + <p>Why not "view-source" and see for yourself?</p> |
| 64 | + |
| 65 | + <h3>What?</h3> |
| 66 | + <p>The initial version of PyScript, demoed |
| 67 | + <a href="https://www.youtube.com/watch?v=qKfkCY7cmBQ">in a keynote address |
| 68 | + by Peter Wang</a> at PyCon 2022, built on the amazing |
| 69 | + work of the <a href="https://pyodide.org/en/stable/">Pyodide</a> |
| 70 | + project. But Pyodide isn't the only Python runtime, compiled to WASM, that |
| 71 | + could be used for this purpose.</p> |
| 72 | + |
| 73 | + <p>These pages are a technical demonstration, proof of concept and |
| 74 | + playful exploration of how PyScript may work with other scripting language |
| 75 | + runtimes. This initial work focused on the amazing work of the |
| 76 | + <a href="https://micropython.org">MicroPython</a> project (a full |
| 77 | + re-implementation of Python 3 targeting constrained computing |
| 78 | + environments).</p> |
| 79 | + |
| 80 | + <p>Here's what |
| 81 | + <a href="http://dpgeorge.net/">Damien George</a> |
| 82 | + (creator of MicroPython) says about such efforts:</p> |
| 83 | + |
| 84 | + <blockquote> |
| 85 | + <p>MicroPython was written from day one to be easy to embed, and tries to support a wide variety of targets. For example, in a minimal configuration, the only connection to the external world that it needs is a place to output characters.</p> |
| 86 | + <p>Although I never had the idea that MicroPython would be embedded in the browser, it actually fits quite naturally because MicroPython is very self contained. MicroPython's small size and efficient use of resources (RAM and CPU) means that it's well suited to being embedded in a webpage, because the download size and start-up time is minimised. It's pretty exciting to think that MicroPython could gain traction as a way to build websites.</p> |
| 87 | + </blockquote> |
| 88 | + |
| 89 | + <h3>Why?</h3> |
| 90 | + |
| 91 | + <p>Different runtimes exhibit different strengths and weaknesses. As |
| 92 | + always, there are tradeoffs.</p> |
| 93 | + |
| 94 | + <p>Whereas Pyodide is a relatively mature version of standard CPython, |
| 95 | + including powerful native modules such as |
| 96 | + <a href="https://numpy.org/">numpy</a> and |
| 97 | + <a href="https://scipy.org/">scipy</a>, it's also rather large (circa 11Mb) |
| 98 | + and slow to start up.</p> |
| 99 | + |
| 100 | + <p>Alternatively, MicroPython is a highly regarded, mature and |
| 101 | + battle tested reimplementation of Python 3 but with "micro" |
| 102 | + reimplementations of popular libraries. It is small (base 303Kb) and |
| 103 | + startup time is only a few thousandths of a second (from a warm cache), |
| 104 | + even on mobile devices.</p> |
| 105 | + |
| 106 | + <p>Given such tradeoffs, we want folks to be able to choose the runtime |
| 107 | + to use with PyScript that best suits their unique requirements.</p> |
| 108 | + |
| 109 | + <h3>How?</h3> |
| 110 | + |
| 111 | + <p>The code on these pages is experimental.</p> |
| 112 | + |
| 113 | + <p>A small, fast and simple implementation of PyScript, created for |
| 114 | + testing purposes, allows us to quickly explore the |
| 115 | + characteristics of different potential runtimes.</p> |
| 116 | + <p>This version of PyScript, simply does four things:</p> |
| 117 | + <ol> |
| 118 | + <li>Read custom configuration (more on this later), otherwise fall back |
| 119 | + to sensible defaults.</li> |
| 120 | + <li>Download and start the language runtime. Currently, this is |
| 121 | + configured to be MicroPython.</li> |
| 122 | + <li>Register and manage plugins that contain the PyScript platform's |
| 123 | + logic. Currently, there are two: one for the |
| 124 | + <code><py-script></code> tag, |
| 125 | + and one for the <code><py-repl></code> tag.</li> |
| 126 | + <li>Load user defined files onto the runtime's virtual file system (data, |
| 127 | + code, modules etc).</li> |
| 128 | + </ol> |
| 129 | + <p>Drop into the browser console to see what PyScript is doing, under the |
| 130 | + hood.</p> |
| 131 | + </div> |
| 132 | + </div> |
| 133 | +</body> |
| 134 | + |
| 135 | +</html> |
| 136 | + |
| 137 | +<script src="pyscript.js" type="module"></script> |
0 commit comments