Shared tables and files

Collect form answers, count seats, share a list or approve requests: declare a table in tables.json. Turn a spreadsheet or an Access database into an app. Keep files in the visitor's browser.

An app can keep small tables of rows on the server that everybody who opens it shares: the answers to a survey, the seats of an event, a team’s inventory, requests waiting for approval, the votes of a poll. You decide who may add, read and change rows.

Declare the tables

Add a file tables.json to the project:

{
  "responses": {"add": "anyone", "read": "editors", "change": "editors"},
  "seats":     {"add": "anyone", "read": "editors", "change": "editors", "limit": 40},
  "requests":  {"add": "signed_in", "read": "own", "change": "editors"},
  "inventory": {"add": "editors", "read": "anyone", "change": "editors"}
}
RuleValues
addanyone, signed_in, editors
readanyone, signed_in, own (each person their own rows; editors all), editors
changeeditors, own (the row’s author, and editors): updating and removing
limitthe most rows, a capacity; a full table refuses new rows
oncetrue: one row per signed-in person
keep_daysrows are deleted this many days after they came (checked every night): keep answers only as long as you need them

Editors are the people who may change the app: you, and the people you share it with as editors. Only tables named in the file exist, and the rules come only from the file.

A visitor who isn’t signed in and adds to an anyone table passes a bot check first: a second of work in their browser, done for you by the library. No captcha, no third party.

A row is a JSON object of up to 64 KB. The rest depends on the plan of the app’s owner:

PlanTables per appRows per tableRows in all, per app
Free21,0005 MB
Pro1050,00025 MB
Team1050,000100 MB

Rows already kept stay when a plan ends; new ones wait until there is room again.

Rows are stored encrypted, with a key for each table, and every export or deletion in the Data panel is written to the project’s activity and your organisation’s audit log.

Use them

In a web app:

import sdk from "/sdk.js";           // the same as /pycorner.js

const t = sdk.table("responses");
await t.add({ name: "Ada", rating: 5 });
const { rows, next, count } = await t.list({ limit: 100 });
await t.update(rows[0].id, { status: "done" });
await t.remove(rows[0].id);
const { full, can } = await t.info();   // can.read && can.change: show the editors' screen

In Streamlit, marimo, Jupyter or PyScript:

import pycorner
t = pycorner.table("responses")
t.add({"name": "Ada", "rating": 5})
for row in t.all():
    print(row["data"])

Each row comes as {id, data, created, updated, mine, author}. author is a name, and only editors get it.

Keep the rows in your own database

For data that must stay in your building: name one of your database resources (Resources → Database) in tables.json, and the rows live there instead of on our servers.

{
  "$store": "office-db",
  "responses": {"add": "anyone", "read": "editors"}
}

"$store" applies to every table; "store" on one table sets it for that table only. The rules, the bot check and the capacity still work the same; the app’s code doesn’t change.

Without a connection

On a train, in a basement, at an event with weak Wi-Fi: add, update and remove keep what they can’t send in the browser and send it by themselves when the connection is back, also on the next visit. Nothing is lost and nothing is sent twice.

const row = await t.add({ rating: 5 });
if (row.queued) showNote("Saved here; it is sent when you're back online.");

sdk.outbox.on((e) => {          // e.type: "queued" | "sent" | "failed"; e.pending: how many wait
  if (e.type === "failed") alert(`Not sent: ${e.error.message}`);   // e.g. the event is full
});
await sdk.outbox.pending();      // how many wait

What waits is encrypted with a key for this app and this person, so neither another app nor the next person on a shared computer can read it. Pass {queue: false} where the answer must be confirmed now (a seat at an event): you get the error instead.

A copy that stays in sync

For lists people keep working on (stock, a checklist, a team’s tasks), keep a copy of the table in the browser. It opens at once, also offline, shows changes that wait as if they were sent, and fetches only what changed since the last time.

const copy = await sdk.table("stock").mirror({ onChange: (rows) => draw(rows) });
draw(copy.rows);                          // newest first
await copy.update(id, { count: 4 });       // offline too
await copy.refresh();                      // fetch the changes now (otherwise every 15 seconds)

When two people change the same row, each change merges the fields it names, in the order they reach the server; a removal wins. The copy holds what this person may read, nothing more.

See and export the data

Open the app’s Share dialog: under Data you see every table, its rules and rows, export it as CSV, and remove one row or all of them.

Turn a file into an app

New project → Import a file takes an Excel workbook, an OpenDocument sheet, a CSV, an Access database (.accdb, .mdb) or a SQLite file. The file is read in your browser. You choose the tables and columns to keep, check the type of each column, and where the rows live:

You get a Records app: a list per table with search, filters and saved views, a form per row, links between tables, import and export, and a Design mode to change tables and fields.

Files in the visitor’s browser

For “bring your own file” tools, keep the file on the visitor’s device:

const [picked] = await sdk.local.pick({ accept: ".xlsx,.csv" });
const file = await sdk.local.file(picked.name);    // a File, again on the next visit
await sdk.local.save("notes.json", JSON.stringify(notes));
await sdk.local.list(); await sdk.local.remove("notes.json");

The files stay in that browser, encrypted with a key only this app gets, so no other app on the same address can read them. They survive a reload, not a cleared browser or another device: offer a backup download where it matters. Opening them needs a connection once; then the page works offline.

Settings and your brand

await sdk.settings() gives {config, brand}: the app’s app.config.json, and, for an app installed from the marketplace, the install’s settings and the storefront’s name, logo and colour. The templates use it, so a partner’s copy shows the partner’s brand without a code change.