A new Python testing library called py-pglite has sparked heated discussion in the developer community about its approach to database testing. The library promises to bring PostgreSQL's full feature set to Python tests through PGlite, a WebAssembly-compiled version of PostgreSQL that runs in Node.js. However, the community is questioning whether this approach truly delivers on its promises of simplicity and performance.
Performance Claims Under Scrutiny
The library's marketing emphasizes blazing fast performance through in-memory PostgreSQL, but developers are pushing back on these claims. Critics point out that WebAssembly running inside Node.js is unlikely to outperform native PostgreSQL code that has been optimized for decades. The additional layers of abstraction - Python calling Node.js running WebAssembly - raise questions about whether this setup can truly be faster than established alternatives like TestContainers or native PostgreSQL instances.
Several community members have shared their experiences with TestContainers, reporting test execution times that seem competitive with py-pglite's promises. One developer noted that their TestContainers-based tests with PostgreSQL took only 30 seconds longer than SQLite tests, suggesting that the performance gap may not be as significant as py-pglite claims.
Performance Comparison (TestContainers vs SQLite):
- SQLite tests with Python 3.9: 3m 41s
- PostgreSQL tests with TestContainers: 4m 11s
- Difference: Only 30 seconds slower for full PostgreSQL compatibility
The Node.js Dependency Dilemma
Perhaps the most contentious aspect of py-pglite is its dependency on Node.js and automatic npm package management. The library advertises no PostgreSQL install needed as a selling point, but developers quickly noted the irony: Node.js itself is 63MB compared to PostgreSQL's 32MB. This has led to questions about whether the dependency trade-off makes sense.
I can't imagine a wasm running inside nodejs being faster than native code that's been optimised for decades. postgres is 32MB, nodejs is 63MB.
More concerning to many developers is the library's automatic installation of npm dependencies at runtime. This behavior, which is enabled by default, has raised red flags about compatibility with existing Node.js setups and security scanning tools. While the feature can be disabled, the lack of clear documentation about managing Node.js dependencies manually has frustrated potential users.
Size Comparison:
- PostgreSQL: 32MB
- Node.js: 63MB
- py-pglite requires Node.js 18+ and Python 3.10+
Alternative Solutions Gaining Attention
The discussion has highlighted several mature alternatives that developers are already using successfully. TestContainers emerged as a popular choice, offering real PostgreSQL instances in Docker containers with minimal setup overhead. Other developers mentioned pytest-docker-compose and embedded-postgres solutions that avoid the Node.js dependency entirely.
Some community members are exploring more ambitious approaches, such as compiling PostgreSQL directly into Python extensions or using WASI runtimes to eliminate the Node.js requirement. These discussions suggest that while py-pglite addresses a real need, the community sees room for improvement in the implementation approach.
Looking Forward
Despite the criticism, py-pglite has generated genuine interest for its attempt to simplify PostgreSQL testing in Python. The library's author has acknowledged the feedback and outlined plans for future versions that could address some of the current limitations, including potential support for native binaries and better dependency management.
The debate reflects a broader challenge in the Python ecosystem: balancing convenience with performance and dependency management. While py-pglite may not be the perfect solution, it has sparked valuable discussions about testing strategies and highlighted the ongoing need for better database testing tools in Python development.
Reference: py-pglite