4 ms·
I'd also love to try PGlite in Python. While reading this thread, I realized that you could already access PGlite in Pyodide. Pyodide is a Wasm port of CPython
by networked 2y ago
I'd also love to try PGlite in Python.
While reading this thread, I realized that you could already access PGlite in Pyodide.
Pyodide is a Wasm port of CPython.
It can work with JavaScript objects through proxies.
Here is a demo.
I have run the code in current Node.js 18, Deno 1, and Bun 1.
import { PGlite } from "@electric-sql/pglite";
import { loadPyodide } from "pyodide";
globalThis.db = new PGlite();
let pyodide = await loadPyodide();
console.log(
await pyodide.runPythonAsync(`
import js
ret = await js.db.query("""
SELECT 'Hello, world!'
AS "greeting";
""")
ret.rows[0].greeting
`),
);
It works on my machine:
> npm init -y
> npm install '@electric-sql/pglite@==0.2.0'
> npm install 'pyodide@==0.26.2'
> node index.mjs
prerun(C-node) worker= false
Running in main thread, faking onCustomMessage
Hello, world!