py-pglite
Python testing library for PGlite - in-memory PostgreSQL for tests
What it is and what it does
py-pglite is a Python wrapper around PGlite that spins up an in-memory PostgreSQL instance for testing, eliminating the need for Docker containers, server configuration, or test database management. It works with any PostgreSQL client library—SQLAlchemy, Django ORM, psycopg, asyncpg—and provides pytest fixtures that give each test a fresh, isolated database. The core appeal is speed and simplicity: startup in seconds rather than minutes, and no external dependencies beyond psutil.
The package supports both Unix domain sockets (default, fastest) and TCP sockets (required for asyncpg and cloud environments). It also exposes PGlite extensions like pgvector for vector search testing. Configuration is minimal—most tests work with a single fixture—but advanced users can customize timeouts, logging, cleanup behavior, and socket modes via PGliteConfig.
Use it for:
- Unit testing SQLAlchemy or Django models without spinning up a real PostgreSQL server or Docker container.
- Testing FastAPI or other web frameworks that depend on a database, with automatic per-test isolation.
- Validating complex SQL queries, window functions, and JSON operations in CI/CD pipelines where Docker is unavailable or slow.
- Testing vector similarity search and RAG applications using pgvector extension in isolated test environments.
- Rapid local development and debugging of database-heavy code without managing a persistent PostgreSQL instance.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
py-pglite provides a zero-config PostgreSQL testing environment for Python by wrapping PGlite, letting you run real PostgreSQL queries in tests without Docker or server setup.
Yes, if you test Python code that uses PostgreSQL and want to eliminate Docker or server setup overhead. The low install friction, permissive license, and broad client library support make it a straightforward drop-in for pytest suites. Caveat: the package is in beta and aging (no release in 331 days), so verify that PGlite's feature set covers your specific PostgreSQL extensions and that performance meets your test suite's needs before committing to production CI/CD.
Install
py-pglite on PyPI
pip
pip install py-pgliteuv
uv add py-pglitepoetry
poetry add py-pgliteInstalling py-pglite
Before you install
Low friction: pure Python wheel with only psutil as a runtime dependency. Maintenance status is aging—last release was 331 days ago, though the repo remains active with recent commits and moderate community interest (632 stars).
License in practice
Apache-2.0 permissive license allows use in commercial and open-source projects with minimal restrictions; you must include a copy of the license and note any modifications.
Quickstart
pip install py-pglite
from py_pglite import PGliteManager
with PGliteManager() as db:
dsn = db.get_dsn()
# Use dsn with any PostgreSQL client (SQLAlchemy, psycopg, etc.)
Requires Python 3.10 or later; asyncpg users must enable TCP mode via PGliteConfig(use_tcp=True).
Verify before relying
- Whether PGlite's feature set (JSON, arrays, window functions) covers your specific PostgreSQL extensions or advanced SQL features.
- Performance characteristics and memory footprint when running large test suites or complex queries.
- Compatibility with all Django ORM patterns and edge cases beyond the documented socket and backend patterns.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — psutil |
| Maintenance | aging — 331 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 120,186/month — #12,041 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: py_pglite-0.5.3-py3-none-any.whl
Keywords: testing, postgresql, pglite, database, pytest, sqlalchemy, sqlmodel, django, pytest-django
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
pg0-embeddedEmbeds a PostgreSQL database directly in Python…
permissive · top 15,000 on PyPI
PyPgConfigPyPgConfig detects and exposes PostgreSQL…
permissive · top 15,000 on PyPI
pytest-pgsqlA pytest plugin that provides fixtures for…
permissive · top 15,000 on PyPI
pytest-postgresqlA pytest plugin that provides fixtures to…
copyleft · top 5,000 on PyPI
testcontainers-postgresProvides a PostgreSQL Docker container wrapper…
unclear · top 15,000 on PyPI
testing.postgresqlAutomatically creates and tears down temporary…
permissive · top 5,000 on PyPI
pgserverEmbeds a PostgreSQL server with pgvector…
unclear · top 15,000 on PyPI
pytest-databasesProvides pytest fixtures that spin up isolated…
permissive · top 15,000 on PyPI
pg8000pg8000 is a pure-Python PostgreSQL driver that…
permissive · top 1,000 on PyPI
pytest-mock-resourcesProvides pytest fixtures that spin up real…
permissive · top 15,000 on PyPI