{"id":24285,"library":"py-pglite","title":"py-pglite","description":"Python testing library for PGlite - an in-memory PostgreSQL for tests. Provides a lightweight, in-process PostgreSQL via WebAssembly (pglite-manager). Current version 0.5.3, requires Python >=3.10. Active development with monthly releases.","status":"active","version":"0.5.3","language":"python","source_language":"en","source_url":"https://github.com/wey-gu/py-pglite","tags":["postgresql","testing","in-memory","pglite","pytest","django","fastapi","sqlalchemy"],"install":[{"cmd":"pip install py-pglite","lang":"bash","label":"PyPI install"}],"dependencies":[{"reason":"Default PostgreSQL driver used by py-pglite","package":"psycopg2-binary","optional":true},{"reason":"For SQLAlchemy engine/connection integration","package":"SQLAlchemy","optional":true},{"reason":"For async PostgreSQL support","package":"asyncpg","optional":true},{"reason":"For Django test runner integration","package":"django","optional":true},{"reason":"Alternative modern driver (psycopg 3)","package":"psycopg","optional":true}],"imports":[{"note":"Package name is pglite, not py_pglite or py-pglite","wrong":"from py_pglite import PGlite","symbol":"PGlite","correct":"from pglite import PGlite"},{"note":"No alias or hyphen","symbol":"pglite","correct":"import pglite"}],"quickstart":{"code":"import pglite\n\n# Start an in-memory PostgreSQL instance\ndb = pglite.PGlite()\n\n# Get a psycopg2 connection string\nconn_str = db.get_connection_string()\nprint(conn_str)\n\n# Connect using psycopg2\nimport psycopg2\nconn = psycopg2.connect(conn_str)\ncur = conn.cursor()\ncur.execute(\"SELECT version();\")\nprint(cur.fetchone()[0])\ncur.close()\nconn.close()","lang":"python","description":"Basic usage: spin up ephemeral PostgreSQL and run a query."},"warnings":[{"fix":"For async SQLAlchemy: engine = db.get_engine(driver='asyncpg')","message":"In v0.5.0, the API changed from sync-only to support async via SQLAlchemy async engine. The synchronous connection string methods still work, but async users must use get_engine(driver='asyncpg').","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Use context manager: with pglite.PGlite() as db: ...","message":"PGlite launches a Node.js child process (pglite_manager.js). If your Python process exits uncleanly, orphaned processes may remain. Since v0.5.3, cleanup is improved, but always call db.close() or use the context manager.","severity":"gotcha","affected_versions":"<0.5.3"},{"fix":"Do not use for production data. Designed for tests only.","message":"The database is ephemeral and lives only as long as the PGlite instance. Data is lost when the Python process ends or PGlite is garbage collected.","severity":"gotcha","affected_versions":"all"},{"fix":"db = pglite.PGlite(extensions=['vector'])","message":"Extensions like pgvector require opt-in via the 'extensions' parameter. They are not enabled by default.","severity":"gotcha","affected_versions":">=0.4.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run: pip install py-pglite","cause":"Incorrect import or package not installed.","error":"ModuleNotFoundError: No module named 'pglite'"},{"fix":"Upgrade to latest: pip install --upgrade py-pglite","cause":"Old version (<0.2.0) where API was different, or wrong import path.","error":"AttributeError: module 'pglite' has no attribute 'PGlite'"},{"fix":"Use db.get_connection_string() instead of hardcoding localhost:5432.","cause":"PGlite uses a random port, not default 5432. You must use the connection string from get_connection_string().","error":"Connection refused\nIs the server running on host \"localhost\" (::1) and accepting TCP/IP connections on port 5432?"},{"fix":"Ensure Node.js is installed. Set PGLITE_NODE_PATH if needed. Restart the database.","cause":"PGlite Node process crashed or was terminated (e.g., due to resource limits).","error":"OperationalError: server closed the connection unexpectedly"},{"fix":"Set DATABASES = {'default': db.get_connection_dict()} in django settings or use @pytest.mark.django_db.","cause":"misconfiguration when using pytest-django with py-pglite.","error":"django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}