PyScript Vs. Pyodide: Which Should You Use?

Start with PyScript first if you are more of a Pythonic developer. Try Pyodide if you want to “Add some Python” to your JavaScript.

Patrick Chiu • 2022/05/10

Disclaimer: I created SkyCube.app which is a Pyodide-powered ML tool that runs entirely in the browser. Also, my opinions (as of 2022/5/10) might be outdated soon, since I have full confidence that Anaconda will advance PyScript to the next level quickly :)

Usage and Aims

pyscript

PyScript enables Python applications to leverage HTML, CSS, and JavaScript conventions, but not the other way round yet. What I mean is that you can call JavaScript functions/libraries from Python (PyScript), but you cannot call Python functions from JavaScript. It is understandable as Anaconda’s primary users are Python developers. In fact, one of the aims of PyScript is to help Python take a serious step toward making programming and data science more accessible to everyone.

pyodide

On the other hand, Pyodide comes with a robust Javascript ⟺ Python foreign function interface. You can run Python pyodide.runPython("print(x)") or even get a variable pyodide.globals.get("sys") from JavaScript. You can also import js and js.document.title = "New window title" from Python. After all, Pyodide let us freely mix these two languages in your code with minimal friction.

The Bright Side of PyScript

Clean and Simple API

PyScript does provide a clean and simple API! For instance, you can <py-script src="/todo.py"></py-script> to load your Python script. You can even import your other Python script, just like how you normally do so! While in Pyodide, you need to handle the Python script yourself and manage to put it pyodide.runPython(<here>). It is also a great convenience if we just want to output the result to an HTML element by <py-script output="altair"></py-script>, where altair is the id of an HTML element.

What's Next?

Try out some of my side projects below!

LowCMS

Instant CMS layer on top of your local JSONs
TypeScript
Svelte
File System API
Dexie.js
Sift.js

Cache Cloud

Fast serverless caching via HTTP endpoints, built on Cloudflare Workers, KV and Hono
TypeScript
Cloudflare Workers
Serverless
Hono.js
Zod