testgres
Testing utility for PostgreSQL and its extensions
What it is and what it does
testgres is a test utility that spins up isolated, temporary PostgreSQL clusters for use in Python test suites. It handles the full lifecycle—initialization, startup, query execution, and cleanup—so tests can focus on logic rather than database provisioning. The package wraps PostgreSQL command-line tools (initdb, pg_ctl, psql) and provides Python bindings for common operations like executing queries, managing transactions, creating backups, spawning replicas, and running pgbench benchmarks.
It integrates with pytest via fixtures and the standard Python logging module, making it straightforward to aggregate logs from multiple test nodes. The package supports both local and remote (Linux-only) node provisioning via SSH, and provides sensible configuration defaults that can be customized. With six runtime dependencies (pg8000, port-for, six, psutil, packaging, and testgres.os_ops) and low install friction, it is designed to be dropped into existing test suites with minimal setup overhead.
Use it for:
- Run integration tests against a fresh PostgreSQL instance that is created, used, and destroyed within a single test function or fixture.
- Test PostgreSQL extensions or custom configurations by provisioning nodes with specific postgresql.conf settings via default_conf() and append_conf().
- Verify replication and backup workflows by creating a master node, taking backups, spawning replicas, and asserting catchup behavior.
- Execute quick performance benchmarks using pgbench through testgres in a controlled, repeatable test environment.
- Parallelize test suites across multiple isolated PostgreSQL nodes using pytest-xdist, with each node on a distinct port.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
testgres orchestrates temporary PostgreSQL clusters for Python tests, handling initialization, startup, query execution, and automatic cleanup.
Yes, if you need to test PostgreSQL-dependent code in isolation. The package is actively maintained, has no known vulnerabilities, and low install friction. The main caveat is the unclear PostgreSQL license treatment—verify it aligns with your project's licensing before committing. The blocker is a working PostgreSQL installation; if you already have one, testgres is a straightforward way to automate cluster provisioning in tests.
Install
testgres on PyPI
pip
pip install testgresuv
uv add testgrespoetry
poetry add testgresInstalling testgres
Before you install
Low install friction with a pure-Python wheel and six runtime dependencies. Active maintenance with a release 10 days ago and commits through August 2026; the project has 157 stars and no known vulnerabilities.
License in practice
Licensed under PostgreSQL (license_treatment: unclear). The PostgreSQL license is permissive but differs from common open-source licenses; verify compatibility with your project's licensing requirements before adopting.
Quickstart
pip install testgres
import testgres
with testgres.get_new_node() as node:
node.init()
node.start()
result = node.execute('select 1')
print(result)
Requires PostgreSQL binaries (initdb, pg_ctl, psql) in PATH or accessible via PG_CONFIG or PG_BIN environment variable; supports Python 3.7.3 and newer.
Verify before relying
- Whether the PostgreSQL license (license_treatment: unclear) is compatible with your project's licensing model.
- Performance characteristics when running many parallel test nodes (documentation mentions pytest-xdist but does not quantify overhead).
Package facts
| License | PostgreSQL (unclear) |
| Python support | supports the current Python release (>=3.7.3) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — pg8000, port-for, six, psutil, packaging, testgres.os_ops |
| Maintenance | actively maintained — 10 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 101,216/month — #12,953 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: testgres-1.15.2-py3-none-any.whl
Keywords: test, testing, postgresql
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
testing.postgresqlAutomatically creates and tears down temporary…
permissive · top 5,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
postgresProvides a lightweight abstraction layer over…
permissive · top 15,000 on PyPI
testing.common.databaseProvides base classes and utilities for…
permissive · top 5,000 on PyPI
patroniPatroni orchestrates PostgreSQL…
permissive · top 15,000 on PyPI
pgdbWraps PostgreSQL connections to return query…
permissive · top 15,000 on PyPI
testcontainers-postgresProvides a PostgreSQL Docker container wrapper…
unclear · top 15,000 on PyPI
py-pglitepy-pglite provides a zero-config PostgreSQL…
permissive · top 15,000 on PyPI
pgserverEmbeds a PostgreSQL server with pgvector…
unclear · top 15,000 on PyPI