I'd seen this running in a browser before (the ~3MB download is really impressive for that), but I hadn't clocked that it runs server-side with Node.js and Bun as well: https://pglite.dev/docs/
Since that's still not spinning up an actual network server, that feels like it's an alternative to SQLite - you can spin up a full in-process PostgreSQL implementation, that persists to disk, as part of an existing Node.js/Bun application.
That's really interesting!
I'd love to use this from Python, via something like https://github.com/wasmerio/wasmer-python or https://github.com/bytecodealliance/wasmtime-py - has anyone run PGlite via one of those wrappers yet?
Getting PGlite working with other languages is very high on my list. We are working on two approaches:
- a WASI build with a lower level api that users can wrap with a higher level api.
- a "libpglite" that can be linked to by any native language. The WASI build is likely a WASM build of this.
Most languages already have a Postgres wire protocol implementation and so wrapping a low level API that reads/emits this is relatively easy - it's what the JS side of PGlite does.
I'd love to see this for SQLite and DuckDB at the same time. I could see them using a common wasi filesystem shim so they can transparently do range requests over http blobs.
Do you have a branch for this work?
No branch yet, we're still in the early research and experimental stage.
If you can make it work with Rust, and compatible with wasm targets as well, it opens a huge field of possibilities.
Windmill.dev is a workflow engine based fully on postgresql. This would be the missing piece to offer a local development workflow that doesn't require spinning a full pg.
As a workaround, maybe something like this could work:
db.js:
main.py:We have the (accidentally undocumented) execProtocolRaw api that lets you execute Postgres wire protocol messages. If you use that you can then use a Python Postgres wire protocol lib to get all the type support.
Definitely interesting... maybe someone more familiar with the licenses involved can chime in on how this might impact a project/solution and compare/contrast to something like embedded FirebirdSQL.
For example, can you use this in/with a commercial project without releasing source? If you embed this, will you need to change your license to match pg/fb?
aside: Mostly asking out of curiosity if anyone knows already, if I actually had an immediate need, would be reviewing this of my own accord. I often dislike a lot of the simplicity behind SQLite in very similar ways as to things I don't care for with MySQL/MariaDB.
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.
It works on my machine: