1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// One key catch is to statically import the pyodide.asm.js file, because otherwise
// pyodide would try to import it dynamically from a template string,
// which Deno Deploy does not support at the moment.
import "https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.js"; // Statically import the pyodide WASM file
// hacks for tricking pyodide into thinking it's running on browsers
// @ts-expect-error
globalThis.document = {};
// @ts-expect-error
globalThis.location = new URL(import.meta.url);
// Load pyodide ESM
const { loadPyodide } = await import("https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.mjs");
const pyodide = await loadPyodide();
const result = await pyodide.runPythonAsync(`
x = 'world'
f'Hello {x}'
`);
console.log("result:", result.toString());