skillfed

testcontainers-postgres

PostgreSQL component of testcontainers-python.

testcontainers-postgres v0.0.1rc1 84.2K downloads/30d#14,018 on PyPI2,271
License unclear Active released

What it is and what it does

testcontainers-postgres wraps PostgreSQL in a Docker container and exposes it for use in tests. It is a component of the larger testcontainers-python framework, which facilitates functional and integration testing by spinning up ephemeral service containers on demand. The package depends on testcontainers-core (which handles Docker lifecycle and cleanup), sqlalchemy (for connection URL generation), and psycopg2-binary (the PostgreSQL driver). You use it by instantiating a PostgresContainer with a Docker image tag, entering its context manager, and retrieving a sqlalchemy-compatible connection URL—the container starts automatically and tears down when the context exits.

The package is designed to eliminate the need for pre-configured test databases or external services. Configuration is available via environment variables (e.g., TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE, TESTCONTAINERS_RYUK_DISABLED) or runtime settings, allowing control over Docker socket paths, cleanup behavior, and container privileges.

Use it for:

  • Write integration tests that need a real PostgreSQL database without managing containers manually.
  • Run CI/CD pipelines that spin up isolated test databases per test suite without external dependencies.
  • Test database migrations and schema changes against a fresh PostgreSQL instance each run.
  • Develop multi-service tests where PostgreSQL is one of several containerized services.
  • Prototype applications that depend on PostgreSQL without installing it locally.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides a PostgreSQL Docker container wrapper for integration and functional testing, automatically managing container lifecycle and connection details.

Yes, if you use Docker for testing and need PostgreSQL containers. The install friction is low, maintenance is active, and there are no known vulnerabilities. However, the package is at 0.0.1rc1—clarify whether this is stable or abandoned before committing to production CI. Also verify the license before use in proprietary projects, as it is currently undeclared.

Install

testcontainers-postgres on PyPI

pip

pip install testcontainers-postgres

uv

uv add testcontainers-postgres

poetry

poetry add testcontainers-postgres

Installing testcontainers-postgres

Before you install

Low install friction with three straightforward runtime dependencies. The package is actively maintained with recent commits.

License in practice

License treatment is unclear; the package metadata contains no explicit license declaration. Verify the actual license before using in proprietary or restricted contexts.

Quickstart

from testcontainers.postgres import PostgresContainer
import sqlalchemy

with PostgresContainer("postgres:16") as postgres:
    engine = sqlalchemy.create_engine(postgres.get_connection_url())
    with engine.begin() as connection:
        result = connection.execute(sqlalchemy.text("select version()"))
        version, = result.fetchone()

Requires Docker to be running and accessible; testcontainers-core manages container lifecycle via Docker socket (configurable via TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE).

Verify before relying

  • Why the package remains at 0.0.1rc1 despite active maintenance—is this intentional or a pre-release that should have graduated?
  • Whether the unclear license is documented elsewhere (e.g., in the repository root or GitHub).
  • Compatibility and feature parity with the parent testcontainers-python project's current state.

Package facts

License not declared (unclear)
Python support supports the current Python release (>=3.7)
Install friction low — pure-Python wheel
Runtime dependencies 3 — testcontainers-core, sqlalchemy, psycopg2-binary
Maintenance actively maintained — 1,316 days since the last release
Last repo commit
First released
Downloads 84,200/month — #14,018 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: testcontainers_postgres-0.0.1rc1-py3-none-any.whl

Tags

postgres docker testingintegration test databasetestcontainers postgresephemeral postgres containerfunctional testing postgresqldocker-based test databasecontainerized postgres for tests
docker-testingintegration-testspostgres

More Testing packages