Pyodide-compatible Beancount wheels (v2/v3) and a small installer wrapper
npm install beancount-wasmThis package ships Pyodide-compatible Beancount wheels for v2 and v3 and a tiny
wrapper to install them into a Pyodide runtime.
``js
import { createBeancountRuntime } from "beancount-wasm/runtime";
const { pyodide } = await createBeancountRuntime({
version: "v3",
// Optional: override the base URL for Pyodide assets.
// The base URL must contain pyodide.mjs and follow the same layout as
// https://cdn.jsdelivr.net/pyodide/v0.25.1/full/
// pyodideBaseUrl: "https://cdn.jsdelivr.net/pyodide/v0.25.1/full/",
});
const result = await pyodide.runPythonAsync(
from beancount import loader
entries, errors, options = loader.load_string("2024-01-01 open Assets:Cash USD")
len(entries));`
console.log(result);
Options:
- version: "v2" or "v3" (aliases: "2", "3", default: "v3")pyodideBaseUrl
- : base URL for Pyodide assets (defaults to jsDelivr)wheelBaseUrl
- : base URL for wheels (defaults to jsDelivr npm CDN)deps
- : override Beancount dependency installationpythonPackages
- : extra Python packages to install via micropip after Beancountinline
- : "auto" | "prefer" | "only" | "off" (default: "auto")auto
- : try URL first, fallback to inline on failureprefer
- : try inline first, fallback to URLonly
- : inline onlyoff
- : URL onlyonStatus
- : optional status callback
Example forcing inline-only mode:
`js
import { createBeancountRuntime } from "beancount-wasm/runtime";
const { pyodide } = await createBeancountRuntime({
version: "v2",
inline: "only",
});
`
(minus pyodideBaseUrl).$3
Creates a file tree helper for the Pyodide FS. Each file entry is
{ name, content } where name is relative to root.The returned helper exposes:
-
update(files): incremental writes for new/changed files
- remove(names): delete files by name
- reset(files): replace the tree to match the provided listExample:
`js
import { createFileTree } from "beancount-wasm/runtime";const fileTree = createFileTree(pyodide, { root: "/work" });
fileTree.update([{ name: "main.bean", content: "2024-01-01 open Assets:Cash" }]);
fileTree.remove(["old.bean"]);
fileTree.reset([{ name: "main.bean", content: "..." }]);
`$3
Returns the URL used for the selected wheel.$3
Returns { version, filename, deps } for the selected Beancount version.Wheel assets
The wheels live under
wheels/v2/ and wheels/v3/ within the package. When
serving in the browser, these files must be available over HTTP unless you rely
on the built-in inline fallback (inline: "auto").Exports
This package exposes subpath exports only:
-
beancount-wasm/runtime
- beancount-wasm/v2
- beancount-wasm/v3
- beancount-wasm/inline/v2
- beancount-wasm/inline/v3Version-specific entry example:
`js
import { createBeancountRuntime } from "beancount-wasm/v3";const { pyodide } = await createBeancountRuntime();
``