Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

pyodide 🀝 deno

trick pyodide to execute python code in the deno runtime

deno module source: py-town

not all python packages are supported by pyodide

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { runPythonCode } from "https://deno.land/x/py_town@v0.0.2/mod.ts";
export default async function handler(req: Request): Promise<Response> {
const pythonCode = `
import numpy as np
def greet(name):
message = f"Hello, {name}! Welcome to Val Town."
name_length = len(name)
reversed_name = name[::-1]
additional_info = f"Your name has {name_length} characters and reversed it is '{reversed_name}'."
# numpy
array = np.array([1, 2, 3, 4, 5])
array_sum = np.sum(array)
numpy_info = f"The sum of the array [1, 2, 3, 4, 5] is {array_sum}."
return f"{message} {additional_info} {numpy_info}"
result = greet("Val Town")
result
`;
const result = await runPythonCode(pythonCode);
const htmlContent = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pyodide 🀝 Deno</title>
</head>
<body>
<h1>Python Execution Result</h1>
<div id="result">${result}</div>
</body>
</html>
`;
return new Response(htmlContent, {
headers: {
"Content-Type": "text/html",
},
});
}
iamseeley-pythonhttpval.web.val.run
May 20, 2024