I completely agree with the answer of Martijn Pieters.
Stack snippets run entirely in the browser. You can't run Python in everyone's browser, not the CPython (main) implementation.
Sometimes we need to demonstrate some code that does not require OS-bound kinds of stuff or drivers. The PyScript with help of Pyodide gives the ability to run Python code in a browser.
PyScript is a meta project that aims to combine multiple open technologies into a framework that allows users to create sophisticated browser applications with Python. It integrates seamlessly with the way the DOM works in the browser and allows users to add Python logic in a way that feels natural both to web and Python developers.
Yes, it cannot run threads, processes, or sockets and has limitations, but it can execute such third-party libraries as Beautiful Soup, Bokeh, Matplotlib, Natural Language Toolkit (NLTK), NumPy, Pandas, Pillow, SciPy, SQLAlchemy, scikit-learn, etc.
Pyodide uses WebLoop as the main event loop so that we can execute asynchronous functions as well.
import asyncio
import numpy as np
async def func():
for i in range(2, 7):
await asyncio.sleep(.5)
print(np.random.randint(i, size=10))
loop = asyncio.get_event_loop()
loop.run_until_complete(func())
<script src="https://cdn.jsdelivr.net/gh/pysnippet/pysnippet@latest/snippet.min.js"></script>
As you can see, it is enough to add the PySnippet CDN as an external library and run a Python snippet.
Also, note that I have used NumPy without installing it as the PySnippet has been made to solve the auto setup of initialization requirements for easy use.