Brief Review of PyScript on WordPress
Anaconda has introduced PyScript at PyCon US 2022. It enables client-side execution of Python codes in web browsers, and they say it is already compatible with Numpy, Pandas, and other third-party modules. I gave it a quick try on WordPress.
Environment
- WordPress 5.9.3
- Lightning 14.20.3
- Safari 15.4 or Google Chrome 101.0.4951.54
- MacOS 12.3.1
- Apple M1 Pro
Examples
The custom HTML block seems to be the best place for PyScript codes. Some simplest codes work there.
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-script>
print("Hello, world!")
</py-script>
Results
Here comes the greeting! However, PysScript looks to override the default CSS settings, and the bold headings on this page are no longer bold. Similarly, bullet points of a list are missing.
Whether they are spaces or tabs, indents raise IndentationError (as of May 5, 2022).
<py-script>
for i in range(5):
print(i)
</py-script>
Results
Numpy works, at least very partly.
<py-script output="mpl">
import numpy as np
print(f"π = {np.pi}")
</py-script>
<div id="mpl"></div>
Results
Matplotlib fails.
<py-env>
- matplotlib
</py-env>
<py-script output="mpl2">
from matplotlib import pyplot as plt
import numpy as np
x = np.linspace(0, 2 * np.pi)
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x, y)
plt.show()
</py-script>
<div id="mpl2"></div>
Results
I find PyScript incredibly exciting and promising. WordPress may need some updates to get along with it better.
One thought on “Brief Review of PyScript on WordPress”