JavaScript library
pycorner.js: databases, APIs, AI and tunnels for plain web apps.
Web apps (plain HTML, CSS and JavaScript, uploaded as a zip, pushed from the command line or written in the editor) use the same resources as the Python apps, through pycorner.js. Import it from the app’s own origin; there’s nothing to install:
<script type="module">
import pycorner from "/pycorner.js";
const { rows, objects } = await pycorner.db("proddb").query(
"SELECT id, name FROM users WHERE active = %s", [true]);
const res = await pycorner.api("crm").get("contacts", { params: { q: "acme" } });
const contacts = await res.json();
const answer = await pycorner.ai().chat("Summarise: " + JSON.stringify(contacts));
</script>
| Call | What it does |
|---|---|
pycorner.db(name).query(sql, params) | runs SQL on a Database resource; returns {columns, rows, objects} |
pycorner.api(name).get/post/put/patch/delete(path, {params, json, body, headers}) | calls an API resource; the proxy adds its keys; returns a normal Response. Of the upstream’s headers a short list keeps its names, the others arrive as x-upstream-<name>, Set-Cookie never |
pycorner.ai(name = "llm").chat(messages, {model, temperature}) | a chat completion through the owner’s account; returns the text |
pycorner.ai(name).embed(text or [texts]) | embeddings |
pycorner.tools.list() / .call(name, args) | the viewer’s eutonomous tools, where the platform allows them |
pycorner.tunnel(name) | a WebSocket carrying raw TCP bytes through the owner’s tunnel agent |
pycorner.board(name).top() / .submit(score) / .forget() | a leaderboard the app declares in leaderboards.json |
pycorner.files.read(path) / .write(path, content) | the app’s own files; write saves into the project (string or bytes) |
pycorner.saveSelf(path = "index.html") | saves the page as it is now, for apps that keep their state in themselves |
Errors throw a PycornerError with the HTTP status.
Apps that save themselves
files.write and saveSelf work when the app was opened by somebody who may change it, in the editor; each save is a version in the project’s history, under their name, and a save fails with 412 if the file changed since it was opened. A TiddlyWiki (New project → Web app → TiddlyWiki) needs none of this: its own Save button finds the app’s address accepts saves (WebDAV PUT) and uses it. Visitors’ copies can’t save.
How it’s allowed
Every web app runs on the apps origin (apps.pycorner.dev, csr-apps.eutonomous.eu), away from the sign-in. Its address carries a short-lived token for that one app (/w/<app>/<token>/), and pycorner.js sends it with each call. The token opens only the resources the app’s owner made for it under Resources, and nobody’s password or key is ever in the page. When the owner’s account limits outside domains (an egress policy), the browser enforces it for web apps too.
A public web app can also be embedded in another website: it then runs at /embed/<app>/<token>/, with a token that names nobody, and pycorner.js works the same.