Execute Node JS script with PythonShell in Cloudflare Worker


We have a Node JS script which includes a call to PythonShell to also run a Python script. If we want to migrate this to Cloudflare Workers, is this possible? I saw that Cloudflare Workers only support Javascript at the moment, so in our case, how would our call to PythonShell be run?

Thank You!

1 Like

Short answer is: It wouldn’t.
Long answer: Cloudflare Workers run as Isolates using the V8 Engine. They are not containers or isolated processes. You cannot run other processes, and a lot of node.js libraries are incompatible in general due to Workers running on V8 (same Javascript engine as Chrome, so a “Browser-like environment”). There is a node compat mode, but it’s not going to let you use modules like spinning off other processes/child processes, or use any node.js modules like node:net.

Workers can run WASM and any language that compiles to Javascript. There is an example project that compiles Python to Javascript, but it’s limited. There is a 5 MB worker file size limit (on paid) that makes it hard to run other languages that are compiled to WASM like .net/python, as well as CPU time execution limits (on bundled, unbound pricing removes that, but more expensive, start up time is another consideration, and there are still other limits with how long your unbound worker will run for before potentially being evicted, etc).

The advantage to this all is Workers are extremely fast, no cold start times, run at every one of Cloudflare’s 285+ cities, no need to worry about scaling or anything more than just creating the code to run.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.