Experimental Pyodide fork which works in Cloudflare Workers
MPL-2.0 License
This repo holds a proof of concept fork of Pyodide which implements support for Cloudflare Workers. The implementation right now is somewhat hacky but it does function and allows you to use libraries like Pillow and matplotlib on Workers.
To play around with it visit https://pycloud.picheta.me, or clone this repo and follow the "Running" section below.
I wouldn't recommend using this in production as it stands right now. For an alternative way to use Python on Workers (which is more official) check out this template.
⚠️ You need a Workers Paid plan in order to run this on your account, otherwise you may see "CPU exceeded" errors. You'll also need
wrangler
.
$ git clone https://github.com/dom96/pycloud
$ cd pycloud/pycloud
$ npm start
Below are some code samples that are known to run well inside this implementation.
from PIL import Image
img = Image.new(mode="RGB", size=(800, 600), color=(231, 136, 59))
img.save("/result.png")
This does work, but the WASM files are too big to be uploaded to prod.
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('Agg')
fig, ax = plt.subplots( nrows=1, ncols=1 ) # create figure & 1 axis
ax.plot([0,1,2], [10,20,3])
fig.savefig('/result.png') # save the figure to file
plt.close(fig) # close the figure window