--- id: testgres version: "1.15.2" license: PostgreSQL license_treatment: unclear maintenance: active --- # testgres — Testing utility for PostgreSQL and its extensions License: unclear · Maintenance: active · Downloads: 101.2K/mo ## 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 above — 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 pip install testgres uv add testgres poetry add testgres ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 101.2K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags postgresql test cluster setup, temporary postgres database testing, pytest postgresql fixtures, postgres node orchestration, test database provisioning, postgresql integration testing, ephemeral postgres instances, postgres-testing, test-fixtures, database-provisioning [View on SkillFed](https://skillfed.io/packages/testgres) · [View on PyPI](https://pypi.org/project/testgres/)