PostgreSQL component of testcontainers-python. Provides a lightweight, disposable PostgreSQL container for integration testing. Current version: 0.0.1rc1, requires Python >=3.7. Release cadence: follows the main testcontainers-python library (major releases every few months).
pip install testcontainers-postgresVerified import paths — ran on the pinned version, not inferred.
Quickstart: create a PostgreSQL container, get connection URL, and run a query.
Use keyword argument `dbname` instead of `db_name`.
Pass the image as a string directly: `PostgresContainer('postgres:16')` instead of `PostgresContainer(docker_image='postgres:16')`.Always specify a full image tag (e.g., 'postgres:16-alpine') to ensure reproducibility.
Install the main package with `pip install testcontainers` or ensure `testcontainers-core` is installed.
Use `from testcontainers.postgres import PostgresContainer`.
Upgrade to latest version and use `get_connection_url()` instead of `get_container_host_ip()` or `get_exposed_port()`.